Skip to content

Commit 70491b9

Browse files
Refactor SHA to use trait. Implement Digest traits for SHA (#1908)
* feat(SHA): Refactor SHA to use trait. Implement Digest traits for SHA * Fix CI. Fix wrong sha mode for esp32 * Save hash register for interleaving operation An example (wip) `sha_fuzz.rs` was added to test different functionalities of the SHA driver and to ensure proper functionning under all cases. * Use random data when testing SHA * fix(SHA): Buffer words until a full block before writing to memory This fixes interleaving operations by buffering words into the SHA context until a full block can be processed. * Fix(SHA): Use correct length padding for SHA384 and SHA512. - This fixes a long running issue with SHA384 and SHA512, where some digest of specific sizes wouldn't compute correctly, by changing the padding length of the size field. * Re-export digest for convenience * Remove completed TODO * Remove SHA peripheral requirement. - Document safety of the SHA driver. --------- Co-authored-by: Scott Mabin <[email protected]>
1 parent ec13087 commit 70491b9

File tree

6 files changed

+824
-223
lines changed

6 files changed

+824
-223
lines changed

esp-hal/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Added touch pad support for esp32 (#1873, #1956)
1414
- Allow configuration of period updating method for MCPWM timers (#1898)
1515
- Add self-testing mode for TWAI peripheral. (#1929)
16+
- Added a `PeripheralClockControl::reset` to the driver constructors where missing (#1893)
17+
- Added `digest::Digest` implementation to SHA (#1908)
1618
- Added `debugger::debugger_connected`. (#1961)
1719

1820
### Changed
@@ -24,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2426
- Allow DMA to/from psram for esp32s3 (#1827)
2527
- DMA buffers now don't require a static lifetime. Make sure to never `mem::forget` an in-progress DMA transfer (consider using `#[deny(clippy::mem_forget)]`) (#1837)
2628
- Peripherals (where possible) are now explicitly reset and enabled in their constructors (#1893)
29+
- SHA driver now use specific structs for the hashing algorithm instead of a parameter. (#1908)
2730
- Reset peripherals in driver constructors where missing (#1893, #1961)
2831

2932
### Fixed

esp-hal/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ cfg-if = "1.0.0"
2222
critical-section = "1.1.2"
2323
defmt = { version = "0.3.8", optional = true }
2424
delegate = "0.12.0"
25+
digest = { version = "0.10.7", default-features = false, optional = true }
2526
document-features = "0.2.10"
2627
embassy-futures = { version = "0.1.1", optional = true }
2728
embassy-sync = { version = "0.6.0", optional = true }

esp-hal/src/reg_access.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl EndianessConverter for NativeEndianess {
2828
}
2929

3030
/// Use BE for ESP32, NE otherwise
31+
#[derive(Debug, Clone)]
3132
pub(crate) struct SocDependentEndianess;
3233

3334
#[cfg(not(esp32))]
@@ -61,7 +62,7 @@ impl EndianessConverter for SocDependentEndianess {
6162
// It assumes incoming `dst` are aligned to desired layout (in future
6263
// ptr.is_aligned can be used). It also assumes that writes are done in FIFO
6364
// order.
64-
#[derive(Debug)]
65+
#[derive(Debug, Clone)]
6566
pub(crate) struct AlignmentHelper<E: EndianessConverter> {
6667
buf: [u8; U32_ALIGN_SIZE],
6768
buf_fill: usize,

0 commit comments

Comments
 (0)