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:
committed by
Adam Langley
parent
a32596b054
commit
414f69504d
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user