| ... | @@ -138,40 +138,39 @@ fn initHash( | ... | @@ -138,40 +138,39 @@ fn initHash( |
| 138 | } | 138 | } |
| 139 | | 139 | |
| 140 | fn blake2bLong(out: []u8, in: []const u8) void { | 140 | fn blake2bLong(out: []u8, in: []const u8) void { |
| 141 | var b2 = Blake2b512.init(.{ .expected_out_bits = math.min(512, out.len * 8) }); | 141 | const H = Blake2b512; |
| 142 | | 142 | var outlen_bytes: [4]u8 = undefined; |
| 143 | var buffer: [Blake2b512.digest_length]u8 = undefined; | 143 | mem.writeIntLittle(u32, &outlen_bytes, @intCast(u32, out.len)); |
| 144 | mem.writeIntLittle(u32, buffer[0..4], @intCast(u32, out.len)); | 144 | |
| 145 | b2.update(buffer[0..4]); | 145 | var out_buf: [H.digest_length]u8 = undefined; |
| 146 | b2.update(in); | 146 | |
| 147 | b2.final(&buffer); | 147 | if (out.len <= H.digest_length) { |
| 148 | | 148 | var h = H.init(.{ .expected_out_bits = out.len * 8 }); |
| 149 | if (out.len <= Blake2b512.digest_length) { | 149 | h.update(&outlen_bytes); |
| 150 | mem.copy(u8, out, buffer[0..out.len]); | 150 | h.update(in); |
| | 151 | h.final(&out_buf); |
| | 152 | mem.copy(u8, out, out_buf[0..out.len]); |
| 151 | return; | 153 | return; |
| 152 | } | 154 | } |
| 153 | | 155 | |
| 154 | b2 = Blake2b512.init(.{}); | 156 | var h = H.init(.{}); |
| 155 | mem.copy(u8, out, buffer[0..32]); | 157 | h.update(&outlen_bytes); |
| 156 | var out_slice = out[32..]; | 158 | h.update(in); |
| 157 | while (out_slice.len > Blake2b512.digest_length) : ({ | 159 | h.final(&out_buf); |
| 158 | out_slice = out_slice[32..]; | 160 | var out_slice = out; |
| 159 | b2 = Blake2b512.init(.{}); | 161 | mem.copy(u8, out_slice, out_buf[0 .. H.digest_length / 2]); |
| 160 | }) { | 162 | out_slice = out_slice[H.digest_length / 2 ..]; |
| 161 | b2.update(&buffer); | 163 | |
| 162 | b2.final(&buffer); | 164 | var in_buf: [H.digest_length]u8 = undefined; |
| 163 | mem.copy(u8, out_slice, buffer[0..32]); | 165 | while (out_slice.len > H.digest_length) { |
| 164 | } | 166 | mem.copy(u8, &in_buf, &out_buf); |
| 165 | | 167 | H.hash(&in_buf, &out_buf, .{}); |
| 166 | var r = Blake2b512.digest_length; | 168 | mem.copy(u8, out_slice, out_buf[0 .. H.digest_length / 2]); |
| 167 | if (out.len % Blake2b512.digest_length > 0) { | 169 | out_slice = out_slice[H.digest_length / 2 ..]; |
| 168 | r = ((out.len + 31) / 32) - 2; | | |
| 169 | b2 = Blake2b512.init(.{ .expected_out_bits = r * 8 }); | | |
| 170 | } | 170 | } |
| 171 | | 171 | mem.copy(u8, &in_buf, &out_buf); |
| 172 | b2.update(&buffer); | 172 | H.hash(&in_buf, &out_buf, .{ .expected_out_bits = out_slice.len * 8 }); |
| 173 | b2.final(&buffer); | 173 | mem.copy(u8, out_slice, out_buf[0..out_slice.len]); |
| 174 | mem.copy(u8, out_slice, buffer[0..r]); | | |
| 175 | } | 174 | } |
| 176 | | 175 | |
| 177 | fn initBlocks( | 176 | fn initBlocks( |