authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-11-02 23:56:26+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-05 17:21:19-05:00
loge7b60b219be3885718425d8ddf25d38d3808e90e
treeb11c4a58b9cbda15aeb94d405c4985cbd4b606b5
parent2e354c387e5b5f9a033c29e622ea4a4dbb04bccb

std/crypto: don't constrain Gimli hash output to a fixed length

As documented in the comment right above the finalization function, Gimli can be used as a XOF, i.e. the output doesn't have a fixed length. So, allow it to be used that way, just like BLAKE3.

1 files changed, 2 insertions(+), 2 deletions(-)

lib/std/crypto/gimli.zig+2-2
...@@ -250,7 +250,7 @@ pub const Hash = struct {...@@ -250,7 +250,7 @@ pub const Hash = struct {
250 /// By default, Gimli-Hash provides a fixed-length output of 32 bytes250 /// By default, Gimli-Hash provides a fixed-length output of 32 bytes
251 /// (the concatenation of two 16-byte blocks). However, Gimli-Hash can251 /// (the concatenation of two 16-byte blocks). However, Gimli-Hash can
252 /// be used as an “extendable one-way function” (XOF).252 /// be used as an “extendable one-way function” (XOF).
253 pub fn final(self: *Self, out: *[digest_length]u8) void {253 pub fn final(self: *Self, out: []u8) void {
254 const buf = self.state.toSlice();254 const buf = self.state.toSlice();
255255
256 // XOR 1 into the next byte of the state256 // XOR 1 into the next byte of the state
...@@ -262,7 +262,7 @@ pub const Hash = struct {...@@ -262,7 +262,7 @@ pub const Hash = struct {
262 }262 }
263};263};
264264
265pub fn hash(out: *[Hash.digest_length]u8, in: []const u8, options: Hash.Options) void {265pub fn hash(out: []u8, in: []const u8, options: Hash.Options) void {
266 var st = Hash.init(options);266 var st = Hash.init(options);
267 st.update(in);267 st.update(in);
268 st.final(out);268 st.final(out);