| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | //! Ascon is a 320-bit permutation, selected as new standard for lightweight cryptography |
| 2 | 2 | //! in the NIST Lightweight Cryptography competition (2019–2023). |
| 3 | | //! https://csrc.nist.gov/News/2023/lightweight-cryptography-nist-selects-ascon |
| 3 | //! https://csrc.nist.gov/pubs/sp/800/232/ipd |
| 4 | 4 | //! |
| 5 | 5 | //! The permutation is compact, and optimized for timing and side channel resistance, |
| 6 | 6 | //! making it a good choice for embedded applications. |
| ... | ... | @@ -19,8 +19,9 @@ const native_endian = builtin.cpu.arch.endian(); |
| 19 | 19 | /// |
| 20 | 20 | /// The state is represented as 5 64-bit words. |
| 21 | 21 | /// |
| 22 | | /// The NIST submission (v1.2) serializes these words as big-endian, |
| 23 | | /// but software implementations are free to use native endianness. |
| 22 | /// The original NIST submission (v1.2) serializes these words as big-endian, |
| 23 | /// but NIST SP 800-232 switched to a little-endian representation. |
| 24 | /// Software implementations are free to use native endianness with no security degradation. |
| 24 | 25 | pub fn State(comptime endian: std.builtin.Endian) type { |
| 25 | 26 | return struct { |
| 26 | 27 | const Self = @This(); |
| ... | ... | @@ -157,7 +158,7 @@ pub fn State(comptime endian: std.builtin.Endian) type { |
| 157 | 158 | |
| 158 | 159 | /// Apply a reduced-round permutation to the state. |
| 159 | 160 | pub inline fn permuteR(state: *Self, comptime rounds: u4) void { |
| 160 | | const rks = [12]u64{ 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, 0x78, 0x69, 0x5a, 0x4b }; |
| 161 | const rks = [16]u64{ 0x3c, 0x2d, 0x1e, 0x0f, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, 0x78, 0x69, 0x5a, 0x4b }; |
| 161 | 162 | inline for (rks[rks.len - rounds ..]) |rk| { |
| 162 | 163 | state.round(rk); |
| 163 | 164 | } |