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>
This commit is contained in:
Adam Langley
2024-01-19 18:25:45 +00:00
committed by Adam Langley
parent a32596b054
commit 414f69504d
3 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -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";
+1 -1
View File
@@ -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);
+2 -2
View File
@@ -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");