Reworking bssl_crypto: don't use zero keys in examples. 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 <bbe@google.com>
diff --git a/rust/bssl-crypto/src/aead.rs b/rust/bssl-crypto/src/aead.rs index 3257925..d367764 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 2527e8d..4602ee1 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 2a07fbc..bf482f7 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");