diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:47:55 +0000 |
commit | 2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4 (patch) | |
tree | 033cc839730fda84ff08db877037977be94e5e3a /vendor/commoncrypto-sys/tests/pbkdf2.rs | |
parent | Initial commit. (diff) | |
download | cargo-upstream.tar.xz cargo-upstream.zip |
Adding upstream version 0.70.1+ds1.upstream/0.70.1+ds1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/commoncrypto-sys/tests/pbkdf2.rs')
-rw-r--r-- | vendor/commoncrypto-sys/tests/pbkdf2.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/vendor/commoncrypto-sys/tests/pbkdf2.rs b/vendor/commoncrypto-sys/tests/pbkdf2.rs new file mode 100644 index 0000000..743a49a --- /dev/null +++ b/vendor/commoncrypto-sys/tests/pbkdf2.rs @@ -0,0 +1,48 @@ +extern crate commoncrypto_sys; +extern crate hex; + +use hex::{ToHex, FromHex}; + +// These password, salts, rounds and derived key values come from the test +// vectors stated in RFC 6070 +const PASSWORD: &'static str = "password"; +const SALT: &'static str = "salt"; + +const DERIVED1: &'static str = "0c60c80f961f0e71f3a9b524af6012062fe037a6"; +const DERIVED4096: &'static str = "4b007901b765489abead49d926f721d065a429c1"; + +macro_rules! test_pbkdf2 { + ( + $test_name: ident, + $prf_algorithm: ident, + $pw: ident, + $salt: ident, + $rounds: expr, + $expected_dkey: ident + ) => { + #[test] + fn $test_name() { + let derived_len = Vec::<u8>::from_hex($expected_dkey).expect("dkey from hex").len(); + let mut pw_derived = vec![0u8; derived_len]; + unsafe { + assert_eq!(0, commoncrypto_sys::CCKeyDerivationPBKDF( + commoncrypto_sys::CCPBKDFAlgorithm::kCCPBKDF2, + $pw.as_ptr(), $pw.len(), + $salt.as_ptr(), $salt.len(), + commoncrypto_sys::CCPseudoRandomAlgorithm::$prf_algorithm, + $rounds, + pw_derived.as_mut_ptr(), pw_derived.len() + )); + } + assert_eq!($expected_dkey, pw_derived.to_hex()); + } + } +} + +test_pbkdf2!(pbkdf2_1, kCCPRFHmacAlgSHA1, PASSWORD, SALT, 1, DERIVED1); +test_pbkdf2!(pbkdf2_4096, + kCCPRFHmacAlgSHA1, + PASSWORD, + SALT, + 4096, + DERIVED4096); |