Skip to content

Commit e22c7bb

Browse files
committed
Improve KMAC README
1 parent 26df8b0 commit e22c7bb

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

kmac/README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A rust implementation of [KMAC](https://en.wikipedia.org/wiki/SHA-3#Additional_instances), following the [NIST SP 800-185](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf) specification.
44

5-
This crate provides KMAC implementations for KMAC128, KMAC256, KMACXOF128, and KMACXOF256.
5+
This crate provides implementations for KMAC128, KMAC256, KMACXOF128, and KMACXOF256. KMAC is a PRF and keyed hash function based on the Keccak (SHA-3) sponge construction, designed for message authentication (MAC) and key derivation (KDF).
66

77
## Examples
88

@@ -14,46 +14,46 @@ use kmac::{Kmac128, Mac, KeyInit};
1414
use hex_literal::hex;
1515

1616
// Use KMAC128 to produce a MAC
17-
let mut mac = Kmac128::new_from_slice(b"key material").unwrap();
18-
mac.update(b"input message");
17+
let mut kmac = Kmac128::new_from_slice(b"key material").unwrap();
18+
kmac.update(b"input message");
1919

2020
// `result` has type `CtOutput` which is a thin wrapper around array of
2121
// bytes for providing constant time equality check
22-
let result = mac.finalize();
22+
let result = kmac.finalize();
2323

2424
// To get underlying array use `into_bytes`, but be careful, since
2525
// incorrect use of the code value may permit timing attacks which defeats
2626
// the security provided by the `CtOutput`
27-
let code_bytes = result.into_bytes();
27+
let mac_bytes = result.into_bytes();
2828
let expected = hex!("
2929
c39a8f614f8821443599440df5402787
3030
0f67e4c47919061584f14a616f3efcf5
3131
");
32-
assert_eq!(code_bytes[..], expected[..]);
32+
assert_eq!(mac_bytes[..], expected[..]);
3333
```
3434

3535
### Verifying a MAC
3636
```rust
3737
use kmac::{Kmac128, Mac, KeyInit};
3838
use hex_literal::hex;
3939

40-
let mut mac = Kmac128::new_from_slice(b"key material").unwrap();
41-
mac.update(b"input message");
40+
let mut kmac = Kmac128::new_from_slice(b"key material").unwrap();
41+
kmac.update(b"input message");
4242

43-
let mac_code = hex!("
43+
let mac_bytes = hex!("
4444
c39a8f614f8821443599440df5402787
4545
0f67e4c47919061584f14a616f3efcf5
4646
");
4747

4848
// `verify_slice` will return `Ok(())` if code is correct, `Err(MacError)` otherwise
49-
mac.verify_slice(&mac_code).unwrap();
49+
kmac.verify_slice(&mac_bytes).unwrap();
5050
```
5151

5252
### Producing a fixed-length output
5353

54-
KMAC can also be used to produce an output of any length, and can be particularly useful as a [key-stretching function](https://en.wikipedia.org/wiki/Key_stretching).
54+
KMAC can also be used to produce an output of any length, which is particularly useful when KMAC is being used as a [key-derivation function (KDF)](https://en.wikipedia.org/wiki/Key_derivation_function).
5555

56-
This method finalizes the KMAC and mixes the requested output length into the KMAC domain separation. That means the resulting bytes are dependent on the exact length of `out`. Use this when the output length is part of the MAC/derivation semantics (for example when the length itself must influence the MAC result).
56+
This method finalizes the KMAC and mixes the requested output length into the KMAC domain separation. The resulting bytes are dependent on the exact length of `out`. Use this when the output length is part of the MAC/derivation semantics (for example when the length itself must influence the MAC result).
5757

5858
A customisation string can also be provided to further domain-separate different uses of KMAC with the same key when initialising the KMAC instance with `new_customization`.
5959

@@ -83,9 +83,9 @@ The XOF variant finalizes the sponge state without binding the requested output
8383
use kmac::{Kmac256, Mac, ExtendableOutput, XofReader};
8484
use hex_literal::hex;
8585

86-
let mut mac = Kmac256::new_customization(b"key material", b"customization").unwrap();
87-
mac.update(b"input message");
88-
let mut reader = mac.finalize_xof();
86+
let mut kmac = Kmac256::new_customization(b"key material", b"customization").unwrap();
87+
kmac.update(b"input message");
88+
let mut reader = kmac.finalize_xof();
8989

9090
let mut output = [0u8; 32];
9191
reader.read(&mut output);

0 commit comments

Comments
 (0)