From fa4c6aa015eb0be40f257aaf8dcd92df35574f7d Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Wed, 24 May 2023 09:53:22 +0900 Subject: [PATCH] [zk-token-sdk] Update random `AeKey` generation to use `OsRng` internally (#31786) update random `AeKey` generation to use `OsRng` internally --- zk-token-sdk/src/encryption/auth_encryption.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/zk-token-sdk/src/encryption/auth_encryption.rs b/zk-token-sdk/src/encryption/auth_encryption.rs index e2d979d38..400bc84fa 100644 --- a/zk-token-sdk/src/encryption/auth_encryption.rs +++ b/zk-token-sdk/src/encryption/auth_encryption.rs @@ -7,7 +7,7 @@ use { aead::{Aead, NewAead}, Aes128GcmSiv, }, - rand::{rngs::OsRng, CryptoRng, Rng, RngCore}, + rand::{rngs::OsRng, Rng}, thiserror::Error, }; use { @@ -43,8 +43,8 @@ pub enum AuthenticatedEncryptionError { struct AuthenticatedEncryption; impl AuthenticatedEncryption { #[cfg(not(target_os = "solana"))] - fn keygen(rng: &mut T) -> AeKey { - AeKey(rng.gen::<[u8; 16]>()) + fn keygen() -> AeKey { + AeKey(OsRng.gen::<[u8; 16]>()) } #[cfg(not(target_os = "solana"))] @@ -104,8 +104,8 @@ impl AeKey { Ok(result.to_vec()) } - pub fn random(rng: &mut T) -> Self { - AuthenticatedEncryption::keygen(rng) + pub fn new_rand() -> Self { + AuthenticatedEncryption::keygen() } pub fn encrypt(&self, amount: u64) -> AeCiphertext { @@ -217,7 +217,7 @@ mod tests { #[test] fn test_aes_encrypt_decrypt_correctness() { - let key = AeKey::random(&mut OsRng); + let key = AeKey::new_rand(); let amount = 55; let ct = key.encrypt(amount);