unstable
only.Expand description
§Secure Hash Algorithm (SHA) Accelerator
§Overview
This SHA accelerator is a hardware device that speeds up the SHA algorithm significantly, compared to a SHA algorithm implemented solely in software
§Configuration
This driver allows you to perform cryptographic hash operations using various hash algorithms supported by the SHA peripheral, such as:
- SHA-1
- SHA-224
- SHA-256
- SHA-384
- SHA-512
The driver supports two working modes:
- Typical SHA
- DMA-SHA
It provides functions to update the hash calculation with input data, finish the hash calculation and retrieve the resulting hash value. The SHA peripheral on ESP chips can handle large data streams efficiently, making it suitable for cryptographic applications that require secure hashing.
To use the SHA Peripheral Driver, you need to initialize it with the desired SHA mode and the corresponding SHA peripheral. Once initialized, you can update the hash calculation by providing input data, finish the calculation to retrieve the hash value and repeat the process for a new hash calculation if needed.
§Examples
let mut source_data = "HELLO, ESPRESSIF!".as_bytes();
let mut sha = Sha::new(peripherals.SHA);
let mut hasher = sha.start::<Sha256>();
// Short hashes can be created by decreasing the output buffer to the
// desired length
let mut output = [0u8; 32];
while !source_data.is_empty() {
// All the HW Sha functions are infallible so unwrap is fine to use if
// you use block!
source_data = block!(hasher.update(source_data)).unwrap();
}
// Finish can be called as many times as desired to get multiple copies of
// the output.
block!(hasher.finish(output.as_mut_slice())).unwrap();
§Implementation State
- DMA-SHA Mode is not supported.
Structs§
- The SHA Accelerator driver instance
- A SHA implementation struct.
- A SHA implementation struct.
- A SHA implementation struct.
- A SHA implementation struct.
- An active digest
Traits§
- This trait encapsulates the configuration for a specific SHA algorithm.