Skip to content

Commit 7b4cced

Browse files
authored
sha3: move SHAKE into separate shake crate (#869)
1 parent 5d6d720 commit 7b4cced

19 files changed

Lines changed: 490 additions & 105 deletions

File tree

.github/workflows/shake.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: shake
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/shake.yml"
7+
- "shake/**"
8+
- "Cargo.*"
9+
push:
10+
branches: master
11+
12+
defaults:
13+
run:
14+
working-directory: shake
15+
16+
env:
17+
CARGO_INCREMENTAL: 0
18+
RUSTFLAGS: "-Dwarnings"
19+
20+
# Cancels CI jobs when new commits are pushed to a PR branch
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
23+
cancel-in-progress: true
24+
25+
jobs:
26+
set-msrv:
27+
uses: RustCrypto/actions/.github/workflows/set-msrv.yml@master
28+
with:
29+
msrv: 1.85.0
30+
31+
build:
32+
needs: set-msrv
33+
runs-on: ubuntu-latest
34+
strategy:
35+
matrix:
36+
rust:
37+
- ${{needs.set-msrv.outputs.msrv}}
38+
- stable
39+
target:
40+
- thumbv7em-none-eabi
41+
- wasm32-unknown-unknown
42+
steps:
43+
- uses: actions/checkout@v6
44+
- uses: RustCrypto/actions/cargo-cache@master
45+
- uses: dtolnay/rust-toolchain@master
46+
with:
47+
toolchain: ${{ matrix.rust }}
48+
targets: ${{ matrix.target }}
49+
- uses: RustCrypto/actions/cargo-hack-install@master
50+
- run: cargo hack build --target ${{ matrix.target }} --each-feature
51+
52+
test:
53+
needs: set-msrv
54+
runs-on: ubuntu-latest
55+
strategy:
56+
matrix:
57+
rust:
58+
- ${{needs.set-msrv.outputs.msrv}}
59+
- stable
60+
steps:
61+
- uses: actions/checkout@v6
62+
- uses: RustCrypto/actions/cargo-cache@master
63+
- uses: dtolnay/rust-toolchain@master
64+
with:
65+
toolchain: ${{ matrix.rust }}
66+
- uses: RustCrypto/actions/cargo-hack-install@master
67+
- run: cargo hack test --feature-powerset
68+
69+
minimal-versions:
70+
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
71+
with:
72+
working-directory: ${{ github.workflow }}

Cargo.lock

Lines changed: 10 additions & 0 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
@@ -23,6 +23,7 @@ members = [
2323
"sha2",
2424
"sha3",
2525
"shabal",
26+
"shake",
2627
"skein",
2728
"sm3",
2829
"streebog",

sha3/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Internal implementation by removing unnecessary buffering ([#849])
1111
- Serialization format used by `SerializableState` trait implementations ([#849])
1212

13+
### Removed
14+
- `Shake`, `Shake128`, and `Shake256` types (moved to the `shake` crate) ([#869])
15+
1316
[#849]: https://github.com/RustCrypto/hashes/pull/849
17+
[#869]: https://github.com/RustCrypto/hashes/pull/869
1418

1519
## 0.11.0 (2026-04-02)
1620
### Added

sha3/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ description = "Implementation of the SHA-3 family of cryptographic hash algorith
1414

1515
[dependencies]
1616
digest = { version = "0.11", default-features = false }
17-
keccak = "0.2"
1817
sponge-cursor = "0.1"
18+
keccak = "0.2"
1919

2020
[dev-dependencies]
21-
digest = { version = "0.11", features = ["dev"] }
21+
digest = { version = "0.11", default-features = false, features = ["dev"] }
2222
hex-literal = "1"
2323

2424
[features]

sha3/README.md

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
Implementation of the [SHA-3] family of cryptographic hash algorithms.
1111

12-
There are 6 standard algorithms specified in the SHA-3 standard:
12+
There are 4 standard fixed-size algorithms specified in the SHA-3 standard:
13+
`SHA3-224`, `SHA3-256`, `SHA3-384`, `SHA3-512`.
1314

14-
- `SHA3-224`, `SHA3-256`, `SHA3-384`, `SHA3-512`
15-
- `SHAKE128` and `SHAKE256` (an extendable output function (XOF))
15+
`SHAKE128` and `SHAKE256` extendable output functions (XOF) are defined in the [`shake`] crate
1616

1717
Additionally, this crate supports:
18-
- `KeccakFull`: CryptoNight variant of SHA-3
1918
- `Keccak224`, `Keccak256`, `Keccak384`, `Keccak512`: NIST submission without padding changes
19+
- `Keccak256Full`: CryptoNight variant of SHA-3
2020

2121
## Examples
2222

@@ -34,25 +34,6 @@ let hash = hasher.finalize();
3434
assert_eq!(hash, hex!("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"));
3535
```
3636

37-
SHAKE functions have an extendable output, so finalization method returns
38-
XOF reader from which results of arbitrary length can be read. Note that
39-
these functions do not implement `Digest`, so lower-level traits have to
40-
be imported:
41-
42-
```rust
43-
use sha3::{shake::Shake128, digest::{Update, ExtendableOutput, XofReader}};
44-
use hex_literal::hex;
45-
46-
let mut hasher = Shake128::default();
47-
hasher.update(b"abc");
48-
let mut reader = hasher.finalize_xof();
49-
let mut buf = [0u8; 10];
50-
reader.read(&mut buf);
51-
assert_eq!(buf, hex!("5881092dd818bf5cf8a3"));
52-
reader.read(&mut buf);
53-
assert_eq!(buf, hex!("ddb793fbcba74097d5c5"));
54-
```
55-
5637
See the [`digest`] crate docs for additional examples.
5738

5839
## License
@@ -86,4 +67,5 @@ dual licensed as above, without any additional terms or conditions.
8667
[//]: # (general links)
8768

8869
[SHA-3]: https://en.wikipedia.org/wiki/SHA-3
70+
[`shake`]: http://docs.rs/shake
8971
[`digest`]: https://docs.rs/digest

sha3/benches/mod.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
extern crate test;
33

44
use digest::bench_update;
5-
use sha3::{
6-
Sha3_224, Sha3_256, Sha3_384, Sha3_512,
7-
shake::{Shake128, Shake256},
8-
};
5+
use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512};
96
use test::Bencher;
107

118
bench_update!(
@@ -39,19 +36,3 @@ bench_update!(
3936
sha3_512_1000 1000;
4037
sha3_512_10000 10000;
4138
);
42-
43-
bench_update!(
44-
Shake128::default();
45-
shake128_10 10;
46-
shake128_100 100;
47-
shake128_1000 1000;
48-
shake128_10000 10000;
49-
);
50-
51-
bench_update!(
52-
Shake256::default();
53-
shake256_10 10;
54-
shake256_100 100;
55-
shake256_1000 1000;
56-
shake256_10000 10000;
57-
);

sha3/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ use digest::{
2020
},
2121
consts::{U28, U32, U48, U64, U72, U104, U136, U144, U200, U201},
2222
};
23+
2324
#[cfg(feature = "oid")]
2425
mod oids;
2526
mod utils;
2627

27-
/// Implementation of the SHAKE function.
28-
pub mod shake;
29-
3028
macro_rules! impl_fixed {
3129
($(
3230
$(#[$attr:meta])*

sha3/tests/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
use digest::dev::{fixed_reset_test, xof_reset_test};
1+
use digest::dev::fixed_reset_test;
22
use digest::new_test;
33

44
new_test!(sha3_224_kat, sha3::Sha3_224, fixed_reset_test);
55
new_test!(sha3_256_kat, sha3::Sha3_256, fixed_reset_test);
66
new_test!(sha3_384_kat, sha3::Sha3_384, fixed_reset_test);
77
new_test!(sha3_512_kat, sha3::Sha3_512, fixed_reset_test);
88

9-
new_test!(shake128_kat, sha3::shake::Shake128, xof_reset_test);
10-
new_test!(shake256_kat, sha3::shake::Shake256, xof_reset_test);
11-
129
// Test vectors from https://github.com/kazcw/yellowsun/blob/test-keccak/src/lib.rs#L171
1310
new_test!(keccak_224_kat, sha3::Keccak224, fixed_reset_test);
1411
new_test!(keccak_256_kat, sha3::Keccak256, fixed_reset_test);

shake/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## 0.1.0 (2026-05-13)
9+
- Initial release with implementation moved from the `sha3` crate ([#869])
10+
11+
[#869]: https://github.com/RustCrypto/hashes/pull/869

0 commit comments

Comments
 (0)