| ... | @@ -733,6 +733,32 @@ test "xoroshiro sequence" { | ... | @@ -733,6 +733,32 @@ test "xoroshiro sequence" { |
| 733 | } | 733 | } |
| 734 | } | 734 | } |
| 735 | | 735 | |
| | 736 | // Gimli |
| | 737 | // |
| | 738 | // CSPRNG |
| | 739 | pub const Gimli = struct { |
| | 740 | random: Random, |
| | 741 | state: std.crypto.gimli.State, |
| | 742 | |
| | 743 | pub fn init(init_s: u64) Gimli { |
| | 744 | var self = Gimli{ |
| | 745 | .random = Random{ .fillFn = fill }, |
| | 746 | .state = std.crypto.gimli.State{ |
| | 747 | .data = [_]u32{0} ** (std.crypto.gimli.State.BLOCKBYTES / 4), |
| | 748 | }, |
| | 749 | }; |
| | 750 | self.state.data[0] = @truncate(u32, init_s >> 32); |
| | 751 | self.state.data[1] = @truncate(u32, init_s); |
| | 752 | return self; |
| | 753 | } |
| | 754 | |
| | 755 | fn fill(r: *Random, buf: []u8) void { |
| | 756 | const self = @fieldParentPtr(Gimli, "random", r); |
| | 757 | |
| | 758 | self.state.squeeze(buf); |
| | 759 | } |
| | 760 | }; |
| | 761 | |
| 736 | // ISAAC64 - http://www.burtleburtle.net/bob/rand/isaacafa.html | 762 | // ISAAC64 - http://www.burtleburtle.net/bob/rand/isaacafa.html |
| 737 | // | 763 | // |
| 738 | // CSPRNG | 764 | // CSPRNG |