Skip to content

Commit

Permalink
Refactor SHA to use trait. Implement Digest traits for SHA (#1908)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
AnthonyGrondin and MabezDev authored Aug 19, 2024
1 parent ec13087 commit 70491b9
Show file tree
Hide file tree
Showing 6 changed files with 824 additions and 223 deletions.
3 changes: 3 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added touch pad support for esp32 (#1873, #1956)
- Allow configuration of period updating method for MCPWM timers (#1898)
- Add self-testing mode for TWAI peripheral. (#1929)
- Added a `PeripheralClockControl::reset` to the driver constructors where missing (#1893)
- Added `digest::Digest` implementation to SHA (#1908)
- Added `debugger::debugger_connected`. (#1961)

### Changed
Expand All @@ -24,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow DMA to/from psram for esp32s3 (#1827)
- 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)
- Peripherals (where possible) are now explicitly reset and enabled in their constructors (#1893)
- SHA driver now use specific structs for the hashing algorithm instead of a parameter. (#1908)
- Reset peripherals in driver constructors where missing (#1893, #1961)

### Fixed
Expand Down
1 change: 1 addition & 0 deletions esp-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cfg-if = "1.0.0"
critical-section = "1.1.2"
defmt = { version = "0.3.8", optional = true }
delegate = "0.12.0"
digest = { version = "0.10.7", default-features = false, optional = true }
document-features = "0.2.10"
embassy-futures = { version = "0.1.1", optional = true }
embassy-sync = { version = "0.6.0", optional = true }
Expand Down
3 changes: 2 additions & 1 deletion esp-hal/src/reg_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl EndianessConverter for NativeEndianess {
}

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

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

0 comments on commit 70491b9

Please sign in to comment.