Skip to content

Commit 7d44caf

Browse files
authored
Migrate to buffering macros (#678)
1 parent 50ea2ee commit 7d44caf

File tree

146 files changed

+4539
-4383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+4539
-4383
lines changed

.github/workflows/sha3.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
toolchain: ${{ matrix.rust }}
4343
targets: ${{ matrix.target }}
4444
- uses: RustCrypto/actions/cargo-hack-install@master
45-
- run: cargo hack build --target ${{ matrix.target }} --each-feature --exclude-features default,std,asm
45+
- run: cargo hack build --target ${{ matrix.target }} --each-feature --exclude-features default,asm
4646

4747
test:
4848
needs: set-msrv

Cargo.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ opt-level = 2
3131

3232
[patch.crates-io]
3333
# https://github.com/RustCrypto/traits/pull/1787
34+
# https://github.com/RustCrypto/traits/pull/1799
3435
digest = { git = "https://github.com/RustCrypto/traits" }

ascon-hash/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Edition changed to 2024 and MSRV bumped to 1.85 ([#652])
1010
- Relax MSRV policy and allow MSRV bumps in patch releases
1111
- Update to `digest` v0.11
12+
- Replace type aliases with newtypes [#678]
1213
- Adopt to changes from NIST draft
1314
- Remove `AsconAHash` and `AsconAXof`
1415
- Rename `AsonHash` to `AsconHAsh256`
1516
- Rename `AsconXof` to `AsconXof128`
1617

1718
[#652]: https://github.com/RustCrypto/hashes/pull/652
19+
[#678]: https://github.com/RustCrypto/hashes/pull/678
1820

1921
## 0.2.0 (2023-03-21)
2022
### Changed

ascon-hash/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ keywords = ["crypto", "hash", "ascon"]
1616
categories = ["cryptography", "no-std"]
1717

1818
[dependencies]
19-
digest = { version = "=0.11.0-pre.10", default-features = false, features = ["core-api"] }
19+
digest = "=0.11.0-pre.10"
2020
ascon = { version = "0.4", default-features = false }
2121

2222
[dev-dependencies]
@@ -26,8 +26,8 @@ hex-literal = "1"
2626
base16ct = { version = "0.2", features = ["alloc"] }
2727

2828
[features]
29-
default = ["std"]
30-
std = ["digest/std"]
29+
default = ["alloc"]
30+
alloc = ["digest/alloc"]
3131
zeroize = ["ascon/zeroize", "digest/zeroize"]
3232

3333
[package.metadata.docs.rs]

ascon-hash/src/lib.rs

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ use ascon::State;
1313
pub use digest::{self, Digest, ExtendableOutput, Reset, Update, XofReader};
1414
use digest::{
1515
HashMarker, Output, OutputSizeUser,
16-
block_buffer::Eager,
17-
consts::{U8, U32},
18-
core_api::{
19-
AlgorithmName, Block, Buffer, BufferKindUser, CoreWrapper, ExtendableOutputCore,
20-
FixedOutputCore, UpdateCore, XofReaderCore, XofReaderCoreWrapper,
16+
block_api::{
17+
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, Eager, ExtendableOutputCore,
18+
FixedOutputCore, UpdateCore, XofReaderCore,
2119
},
22-
crypto_common::BlockSizeUser,
20+
consts::{U8, U32, U40},
21+
crypto_common::hazmat::{DeserializeStateError, SerializableState, SerializedState},
2322
};
2423

2524
/// Produce mask for padding.
@@ -176,6 +175,26 @@ impl AlgorithmName for AsconCore {
176175
}
177176
}
178177

178+
impl SerializableState for AsconCore {
179+
type SerializedStateSize = U40;
180+
181+
fn serialize(&self) -> SerializedState<Self> {
182+
self.state.state.as_bytes().into()
183+
}
184+
185+
fn deserialize(
186+
serialized_state: &SerializedState<Self>,
187+
) -> Result<Self, DeserializeStateError> {
188+
let state = ascon::State::from(&serialized_state.0);
189+
Ok(Self {
190+
state: HashCore {
191+
state,
192+
phantom: PhantomData,
193+
},
194+
})
195+
}
196+
}
197+
179198
/// Ascon XOF
180199
#[derive(Clone, Debug, Default)]
181200
pub struct AsconXofCore {
@@ -241,29 +260,37 @@ impl AlgorithmName for AsconXofCore {
241260
}
242261
}
243262

244-
/// Ascon-Hash256
245-
///
246-
/// ```
247-
/// use ascon_hash::{AsconHash256, Digest};
248-
///
249-
/// let mut hasher = AsconHash256::new();
250-
/// hasher.update(b"some bytes");
251-
/// let digest = hasher.finalize();
252-
/// assert_eq!(&digest[..], b"\xe9\x09\xc2\xf6\xda\x9c\xb3\x02\x84\x23\x26\x5c\x8f\x23\xfc\x2d\x26\xbf\xc0\xf3\xdb\x70\x46\x83\xef\x16\xb7\x87\xa9\x45\xed\x68");
253-
/// ```
254-
pub type AsconHash256 = CoreWrapper<AsconCore>;
255-
/// Ascon-XOF128
256-
///
257-
/// ```
258-
/// use ascon_hash::{AsconXof128, ExtendableOutput, Update, XofReader};
259-
///
260-
/// let mut xof = AsconXof128::default();
261-
/// xof.update(b"some bytes");
262-
/// let mut reader = xof.finalize_xof();
263-
/// let mut dst = [0u8; 5];
264-
/// reader.read(&mut dst);
265-
/// assert_eq!(&dst, b"\x8c\x7d\xd1\x14\xa0");
266-
/// ```
267-
pub type AsconXof128 = CoreWrapper<AsconXofCore>;
268-
/// Reader for AsconXOF output
269-
pub type AsconXof128Reader = XofReaderCoreWrapper<AsconXofReaderCore>;
263+
impl SerializableState for AsconXofCore {
264+
type SerializedStateSize = U40;
265+
266+
fn serialize(&self) -> SerializedState<Self> {
267+
self.state.state.as_bytes().into()
268+
}
269+
270+
fn deserialize(
271+
serialized_state: &SerializedState<Self>,
272+
) -> Result<Self, DeserializeStateError> {
273+
let state = ascon::State::from(&serialized_state.0);
274+
Ok(Self {
275+
state: HashCore {
276+
state,
277+
phantom: PhantomData,
278+
},
279+
})
280+
}
281+
}
282+
283+
digest::buffer_fixed!(
284+
/// Ascon-Hash256
285+
pub struct AsconHash256(AsconCore);
286+
impl: FixedHashTraits;
287+
);
288+
289+
digest::buffer_xof!(
290+
/// Ascon-XOF128 hasher.
291+
pub struct AsconXof128(AsconXofCore);
292+
impl: XofHasherTraits;
293+
/// Ascon-XOF128 reader.
294+
pub struct AsconXof128Reader(AsconXofReaderCore);
295+
impl: XofReaderTraits;
296+
);

belt-hash/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## 0.2.0 (UNRELEASED)
9+
### Added
10+
- `alloc` crate feature ([#678])
11+
912
### Changed
1013
- Edition changed to 2024 and MSRV bumped to 1.85 ([#652])
1114
- Relax MSRV policy and allow MSRV bumps in patch releases
1215
- Update to `digest` v0.11
16+
- Replace type aliases with newtypes ([#678])
17+
18+
### Removed
19+
- `std` crate feature ([#678])
1320

1421
[#652]: https://github.com/RustCrypto/hashes/pull/652
22+
[#678]: https://github.com/RustCrypto/hashes/pull/678
1523

1624
## 0.1.1 (2022-11-22)
1725
### Added

belt-hash/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ hex-literal = "1"
2222
base16ct = { version = "0.2", features = ["alloc"] }
2323

2424
[features]
25-
default = ["oid", "std"]
26-
std = ["digest/std"]
25+
default = ["alloc", "oid"]
26+
alloc = ["digest/alloc"]
2727
oid = ["digest/oid"]
2828
zeroize = ["digest/zeroize"]
2929

0 commit comments

Comments
 (0)