Skip to content

Commit 5571be6

Browse files
committed
refactor xof
1 parent 63ad9c5 commit 5571be6

11 files changed

Lines changed: 372 additions & 339 deletions

File tree

ascon-xof128/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repository = "https://github.com/RustCrypto/hashes"
1010
license = "Apache-2.0 OR MIT"
1111
keywords = ["hash", "ascon"]
1212
categories = ["cryptography", "no-std"]
13-
description = "Implementation of Ascon-XOF128"
13+
description = "Implementation of Ascon-XOF128 and Ascon-СXOF128"
1414

1515
[dependencies]
1616
digest = "0.11"

ascon-xof128/README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
![Rust Version][rustc-image]
88
[![Project Chat][chat-image]][chat-link]
99

10-
Pure Rust implementation of the [Ascon-XOF128] extendable output function (XOF).
10+
Pure Rust implementation of the Ascon-XOF128 and Ascon-СXOF128 extendable output functions (XOF)
11+
specified in [NIST SP 800-232].
1112

1213
## Examples
1314

@@ -23,7 +24,21 @@ xof.update(b"some bytes");
2324
let mut reader = xof.finalize_xof();
2425
let mut dst = [0u8; 5];
2526
reader.read(&mut dst);
26-
assert_eq!(dst, hex!("8c7dd114a0"));
27+
assert_eq!(dst, hex!("8C7DD114A0"));
28+
```
29+
30+
Ascon-CXOF128 works similarly, but you must specify a customization string to initialize it:
31+
32+
```rust
33+
use ascon_xof128::{AsconCxof128, CustomizedInit, ExtendableOutput, Update, XofReader};
34+
use hex_literal::hex;
35+
36+
let mut xof = AsconCxof128::new_customized(b"some customization string");
37+
xof.update(b"some bytes");
38+
let mut reader = xof.finalize_xof();
39+
let mut dst = [0u8; 5];
40+
reader.read(&mut dst);
41+
assert_eq!(dst, hex!("7824810FF7"));
2742
```
2843

2944
See the [`digest`] crate docs for additional examples.
@@ -58,5 +73,5 @@ dual licensed as above, without any additional terms or conditions.
5873

5974
[//]: # (general links)
6075

61-
[Ascon-XOF128]: https://doi.org/10.6028/NIST.SP.800-232.ipd
76+
[NIST SP 800-232]: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-232.ipd.pdf
6277
[`digest`]: https://docs.rs/digest

ascon-xof128/src/block_api.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

ascon-xof128/src/block_api/cxof.rs

Lines changed: 0 additions & 149 deletions
This file was deleted.

ascon-xof128/src/block_api/reader.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

ascon-xof128/src/block_api/xof.rs

Lines changed: 0 additions & 120 deletions
This file was deleted.

ascon-xof128/src/consts.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use ascon::State;
2+
3+
const XOF_IV: u64 = 0x0000_0800_00CC_0003;
4+
const CXOF_IV: u64 = 0x0000_0800_00CC_0004;
5+
6+
pub(crate) const XOF_INIT_STATE: State = init_state(XOF_IV);
7+
pub(crate) const CXOF_INIT_STATE: State = init_state(CXOF_IV);
8+
9+
const fn init_state(iv: u64) -> ascon::State {
10+
let mut state = [iv, 0, 0, 0, 0];
11+
ascon::permute12(&mut state);
12+
state
13+
}

0 commit comments

Comments
 (0)