Skip to content

Commit b9827f9

Browse files
committed
update examples
1 parent e93950a commit b9827f9

3 files changed

Lines changed: 44 additions & 14 deletions

File tree

cshake/README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,32 @@ defined in the NIST [SHA-3 Derived Functions].
1212

1313
## Examples
1414

15-
SHAKE functions have an extendable output, so finalization method returns
16-
XOF reader from which results of arbitrary length can be read. Note that
17-
these functions do not implement `Digest`, so lower-level traits have to
18-
be imported:
19-
20-
```rust,ignore
21-
// TODO: update to cSHAKE
22-
use sha3::{Shake128, digest::{Update, ExtendableOutput, XofReader}};
15+
cSHAKE functions have an extendable output, so finalization methods return
16+
XOF reader from which results of arbitrary length can be read.
17+
18+
```rust
19+
use cshake::CShake128;
20+
use cshake::digest::{CustomizedInit, Update, ExtendableOutput, XofReader};
2321
use hex_literal::hex;
2422

25-
let mut hasher = Shake128::default();
23+
let mut hasher = CShake128::default();
2624
hasher.update(b"abc");
2725
let mut reader = hasher.finalize_xof();
2826
let mut buf = [0u8; 10];
2927
reader.read(&mut buf);
3028
assert_eq!(buf, hex!("5881092dd818bf5cf8a3"));
29+
reader.read(&mut buf);
30+
assert_eq!(buf, hex!("ddb793fbcba74097d5c5"));
31+
32+
// With customization string
33+
let mut hasher = CShake128::new_customized(b"my customization string");
34+
hasher.update(b"abc");
35+
let mut reader = hasher.finalize_xof();
36+
let mut buf = [0u8; 10];
37+
reader.read(&mut buf);
38+
assert_eq!(buf, hex!("a296533c8d5753bf3421"));
39+
reader.read(&mut buf);
40+
assert_eq!(buf, hex!("124e8eb79262233170ce"));
3141
```
3242

3343
See the [`digest`] crate docs for additional examples.

sha3/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ let mut reader = hasher.finalize_xof();
4949
let mut buf = [0u8; 10];
5050
reader.read(&mut buf);
5151
assert_eq!(buf, hex!("5881092dd818bf5cf8a3"));
52+
reader.read(&mut buf);
53+
assert_eq!(buf, hex!("ddb793fbcba74097d5c5"));
5254
```
5355

5456
See the [`digest`] crate docs for additional examples.

turbo-shake/README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,35 @@ XOF reader from which results of arbitrary length can be read. Note that
1616
these functions do not implement `Digest`, so lower-level traits have to
1717
be imported:
1818

19-
```rust,ignore
20-
// TODO: update to TurboSHAKE
21-
use sha3::{Shake128, digest::{Update, ExtendableOutput, XofReader}};
19+
```rust
20+
use turbo_shake::TurboShake128;
21+
use turbo_shake::digest::{Update, ExtendableOutput, XofReader};
2222
use hex_literal::hex;
2323

24-
let mut hasher = Shake128::default();
24+
// With the default domain separator.
25+
//
26+
// Note that we have to use `<TurboShake128>` because of
27+
// the inadequate handling of defaults in Rust.
28+
// Alternatively, you could use `let mut hasher: TurboShake128 = Default::default();`
29+
// or `TurboShake128::<DEFAULT_DS>::default()`.
30+
let mut hasher = <TurboShake128>::default();
2531
hasher.update(b"abc");
2632
let mut reader = hasher.finalize_xof();
2733
let mut buf = [0u8; 10];
2834
reader.read(&mut buf);
29-
assert_eq!(buf, hex!("5881092dd818bf5cf8a3"));
35+
assert_eq!(buf, hex!("dcf1646dfe993a8eb6b7"));
36+
reader.read(&mut buf);
37+
assert_eq!(buf, hex!("82d1faaca6d82416a5dc"));
38+
39+
// With a custom domain separator
40+
let mut hasher = TurboShake128::<0x10>::default();
41+
hasher.update(b"abc");
42+
let mut reader = hasher.finalize_xof();
43+
let mut buf = [0u8; 10];
44+
reader.read(&mut buf);
45+
assert_eq!(buf, hex!("6702f7b19ea87087ed0f"));
46+
reader.read(&mut buf);
47+
assert_eq!(buf, hex!("45a2fa692bc18c3526d3"));
3048
```
3149

3250
See the [`digest`] crate docs for additional examples.

0 commit comments

Comments
 (0)