authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-07-08 02:01:12+10:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-02-06 00:16:00+11:00
log5a095a3f083f5e2248b0d37bf499c350ad18179f
treef0a8b53f66201c6d00211647528556f7a2b7e8c5
parent25cbee0b84074368c23b7540a63cba83162e4b73
signaturelock-open Commit is signed but in an unrecognized format.

std: add Gimli based PRNG to std.rand


1 files changed, 26 insertions(+), 0 deletions(-)

lib/std/rand.zig+26
...@@ -733,6 +733,32 @@ test "xoroshiro sequence" {...@@ -733,6 +733,32 @@ test "xoroshiro sequence" {
733 }733 }
734}734}
735735
736// Gimli
737//
738// CSPRNG
739pub 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.html762// ISAAC64 - http://www.burtleburtle.net/bob/rand/isaacafa.html
737//763//
738// CSPRNG764// CSPRNG