-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Merge branch 'release/v9.3.0'
- Loading branch information
Showing
51 changed files
with
1,381 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#[cfg(feature = "rsa")] | ||
pub fn rsa_key_wrapping() { | ||
use cosmian_crypto_core::{ | ||
reexport::rand_core::{RngCore, SeedableRng}, | ||
CsRng, RsaKeyLength, RsaKeyWrappingAlgorithm, RsaPrivateKey, | ||
}; | ||
use zeroize::Zeroizing; | ||
|
||
let mut rng = CsRng::from_entropy(); | ||
println!("... Generating a 3072 bit RSA key ..."); | ||
let rsa_private_key = RsaPrivateKey::new(&mut rng, RsaKeyLength::Modulus3072).unwrap(); | ||
|
||
let mut key_to_wrap = [0_u8; 32]; | ||
rng.fill_bytes(&mut key_to_wrap); | ||
|
||
let mut key_to_wrap = [0_u8; 189]; | ||
rng.fill_bytes(&mut key_to_wrap); | ||
let key_to_wrap = Zeroizing::from(key_to_wrap.to_vec()); | ||
|
||
let rsa_public_key = rsa_private_key.public_key(); | ||
|
||
print!("Key wrapping with PKCS#11 CKM_RSA_AES_KEY_WRAP SHA-256 AES 256 ..."); | ||
let wrapped_key = rsa_public_key | ||
.wrap_key( | ||
&mut rng, | ||
RsaKeyWrappingAlgorithm::Aes256Sha256, | ||
&key_to_wrap, | ||
) | ||
.unwrap(); | ||
|
||
print!("unwrapping ...: "); | ||
let unwrapped_key = rsa_private_key | ||
.unwrap_key(RsaKeyWrappingAlgorithm::Aes256Sha256, &wrapped_key) | ||
.unwrap(); | ||
|
||
assert_eq!(unwrapped_key, key_to_wrap); | ||
println!("OK"); | ||
} |
Oops, something went wrong.