| ... | ... | @@ -119,11 +119,11 @@ fn compress( |
| 119 | 119 | return state; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | | fn first_8_words(compression_output: [16]u32) [8]u32 { |
| 123 | | return @ptrCast(*const [8]u32, &compression_output).*; |
| 122 | fn first_8_words(words: [16]u32) [8]u32 { |
| 123 | return @ptrCast(*const [8]u32, &words).*; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | | fn words_from_little_endian_bytes(bytes: []const u8, words: []u32) void { |
| 126 | fn words_from_little_endian_bytes(words: []u32, bytes: []const u8) void { |
| 127 | 127 | var byte_slice = bytes; |
| 128 | 128 | for (words) |*word| { |
| 129 | 129 | word.* = mem.readIntSliceLittle(u32, byte_slice); |
| ... | ... | @@ -141,7 +141,7 @@ const Output = struct { |
| 141 | 141 | counter: u64, |
| 142 | 142 | flags: u8, |
| 143 | 143 | |
| 144 | | fn chaining_value(self: *Output) [8]u32 { |
| 144 | fn chaining_value(self: *const Output) [8]u32 { |
| 145 | 145 | return first_8_words(compress( |
| 146 | 146 | self.input_chaining_value, |
| 147 | 147 | self.block_words, |
| ... | ... | @@ -151,7 +151,7 @@ const Output = struct { |
| 151 | 151 | )); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | | fn root_output_bytes(self: *Output, output: []u8) void { |
| 154 | fn root_output_bytes(self: *const Output, output: []u8) void { |
| 155 | 155 | var out_block_it = ChunkIterator.init(output, 2 * OUT_LEN); |
| 156 | 156 | var output_block_counter: usize = 0; |
| 157 | 157 | while (out_block_it.next()) |out_block| { |
| ... | ... | @@ -214,7 +214,7 @@ const ChunkState = struct { |
| 214 | 214 | // input is coming, so this compression is not CHUNK_END. |
| 215 | 215 | if (self.block_len == BLOCK_LEN) { |
| 216 | 216 | var block_words: [16]u32 = undefined; |
| 217 | | words_from_little_endian_bytes(&self.block, &block_words); |
| 217 | words_from_little_endian_bytes(&block_words, &self.block); |
| 218 | 218 | self.chaining_value = first_8_words(compress( |
| 219 | 219 | self.chaining_value, |
| 220 | 220 | block_words, |
| ... | ... | @@ -234,7 +234,7 @@ const ChunkState = struct { |
| 234 | 234 | |
| 235 | 235 | fn output(self: *const ChunkState) Output { |
| 236 | 236 | var block_words: [16]u32 = undefined; |
| 237 | | words_from_little_endian_bytes(&self.block, &block_words); |
| 237 | words_from_little_endian_bytes(&block_words, &self.block); |
| 238 | 238 | return Output{ |
| 239 | 239 | .input_chaining_value = self.chaining_value, |
| 240 | 240 | .block_words = block_words, |
| ... | ... | @@ -299,7 +299,7 @@ pub const Blake3 = struct { |
| 299 | 299 | /// Construct a new `Blake3` for the keyed hash function. |
| 300 | 300 | pub fn init_keyed(key: [KEY_LEN]u8) Blake3 { |
| 301 | 301 | var key_words: [8]u32 = undefined; |
| 302 | | words_from_little_endian_bytes(key[0..], &key_words); |
| 302 | words_from_little_endian_bytes(&key_words, key[0..]); |
| 303 | 303 | return Blake3.init_internal(key_words, KEYED_HASH); |
| 304 | 304 | } |
| 305 | 305 | |
| ... | ... | @@ -311,7 +311,7 @@ pub const Blake3 = struct { |
| 311 | 311 | var context_key: [KEY_LEN]u8 = undefined; |
| 312 | 312 | context_hasher.final(context_key[0..]); |
| 313 | 313 | var context_key_words: [8]u32 = undefined; |
| 314 | | words_from_little_endian_bytes(&context_key, &context_key_words); |
| 314 | words_from_little_endian_bytes(&context_key_words, &context_key); |
| 315 | 315 | return Blake3.init_internal(context_key_words, DERIVE_KEY_MATERIAL); |
| 316 | 316 | } |
| 317 | 317 | |
| ... | ... | @@ -327,12 +327,12 @@ pub const Blake3 = struct { |
| 327 | 327 | self.cv_stack_len = 0; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | | fn push_stack(self: *Blake3, cv: [8]u32) void { |
| 330 | fn push_cv(self: *Blake3, cv: [8]u32) void { |
| 331 | 331 | self.cv_stack[self.cv_stack_len] = cv; |
| 332 | 332 | self.cv_stack_len += 1; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | | fn pop_stack(self: *Blake3) [8]u32 { |
| 335 | fn pop_cv(self: *Blake3) [8]u32 { |
| 336 | 336 | self.cv_stack_len -= 1; |
| 337 | 337 | return self.cv_stack[self.cv_stack_len]; |
| 338 | 338 | } |
| ... | ... | @@ -348,10 +348,10 @@ pub const Blake3 = struct { |
| 348 | 348 | // by the number of trailing 0-bits in the new total number of chunks. |
| 349 | 349 | var chunk_counter = total_chunks; |
| 350 | 350 | while (chunk_counter & 1 == 0) { |
| 351 | | new_cv = parent_cv(self.pop_stack(), new_cv, self.key, self.flags); |
| 351 | new_cv = parent_cv(self.pop_cv(), new_cv, self.key, self.flags); |
| 352 | 352 | chunk_counter >>= 1; |
| 353 | 353 | } |
| 354 | | self.push_stack(new_cv); |
| 354 | self.push_cv(new_cv); |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /// Add input to the hash state. This can be called any number of times. |
| ... | ... | @@ -376,7 +376,7 @@ pub const Blake3 = struct { |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /// Finalize the hash and write any number of output bytes. |
| 379 | | pub fn final(self: *Blake3, out_slice: []u8) void { |
| 379 | pub fn final(self: *const Blake3, out_slice: []u8) void { |
| 380 | 380 | // Starting with the Output from the current chunk, compute all the |
| 381 | 381 | // parent chaining values along the right edge of the tree, until we |
| 382 | 382 | // have the root Output. |