Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkcs12: use der::BmpString for KDF #1209

Merged
merged 1 commit into from
Sep 5, 2023
Merged

Conversation

tarcieri
Copy link
Member

Uses the BmpString type to implement transcoding from UTF-8 to BMP/UCS-2.

This type notably restricts the use of UTF-16 surrogate pairs, something the previous implementation was not doing correctly. This entailed making the methods which transcode UTF-8 fallible, since we need to handle the error case that they encode characters outside BMP/UCS-2.

cc @xemwebe

Uses the `BmpString` type to implement transcoding from UTF-8 to
BMP/UCS-2.

This type notably restricts the use of UTF-16 surrogate pairs, something
the previous implementation was not doing correctly. This entailed
making the methods which transcode UTF-8 fallible, since we need to
handle the error case that they encode characters outside BMP/UCS-2.
Comment on lines 162 to +172
const PASS_SHORT: &str = "🔥";
const SALT_INC: [u8; 8] = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8];

assert_eq!(
derive_key_utf8::<sha2::Sha256>(
PASS_SHORT,
&SALT_INC,
Pkcs12KeyType::EncryptionKey,
100,
32
),
hex!("d01e72a940b4b1a7a5707fc8264a60cb7606ff9051dedff90930687d2513c006")
);
assert!(derive_key_utf8::<sha2::Sha256>(
PASS_SHORT,
&SALT_INC,
Pkcs12KeyType::EncryptionKey,
100,
32
)
.is_err()); // Emoji is not in the Basic Multilingual Plane
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: now errors on the emoji test. I believe this is the correct behavior since the emoji is not valid BMP/UCS-2

@tarcieri tarcieri merged commit 4f41bdb into master Sep 5, 2023
172 checks passed
@tarcieri tarcieri deleted the pkcs12/use-bmpstring-for-kdf branch September 5, 2023 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant