diff --git a/pkcs12/Cargo.toml b/pkcs12/Cargo.toml index 520356ab1..d51772343 100644 --- a/pkcs12/Cargo.toml +++ b/pkcs12/Cargo.toml @@ -14,9 +14,6 @@ readme = "README.md" edition = "2021" rust-version = "1.65" -[features] -alloc = [] - [dependencies] cfg-if = "1.0.0" digest = { version = "0.10.7", features=["alloc"] } diff --git a/pkcs12/src/kdf.rs b/pkcs12/src/kdf.rs index 4ac584814..fc4ba1b22 100644 --- a/pkcs12/src/kdf.rs +++ b/pkcs12/src/kdf.rs @@ -1,7 +1,7 @@ //! Implementation of the key derivation function //! [RFC 7292 Appendix B](https://datatracker.ietf.org/doc/html/rfc7292#appendix-B) -use alloc::vec::Vec; +use alloc::{vec, vec::Vec}; use digest::{core_api::BlockSizeUser, Digest, FixedOutputReset, OutputSizeUser, Update}; use zeroize::Zeroize; diff --git a/pkcs12/tests/kdf.rs b/pkcs12/tests/kdf.rs index acdfdf659..f5954dd73 100644 --- a/pkcs12/tests/kdf.rs +++ b/pkcs12/tests/kdf.rs @@ -1,10 +1,13 @@ -#![cfg(feature = "alloc")] - +/// Test cases for the key derivation functions. +/// All test cases have been verified against openssl's method `PKCS12_key_gen_utf8`. +/// See https://github.com/xemwebe/test_pkcs12_kdf for a sample program. +/// + +use hex_literal::hex; +use pkcs12::kdf::{derive_key, Pkcs12KeyType}; + #[test] fn pkcs12_key_derive_sha256() { - use hex_literal::hex; - use pkcs12::kdf::{derive_key, Pkcs12KeyType}; - const PASS_SHORT: &str = "ge@äheim"; const SALT_INC: [u8; 8] = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]; @@ -123,3 +126,16 @@ fn pkcs12_key_derive_whirlpool() { hex!("3324282adb468bff0734d3b7e399094ec8500cb5b0a3604055da107577aaf766") ); } + +#[test] +fn pkcs12_key_derive_special_chars() { + const PASS_SHORT: &str = "🔥"; + const SALT_INC: [u8; 8] = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]; + + assert_eq!( + derive_key::(PASS_SHORT, &SALT_INC, Pkcs12KeyType::EncryptionKey, 100, 32), + hex!("d01e72a940b4b1a7a5707fc8264a60cb7606ff9051dedff90930687d2513c006") + ); +} + +