Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/shake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: shake

on:
pull_request:
paths:
- ".github/workflows/shake.yml"
- "shake/**"
- "Cargo.*"
push:
branches: master

defaults:
run:
working-directory: shake

env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-Dwarnings"

# Cancels CI jobs when new commits are pushed to a PR branch
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
set-msrv:
uses: RustCrypto/actions/.github/workflows/set-msrv.yml@master
with:
msrv: 1.85.0

build:
needs: set-msrv
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- ${{needs.set-msrv.outputs.msrv}}
- stable
target:
- thumbv7em-none-eabi
- wasm32-unknown-unknown
steps:
- uses: actions/checkout@v6
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- uses: RustCrypto/actions/cargo-hack-install@master
- run: cargo hack build --target ${{ matrix.target }} --each-feature

test:
needs: set-msrv
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- ${{needs.set-msrv.outputs.msrv}}
- stable
steps:
- uses: actions/checkout@v6
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- uses: RustCrypto/actions/cargo-hack-install@master
- run: cargo hack test --feature-powerset

minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
with:
working-directory: ${{ github.workflow }}
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ members = [
"sha2",
"sha3",
"shabal",
"shake",
"skein",
"sm3",
"streebog",
Expand Down
4 changes: 4 additions & 0 deletions sha3/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Internal implementation by removing unnecessary buffering ([#849])
- Serialization format used by `SerializableState` trait implementations ([#849])

### Removed
- `Shake`, `Shake128`, and `Shake256` types (moved to the `shake` crate) ([#869])

[#849]: https://github.com/RustCrypto/hashes/pull/849
[#869]: https://github.com/RustCrypto/hashes/pull/869

## 0.11.0 (2026-04-02)
### Added
Expand Down
4 changes: 2 additions & 2 deletions sha3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ description = "Implementation of the SHA-3 family of cryptographic hash algorith

[dependencies]
digest = { version = "0.11", default-features = false }
keccak = "0.2"
sponge-cursor = "0.1"
keccak = "0.2"

[dev-dependencies]
digest = { version = "0.11", features = ["dev"] }
digest = { version = "0.11", default-features = false, features = ["dev"] }
hex-literal = "1"

[features]
Expand Down
28 changes: 5 additions & 23 deletions sha3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

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

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

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

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

## Examples

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

SHAKE functions have an extendable output, so finalization method returns
XOF reader from which results of arbitrary length can be read. Note that
these functions do not implement `Digest`, so lower-level traits have to
be imported:

```rust
use sha3::{shake::Shake128, digest::{Update, ExtendableOutput, XofReader}};
use hex_literal::hex;

let mut hasher = Shake128::default();
hasher.update(b"abc");
let mut reader = hasher.finalize_xof();
let mut buf = [0u8; 10];
reader.read(&mut buf);
assert_eq!(buf, hex!("5881092dd818bf5cf8a3"));
reader.read(&mut buf);
assert_eq!(buf, hex!("ddb793fbcba74097d5c5"));
```

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

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

[SHA-3]: https://en.wikipedia.org/wiki/SHA-3
[`shake`]: http://docs.rs/shake
[`digest`]: https://docs.rs/digest
21 changes: 1 addition & 20 deletions sha3/benches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
extern crate test;

use digest::bench_update;
use sha3::{
Sha3_224, Sha3_256, Sha3_384, Sha3_512,
shake::{Shake128, Shake256},
};
use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512};
use test::Bencher;

bench_update!(
Expand Down Expand Up @@ -39,19 +36,3 @@ bench_update!(
sha3_512_1000 1000;
sha3_512_10000 10000;
);

bench_update!(
Shake128::default();
shake128_10 10;
shake128_100 100;
shake128_1000 1000;
shake128_10000 10000;
);

bench_update!(
Shake256::default();
shake256_10 10;
shake256_100 100;
shake256_1000 1000;
shake256_10000 10000;
);
4 changes: 1 addition & 3 deletions sha3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ use digest::{
},
consts::{U28, U32, U48, U64, U72, U104, U136, U144, U200, U201},
};

#[cfg(feature = "oid")]
mod oids;
mod utils;

/// Implementation of the SHAKE function.
pub mod shake;

macro_rules! impl_fixed {
($(
$(#[$attr:meta])*
Expand Down
5 changes: 1 addition & 4 deletions sha3/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use digest::dev::{fixed_reset_test, xof_reset_test};
use digest::dev::fixed_reset_test;
use digest::new_test;

new_test!(sha3_224_kat, sha3::Sha3_224, fixed_reset_test);
new_test!(sha3_256_kat, sha3::Sha3_256, fixed_reset_test);
new_test!(sha3_384_kat, sha3::Sha3_384, fixed_reset_test);
new_test!(sha3_512_kat, sha3::Sha3_512, fixed_reset_test);

new_test!(shake128_kat, sha3::shake::Shake128, xof_reset_test);
new_test!(shake256_kat, sha3::shake::Shake256, xof_reset_test);

// Test vectors from https://github.com/kazcw/yellowsun/blob/test-keccak/src/lib.rs#L171
new_test!(keccak_224_kat, sha3::Keccak224, fixed_reset_test);
new_test!(keccak_256_kat, sha3::Keccak256, fixed_reset_test);
Expand Down
11 changes: 11 additions & 0 deletions shake/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.1.0 (2026-05-13)
- Initial release with implementation moved from the `sha3` crate ([#869])

[#869]: https://github.com/RustCrypto/hashes/pull/869
30 changes: 30 additions & 0 deletions shake/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "shake"
version = "0.1.0"
authors = ["RustCrypto Developers"]
edition = "2024"
rust-version = "1.85"
documentation = "https://docs.rs/shake"
readme = "README.md"
repository = "https://github.com/RustCrypto/hashes"
license = "MIT OR Apache-2.0"
keywords = ["sha3", "keccak", "hash", "xof", "digest"]
categories = ["cryptography", "no-std"]
description = "Implementation of the SHAKE family of extendable-output functions (XOFs)"

[dependencies]
digest = { version = "0.11", default-features = false }
sponge-cursor = "0.1"
keccak = "0.2"

[dev-dependencies]
digest = { version = "0.11", default-features = false, features = ["dev"] }
hex-literal = "1"

[features]
default = ["alloc"]
alloc = ["digest/alloc"]
zeroize = ["digest/zeroize", "sponge-cursor/zeroize"]

[package.metadata.docs.rs]
all-features = true
Loading
Loading