From 414f69504d30d0848b69f6453ea7fb5e88004cb4 Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Thu, 18 Jan 2024 13:47:20 -0800 Subject: [PATCH] Reworking bssl_crypto: don't use zero keys in examples. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Someone _probably_ wouldn't copy–paste an example to the point of using a zero key but, just in case, since we have `rand_array` now, we might as well use it so that the examples are safe. Change-Id: I289cb8f27894e8f0429fbbed37a1db3ea4295ffd Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/65567 Reviewed-by: Bob Beck --- rust/bssl-crypto/src/aead.rs | 4 ++-- rust/bssl-crypto/src/aes.rs | 2 +- rust/bssl-crypto/src/hmac.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rust/bssl-crypto/src/aead.rs b/rust/bssl-crypto/src/aead.rs index 32579259a..d3677646b 100644 --- a/rust/bssl-crypto/src/aead.rs +++ b/rust/bssl-crypto/src/aead.rs @@ -31,11 +31,11 @@ //! ``` //! use bssl_crypto::aead::{Aead, Aes256Gcm}; //! -//! let key = [0u8; 32]; +//! let key = bssl_crypto::rand_array(); //! let aead = Aes256Gcm::new(&key); //! //! let mut message_counter: u64 = 0; -//! let mut nonce = [0u8; 12]; +//! let mut nonce = bssl_crypto::rand_array(); //! nonce[4..].copy_from_slice(message_counter.to_be_bytes().as_slice()); //! message_counter += 1; //! let plaintext = b"message"; diff --git a/rust/bssl-crypto/src/aes.rs b/rust/bssl-crypto/src/aes.rs index 2527e8d2e..4602ee120 100644 --- a/rust/bssl-crypto/src/aes.rs +++ b/rust/bssl-crypto/src/aes.rs @@ -29,7 +29,7 @@ //! ``` //! use bssl_crypto::aes; //! -//! let key_bytes = [0u8; 32]; +//! let key_bytes = bssl_crypto::rand_array(); //! let enc_key = aes::EncryptKey::new_256(&key_bytes); //! let block = [0u8; aes::BLOCK_SIZE]; //! let mut transformed_block = enc_key.encrypt(&block); diff --git a/rust/bssl-crypto/src/hmac.rs b/rust/bssl-crypto/src/hmac.rs index 2a07fbc23..bf482f760 100644 --- a/rust/bssl-crypto/src/hmac.rs +++ b/rust/bssl-crypto/src/hmac.rs @@ -30,7 +30,7 @@ //! ``` //! use bssl_crypto::hmac::HmacSha256; //! -//! let key = [0u8; 32]; +//! let key = bssl_crypto::rand_array(); //! let mut ctx = HmacSha256::new(&key); //! ctx.update(b"hel"); //! ctx.update(b"lo"); @@ -46,7 +46,7 @@ //! ``` //! use bssl_crypto::hmac::HmacSha256; //! -//! let key = [0u8; 32]; +//! let key = bssl_crypto::rand_array(); //! let mut keyed_ctx = HmacSha256::new(&key); //! let mut ctx1 = keyed_ctx.clone(); //! ctx1.update(b"foo");