35 Commits

Author SHA1 Message Date
agureev
c4b35a1346 chore: add Risc0 zkVM dependency 2026-06-23 16:25:41 +04:00
Artyom Pavlov
609b63ecbf
keccak: replace keccak_soft_compact with keccak_backend_soft="compact" (#116)
This would allow to extend configuration knobs for the software backend
in future and would be more consisted with potential similar knobs for
other backends.
2026-03-16 00:00:06 +03:00
Artyom Pavlov
d96c7f3733
Use the standard order of [package] fields (#115)
See https://github.com/RustCrypto/meta/issues/22
2026-03-12 04:17:45 +03:00
Artyom Pavlov
1efeff7d02
keccak: refactor to a closure-based API (#113)
The new API provides a better way for exposing support for parallel
processing in implemented backends and resolves the issue with branching
on each application of a Keccak permutation.
2026-03-06 16:07:46 +03:00
Tony Arcieri
806d446c41
keccak: convert ARMv8 ASM into intrinsics (#112)
Rewrites the inline assembly implementation using an equivalent (but not
identical) intrinsics implementation. Also exposes support for computing
two Keccak states in parallel which a previous comment in the ASM
implementation noted was possible but wasn't actually exposed, and is
now available as `p1600_armv8_sha3_times2` (though not yet in the public
API, see #110).

This is a little tricky due to high register pressure: this
implementation uses every vector register.

I started by rewriting the round loop and iterating over the round
constants, then breaking apart the body into theta and everything else
(rho/pi/chi/iota), mapping the NEON registers onto a `[uint64x2_t; 25]`
state.

Theta was translated by hand, but the rest of them were too tedious
regarding a manual mapping of the registers to slots in the state array.
So I wrote a small program that operates over a representation of the
original assembly, doing all the bookkeeping for which registers map to
which slots in the state array, and outputs the equivalent intrinsics
code.

Godbolt links to the original `asm!` versus this translation:
- original: https://godbolt.org/z/G8Mf5vboE
- translated: https://godbolt.org/z/sszzbdexK

It's using nearly the same number of instructions, but there are
differences between the two versions, i.e. it isn't an identical
recreation of the original assembly, which I'm not sure is
possible/preferable, but it should be functionally equivalent.

Since we're no longer using `asm!`, `cfg(armv8_asm)` has been removed
and this is now enabled by default on `aarch64` targets.

Closes #95 

# Benchmarks (`sha3` crate on M1 Max)
## Pure software implementation

test sha3_224_10    ... bench:          17.97 ns/iter (+/- 0.32) = 588 MB/s
test sha3_224_100   ... bench:         164.15 ns/iter (+/- 5.14) = 609 MB/s
test sha3_224_1000  ... bench:       1,646.07 ns/iter (+/- 139.45) = 607 MB/s
test sha3_224_10000 ... bench:      16,585.52 ns/iter (+/- 1,168.57) = 602 MB/s
test sha3_256_10    ... bench:          19.12 ns/iter (+/- 0.77) = 526 MB/s
test sha3_256_1000  ... bench:       1,694.21 ns/iter (+/- 41.20) = 590 MB/s
test sha3_256_10000 ... bench:      16,807.40 ns/iter (+/- 556.17) = 594 MB/s
test sha3_265_100   ... bench:         173.41 ns/iter (+/- 4.98) = 578 MB/s
test sha3_384_10    ... bench:          24.32 ns/iter (+/- 1.16) = 416 MB/s
test sha3_384_100   ... bench:         225.00 ns/iter (+/- 5.50) = 444 MB/s
test sha3_384_1000  ... bench:       2,224.49 ns/iter (+/- 47.86) = 449 MB/s
test sha3_384_10000 ... bench:      22,181.02 ns/iter (+/- 971.37) = 450 MB/s
test sha3_512_10    ... bench:          33.78 ns/iter (+/- 0.32) = 303 MB/s
test sha3_512_100   ... bench:         320.54 ns/iter (+/- 10.77) = 312 MB/s
test sha3_512_1000  ... bench:       3,174.62 ns/iter (+/- 80.98) = 315 MB/s
test sha3_512_10000 ... bench:      31,629.97 ns/iter (+/- 871.85) = 316 MB/s
test shake128_10    ... bench:          15.97 ns/iter (+/- 0.44) = 666 MB/s
test shake128_100   ... bench:         142.19 ns/iter (+/- 6.58) = 704 MB/s
test shake128_1000  ... bench:       1,390.27 ns/iter (+/- 56.14) = 719 MB/s
test shake128_10000 ... bench:      13,813.13 ns/iter (+/- 677.65) = 723 MB/s
test shake256_10    ... bench:          19.06 ns/iter (+/- 0.44) = 526 MB/s
test shake256_100   ... bench:         173.50 ns/iter (+/- 4.26) = 578 MB/s
test shake256_1000  ... bench:       1,695.05 ns/iter (+/- 87.19) = 589 MB/s
test shake256_10000 ... bench:      16,882.98 ns/iter (+/- 683.56) = 592 MB/s

## This new intrinsics implementation
test sha3_224_10    ... bench:          13.07 ns/iter (+/- 0.55) = 769 MB/s
test sha3_224_100   ... bench:         111.29 ns/iter (+/- 6.62) = 900 MB/s
test sha3_224_1000  ... bench:       1,113.87 ns/iter (+/- 29.88) = 898 MB/s
test sha3_224_10000 ... bench:      11,095.95 ns/iter (+/- 302.99) = 901 MB/s
test sha3_256_10    ... bench:          13.53 ns/iter (+/- 0.51) = 769 MB/s
test sha3_256_1000  ... bench:       1,173.40 ns/iter (+/- 33.72) = 852 MB/s
test sha3_256_10000 ... bench:      12,305.99 ns/iter (+/- 623.31) = 812 MB/s
test sha3_265_100   ... bench:         118.16 ns/iter (+/- 2.85) = 847 MB/s
test sha3_384_10    ... bench:          17.27 ns/iter (+/- 0.78) = 588 MB/s
test sha3_384_100   ... bench:         153.80 ns/iter (+/- 5.42) = 653 MB/s
test sha3_384_1000  ... bench:       1,529.35 ns/iter (+/- 18.99) = 654 MB/s
test sha3_384_10000 ... bench:      15,239.19 ns/iter (+/- 189.19) = 656 MB/s
test sha3_512_10    ... bench:          23.43 ns/iter (+/- 0.95) = 434 MB/s
test sha3_512_100   ... bench:         218.97 ns/iter (+/- 4.01) = 458 MB/s
test sha3_512_1000  ... bench:       2,193.58 ns/iter (+/- 37.98) = 455 MB/s
test sha3_512_10000 ... bench:      21,968.75 ns/iter (+/- 385.75) = 455 MB/s
test shake128_10    ... bench:          11.47 ns/iter (+/- 0.32) = 909 MB/s
test shake128_100   ... bench:          95.51 ns/iter (+/- 1.32) = 1052 MB/s
test shake128_1000  ... bench:         960.08 ns/iter (+/- 34.57) = 1041 MB/s
test shake128_10000 ... bench:       9,564.39 ns/iter (+/- 255.34) = 1045 MB/s
test shake256_10    ... bench:          13.61 ns/iter (+/- 0.53) = 769 MB/s
test shake256_100   ... bench:         116.77 ns/iter (+/- 1.94) = 862 MB/s
test shake256_1000  ... bench:       1,163.09 ns/iter (+/- 27.17) = 859 MB/s
test shake256_10000 ... bench:      11,750.47 ns/iter (+/- 250.38) = 851 MB/s

## Original assembly
test sha3_224_10    ... bench:          12.54 ns/iter (+/- 0.43) = 833 MB/s
test sha3_224_100   ... bench:         109.49 ns/iter (+/- 2.54) = 917 MB/s
test sha3_224_1000  ... bench:       1,095.79 ns/iter (+/- 32.04) = 913 MB/s
test sha3_224_10000 ... bench:      10,953.02 ns/iter (+/- 157.49) = 912 MB/s
test sha3_256_10    ... bench:          13.05 ns/iter (+/- 0.25) = 769 MB/s
test sha3_256_1000  ... bench:       1,161.46 ns/iter (+/- 28.09) = 861 MB/s
test sha3_256_10000 ... bench:      11,609.98 ns/iter (+/- 148.88) = 861 MB/s
test sha3_265_100   ... bench:         118.17 ns/iter (+/- 7.42) = 847 MB/s
test sha3_384_10    ... bench:          17.07 ns/iter (+/- 2.80) = 588 MB/s
test sha3_384_100   ... bench:         151.93 ns/iter (+/- 4.39) = 662 MB/s
test sha3_384_1000  ... bench:       1,506.50 ns/iter (+/- 40.71) = 664 MB/s
test sha3_384_10000 ... bench:      15,119.04 ns/iter (+/- 495.59) = 661 MB/s
test sha3_512_10    ... bench:          22.93 ns/iter (+/- 0.53) = 454 MB/s
test sha3_512_100   ... bench:         216.77 ns/iter (+/- 7.42) = 462 MB/s
test sha3_512_1000  ... bench:       2,165.67 ns/iter (+/- 49.04) = 461 MB/s
test sha3_512_10000 ... bench:      21,666.71 ns/iter (+/- 651.02) = 461 MB/s
test shake128_10    ... bench:          11.30 ns/iter (+/- 0.14) = 909 MB/s
test shake128_100   ... bench:          94.75 ns/iter (+/- 3.86) = 1063 MB/s
test shake128_1000  ... bench:         961.72 ns/iter (+/- 81.88) = 1040 MB/s
test shake128_10000 ... bench:       9,573.39 ns/iter (+/- 311.05) = 1044 MB/s
test shake256_10    ... bench:          13.17 ns/iter (+/- 0.54) = 769 MB/s
test shake256_100   ... bench:         117.39 ns/iter (+/- 3.22) = 854 MB/s
test shake256_1000  ... bench:       1,174.65 ns/iter (+/- 45.62) = 851 MB/s
test shake256_10000 ... bench:      11,659.19 ns/iter (+/- 330.23) = 857 MB/s

The performance seems pretty close to the original assembly, maybe just
slightly slower.
2026-02-27 17:36:55 -07:00
Tony Arcieri
cf29ae32c6
keccak v0.2.0-rc.2 (#111) 2026-02-26 10:56:38 -07:00
Tony Arcieri
38d10d2194
keccak: extract Keccak1600 struct with CPU feature detection (#107)
Extracts a struct to hold the state for Keccak-p1600/Keccak-f1600, along
with a CPU feature detection `InitToken` which is queried at the time
the state is initialized.

The previous `p1600`/`f1600` functions with CPU feature detection
support have been factored onto this struct, leaving the software
implementation available unconditionally as part of the public API, and
avoiding performing CPU feature detection on each invocation of the
permutation.

It looks like it should be possible to slot a struct like this into
something like `Sha3HasherCore` in place of its current `state` array.
2026-02-17 12:33:46 -07:00
Tony Arcieri
9dc0b8d950
keccak: replace asm/simd features with --cfg keccak_backend (#106)
Replaces these non-additive "features" with a 1-of-n backend selection
enabled by using `cfg` instead.

- `asm` => `--cfg keccak_backend="armv8_asm"`
- `simd` => `--cfg keccak_backend="simd"`

Closes #85
2026-02-13 16:04:57 -07:00
Tony Arcieri
a1be08a742
Replace no_unroll feature(s) with soft-compact cfg (#105)
The following crates now have a new `cfg` for backend selection:
- `ascon`: `--cfg ascon_backend="soft-compact"`
- `keccak`: `--cfg keccak_backend="soft-compact"`

This replaces the previous crate features, as suggested in #85
2026-02-13 12:00:57 -07:00
Tony Arcieri
0d9bf82ee5
Add workspace-level clippy config (#100)
Uses the same config from other repos (e.g. `traits`, `utils`)
2026-02-12 15:01:09 -07:00
Tony Arcieri
c3a9ef249e
keccak: bump cpufeatures to v0.3 (#99) 2026-02-12 12:20:53 -07:00
Tony Arcieri
d0c9b2a828
keccak v0.2.0-rc.1 (#98) 2026-01-22 11:10:05 -07:00
Tony Arcieri
95a176c25b
Cut new prereleases (#90)
Releases the following:
- `ascon` v0.5.0-rc.0
- `keccak` v0.2.0-rc.0
2025-09-02 20:15:00 -06:00
Tony Arcieri
2bc1c383a4
Upgrade to Rust 2024 edition; MSRV 1.85 (#89) 2025-09-02 20:09:23 -06:00
Artyom Pavlov
710788be9e
Bump MSRV to 1.81 (#84) 2024-11-22 09:43:18 +03:00
Luca Bruno
a30ba7775c
cargo: point repository metadata to clonable URLs (#77)
This tweaks the `repository` fields in Cargo metadata in order to use the correct (i.e. git clonable) URL.
The existing GitHub webUI URLs for each package have been retained and moved to `homepage` fields.
2024-06-10 07:48:30 -06:00
Tony Arcieri
b67665f9bb
keccak v0.2.0-pre.0 (#71) 2024-01-16 12:13:55 -07:00
Tony Arcieri
7675b171ad
keccak: 2021 edition upgrade; MSRV 1.60 (#70)
`keccak` was previously excluded from the toplevel workspace due to its
MSRV of 1.41 and incompatibilities with packages used by `ascon`.

This bumps the edition, changes the version to `0.2.0-pre` to denote it
contains breaking changes (though this is not intended to be a
`0.2.0-pre` release), and bumps MSRV.

With the MSRV bumped, `keccak` can and has been re-added to the toplevel
workspace.
2024-01-12 14:45:05 -07:00
Tony Arcieri
40c50c1641
keccak v0.1.5 (#69) 2024-01-12 11:30:01 -07:00
Tony Arcieri
7cdccabc7a
keccak v0.1.4 (#56) 2023-05-04 11:12:22 -06:00
Tony Arcieri
5831f8bd51
keccak: 2018 edition upgrade, lints, docs (#32)
- Bumps the crate's edition to 2018, which is MSRV-compatible.
- Adds a more expansive set of lints
- Adds the `missing_docs` lint, and adds docs where missing
- Fixes tests on ARMv8
2023-02-11 11:40:15 -07:00
Tony Arcieri
6c98ff8396
keccak v0.1.3 (#28) 2022-11-14 12:30:19 -07:00
Tony Arcieri
a687839512
keccak: add asm feature; use cpufeatures on aarch64 (#24)
Gates `asm` support under a crate feature.

Uses the `cpufeatures` crate to detect the presence of the `sha3`
extension for ARMv8 CPUs, automatically falling back to a software
implementation if it isn't available.

When the `asm` feature is enabled on `aarch64` targets, exposes
`f1600_asm` that relies on ARMv8 `sha3` hardware intrinsics.
2022-11-13 15:15:26 -07:00
Tony Arcieri
b59a4d5aa9
keccak v0.1.2 (#18) 2022-05-24 17:53:43 -06:00
Artyom Pavlov
0901b5f420
Add description of features and remove the dependencies section (#17) 2022-05-24 23:22:02 +00:00
Alexander Wagner
f31b4b6eee
Use portable_simd instead of deprecate packed_simd (#16) 2022-05-24 17:07:32 -06:00
Tony Arcieri
5ec2be1538
keccak v0.1.1 (#15) 2022-05-24 16:35:18 -06:00
Tony Arcieri
79780c5df3
keccak: relicense as Apache 2.0 + MIT (#14)
Was previously CC0 (i.e. public domain)

Closes #5
2022-05-24 16:05:47 -06:00
Tony Arcieri
04b72bea35
keccak: add README.md (#12)
Adds a basic README to the crate
2022-05-24 15:42:59 -06:00
Alexander Wagner
2736330d93
Add f1600x{2, 4, 8} (#8) 2022-05-12 08:49:34 -06:00
Alexander Wagner
a2ef49e5a6
Add generic keccak-p and keccak-f {200, 400, 800} (#7) 2022-05-11 11:36:17 -06:00
Alexander Wagner
71c7948b23
Revive CI with GH Workflows (#6) 2022-01-26 03:26:50 +00:00
newpavlov
35ac0f140f small code cleanup 2018-04-03 19:54:43 +03:00
newpavlov
e986524350 updated keccak Cargo.toml 2018-03-21 16:18:35 +03:00
newpavlov
9bb3d48391 keccak-f[1600] 2018-03-21 15:44:29 +03:00