authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2025-11-22 07:54:12+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-11-22 22:09:51-08:00
log0e3b5e6d8fa22eabf8a79a3f0f143a5ba295c2b3
tree0cfa9c94dbaf510bfcb70e12130383edada91213
parent9473011052792b6ab6f2aa635d11e16eb63d512c

blake3: remove unnecessary comptime, digest_length instead of key_length


1 files changed, 7 insertions(+), 9 deletions(-)

lib/std/crypto/blake3.zig+7-9
......@@ -12,8 +12,8 @@ const Vec16 = @Vector(16, u32);
1212const chunk_length = 1024;
1313const max_depth = 54;
1414
15pub const simd_degree = std.simd.suggestVectorLength(u32) orelse 1;
16pub const max_simd_degree = simd_degree;
15const simd_degree = std.simd.suggestVectorLength(u32) orelse 1;
16const max_simd_degree = simd_degree;
1717const max_simd_degree_or_2 = if (max_simd_degree > 2) max_simd_degree else 2;
1818
1919/// Threshold for switching to parallel processing.
......@@ -502,9 +502,7 @@ fn hashManySimd(
502502 var out_ptr = out.ptr;
503503 var cnt = counter;
504504
505 const simd_deg = comptime simd_degree;
506
507 if (comptime simd_deg >= 16) {
505 if (simd_degree >= 16) {
508506 while (remaining >= 16) {
509507 const sixteen_inputs = [16][*]const u8{
510508 inp[0], inp[1], inp[2], inp[3],
......@@ -525,7 +523,7 @@ fn hashManySimd(
525523 }
526524 }
527525
528 if (comptime simd_deg >= 8) {
526 if (simd_degree >= 8) {
529527 while (remaining >= 8) {
530528 const eight_inputs = [8][*]const u8{
531529 inp[0], inp[1], inp[2], inp[3],
......@@ -544,7 +542,7 @@ fn hashManySimd(
544542 }
545543 }
546544
547 if (comptime simd_deg >= 4) {
545 if (simd_degree >= 4) {
548546 while (remaining >= 4) {
549547 const four_inputs = [4][*]const u8{
550548 inp[0],
......@@ -571,7 +569,7 @@ fn hashManySimd(
571569}
572570
573571fn hashMany(inputs: [][*]const u8, num_inputs: usize, blocks: usize, key: [8]u32, counter: u64, increment_counter: bool, flags: Flags, flags_start: Flags, flags_end: Flags, out: []u8) void {
574 if (comptime max_simd_degree >= 4) {
572 if (max_simd_degree >= 4) {
575573 hashManySimd(inputs, num_inputs, blocks, key, counter, increment_counter, flags, flags_start, flags_end, out);
576574 } else {
577575 hashManyPortable(inputs, num_inputs, blocks, key, counter, increment_counter, flags, flags_start, flags_end, out);
......@@ -909,7 +907,7 @@ pub const Blake3 = struct {
909907 pub const digest_length = 32;
910908 pub const key_length = 32;
911909
912 pub const Options = struct { key: ?[digest_length]u8 = null };
910 pub const Options = struct { key: ?[key_length]u8 = null };
913911 pub const KdfOptions = struct {};
914912
915913 key: [8]u32,