mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 22:04:21 +00:00
std.crypto.sha3: Minor TurboSHAKE/Keccak fixes (#16408)
This commit is contained in:
parent
094cd92615
commit
3022c525ec
2 changed files with 13 additions and 7 deletions
|
|
@ -56,7 +56,7 @@ pub fn KeccakF(comptime f: u11) type {
|
||||||
/// Byte-swap the entire state if the architecture doesn't match the required endianness.
|
/// Byte-swap the entire state if the architecture doesn't match the required endianness.
|
||||||
pub fn endianSwap(self: *Self) void {
|
pub fn endianSwap(self: *Self) void {
|
||||||
for (&self.st) |*w| {
|
for (&self.st) |*w| {
|
||||||
w.* = mem.littleTooNative(T, w.*);
|
w.* = mem.littleToNative(T, w.*);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,15 @@ pub const Shake256 = Shake(256);
|
||||||
/// TurboSHAKE128 is a XOF (a secure hash function with a variable output length), with a 128 bit security level.
|
/// TurboSHAKE128 is a XOF (a secure hash function with a variable output length), with a 128 bit security level.
|
||||||
/// It is based on the same permutation as SHA3 and SHAKE128, but which much higher performance.
|
/// It is based on the same permutation as SHA3 and SHAKE128, but which much higher performance.
|
||||||
/// The delimiter is 0x1f by default, but can be changed for context-separation.
|
/// The delimiter is 0x1f by default, but can be changed for context-separation.
|
||||||
pub fn TurboShake128(comptime delim: ?u8) type {
|
/// For a protocol that uses both KangarooTwelve and TurboSHAKE128, it is recommended to avoid using 0x06, 0x07 or 0x0b for the delimiter.
|
||||||
|
pub fn TurboShake128(comptime delim: ?u7) type {
|
||||||
return TurboShake(128, delim);
|
return TurboShake(128, delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TurboSHAKE256 is a XOF (a secure hash function with a variable output length), with a 256 bit security level.
|
/// TurboSHAKE256 is a XOF (a secure hash function with a variable output length), with a 256 bit security level.
|
||||||
/// It is based on the same permutation as SHA3 and SHAKE256, but which much higher performance.
|
/// It is based on the same permutation as SHA3 and SHAKE256, but which much higher performance.
|
||||||
/// The delimiter is 0x01 by default, but can be changed for context-separation.
|
/// The delimiter is 0x1f by default, but can be changed for context-separation.
|
||||||
pub fn TurboShake256(comptime delim: ?u8) type {
|
pub fn TurboShake256(comptime delim: ?u7) type {
|
||||||
return TurboShake(256, delim);
|
return TurboShake(256, delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,9 +95,14 @@ pub fn Shake(comptime security_level: u11) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The TurboSHAKE extendable output hash function.
|
/// The TurboSHAKE extendable output hash function.
|
||||||
/// https://datatracker.ietf.org/doc/draft-irtf-cfrg-kangarootwelve/
|
/// It is based on the same permutation as SHA3 and SHAKE, but which much higher performance.
|
||||||
pub fn TurboShake(comptime security_level: u11, comptime delim: ?u8) type {
|
/// The delimiter is 0x1f by default, but can be changed for context-separation.
|
||||||
return ShakeLike(security_level, delim orelse 0x1f, 12);
|
/// https://eprint.iacr.org/2023/342
|
||||||
|
pub fn TurboShake(comptime security_level: u11, comptime delim: ?u7) type {
|
||||||
|
comptime assert(security_level <= 256);
|
||||||
|
const d = delim orelse 0x1f;
|
||||||
|
comptime assert(d >= 0x01); // delimiter must be >= 1
|
||||||
|
return ShakeLike(security_level, d, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds: u5) type {
|
fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds: u5) type {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue