| ... | @@ -21,14 +21,15 @@ pub const Shake256 = Shake(256); | ... | @@ -21,14 +21,15 @@ pub const Shake256 = Shake(256); |
| 21 | /// TurboSHAKE128 is a XOF (a secure hash function with a variable output length), with a 128 bit security level. | 21 | /// TurboSHAKE128 is a XOF (a secure hash function with a variable output length), with a 128 bit security level. |
| 22 | /// It is based on the same permutation as SHA3 and SHAKE128, but which much higher performance. | 22 | /// It is based on the same permutation as SHA3 and SHAKE128, but which much higher performance. |
| 23 | /// The delimiter is 0x1f by default, but can be changed for context-separation. | 23 | /// The delimiter is 0x1f by default, but can be changed for context-separation. |
| 24 | pub fn TurboShake128(comptime delim: ?u8) type { | 24 | /// For a protocol that uses both KangarooTwelve and TurboSHAKE128, it is recommended to avoid using 0x06, 0x07 or 0x0b for the delimiter. |
| | 25 | pub fn TurboShake128(comptime delim: ?u7) type { |
| 25 | return TurboShake(128, delim); | 26 | return TurboShake(128, delim); |
| 26 | } | 27 | } |
| 27 | | 28 | |
| 28 | /// TurboSHAKE256 is a XOF (a secure hash function with a variable output length), with a 256 bit security level. | 29 | /// TurboSHAKE256 is a XOF (a secure hash function with a variable output length), with a 256 bit security level. |
| 29 | /// It is based on the same permutation as SHA3 and SHAKE256, but which much higher performance. | 30 | /// It is based on the same permutation as SHA3 and SHAKE256, but which much higher performance. |
| 30 | /// The delimiter is 0x01 by default, but can be changed for context-separation. | 31 | /// The delimiter is 0x1f by default, but can be changed for context-separation. |
| 31 | pub fn TurboShake256(comptime delim: ?u8) type { | 32 | pub fn TurboShake256(comptime delim: ?u7) type { |
| 32 | return TurboShake(256, delim); | 33 | return TurboShake(256, delim); |
| 33 | } | 34 | } |
| 34 | | 35 | |
| ... | @@ -94,9 +95,14 @@ pub fn Shake(comptime security_level: u11) type { | ... | @@ -94,9 +95,14 @@ pub fn Shake(comptime security_level: u11) type { |
| 94 | } | 95 | } |
| 95 | | 96 | |
| 96 | /// The TurboSHAKE extendable output hash function. | 97 | /// The TurboSHAKE extendable output hash function. |
| 97 | /// https://datatracker.ietf.org/doc/draft-irtf-cfrg-kangarootwelve/ | 98 | /// It is based on the same permutation as SHA3 and SHAKE, but which much higher performance. |
| 98 | pub fn TurboShake(comptime security_level: u11, comptime delim: ?u8) type { | 99 | /// The delimiter is 0x1f by default, but can be changed for context-separation. |
| 99 | return ShakeLike(security_level, delim orelse 0x1f, 12); | 100 | /// https://eprint.iacr.org/2023/342 |
| | 101 | pub fn TurboShake(comptime security_level: u11, comptime delim: ?u7) type { |
| | 102 | comptime assert(security_level <= 256); |
| | 103 | const d = delim orelse 0x1f; |
| | 104 | comptime assert(d >= 0x01); // delimiter must be >= 1 |
| | 105 | return ShakeLike(security_level, d, 12); |
| 100 | } | 106 | } |
| 101 | | 107 | |
| 102 | fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds: u5) type { | 108 | fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds: u5) type { |