Skip to content

Commit

Permalink
sha3: fix types to work with infinite output #132
Browse files Browse the repository at this point in the history
Specifically, this allows callers of `SHAKE` functions to either specify
a concrete output lengths (if the needed length is known at call time)
or infinite length (if there's some additional processing before
truncating the output).
  • Loading branch information
marsella committed Sep 9, 2024
1 parent c514ca2 commit 7a311f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Primitive/Keyless/Hash/SHAKE/SHAKE128.cry
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import Primitive::Keyless::Hash::utils (toBytes)
* SHAKE128 extendable-output function.
* [FIPS-202] Section 6.2.
*
* This supports any output length `d`, including infinite length.
*
* Note that the specification of `c` is above, in the instantiation of the
* `keccak` module.
*/
shake128 : {m, d} (fin m, fin d) => [m] -> [d]
shake128 : {d, m} (fin m) => [m] -> [d]
shake128 M = Keccak (M # 0b1111)

/**
Expand Down
4 changes: 3 additions & 1 deletion Primitive/Keyless/Hash/SHAKE/SHAKE256.cry
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import Primitive::Keyless::Hash::utils (toBytes)
* SHAKE256 extendable-output function.
* [FIPS-202] Section 6.2.
*
* This supports any output length `d`, including infinite length.
*
* Note that the specification of `c` is above, in the instantiation of the
* `keccak` module.
*/
shake256: {m, d} (fin m, fin d) => [m] -> [d]
shake256: {d, m} (fin m) => [m] -> [d]
shake256 M = Keccak (M # 0b1111)

/*
Expand Down
5 changes: 2 additions & 3 deletions Primitive/Keyless/Hash/keccak.cry
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ parameter
* with the specific functions for Keccak (Sec 5.2).
* [FIPS-202] Section 4, Algorithm 8; instantiated as in Section 5.2.
*/
Keccak : {m, d}
(fin m, fin d) => [m] -> [d]
Keccak M = take`{d} (extend (Ss ! 0)) where
Keccak : {d, m} (fin m) => [m] -> [d]
Keccak M = take`{front=d, back=inf} (extend (Ss ! 0)) where
// Step 1.
P = M # pad `{x = r, m = m}
// Step 2.
Expand Down

0 comments on commit 7a311f3

Please sign in to comment.