@zigc/lib 0.17.0-dev.224 → 0.17.0-dev.242

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/c/math.zig +31 -2
  2. package/compiler/build_runner.zig +1 -1
  3. package/compiler/reduce/Walk.zig +1 -6
  4. package/compiler/resinator/compile.zig +1 -1
  5. package/compiler/resinator/cvtres.zig +4 -4
  6. package/compiler/resinator/ico.zig +4 -4
  7. package/compiler/resinator/parse.zig +2 -2
  8. package/compiler/resinator/res.zig +1 -1
  9. package/compiler/translate-c/ast.zig +11 -21
  10. package/compiler_rt/atomics.zig +1 -1
  11. package/compiler_rt/cos.zig +1 -1
  12. package/compiler_rt/rem_pio2l.zig +1 -1
  13. package/compiler_rt/sin.zig +1 -1
  14. package/compiler_rt/sincos.zig +1 -1
  15. package/compiler_rt/ssp.zig +2 -2
  16. package/compiler_rt/tan.zig +1 -1
  17. package/docs/wasm/Walk.zig +1 -3
  18. package/docs/wasm/html_render.zig +1 -2
  19. package/package.json +1 -1
  20. package/std/Build/Step/ConfigHeader.zig +1 -1
  21. package/std/Io/Kqueue.zig +1 -1
  22. package/std/Io/Reader.zig +0 -5
  23. package/std/Io/Threaded.zig +4 -4
  24. package/std/Io/Writer.zig +1 -2
  25. package/std/Io/net/HostName.zig +11 -6
  26. package/std/Random/ChaCha.zig +2 -2
  27. package/std/Random/benchmark.zig +2 -2
  28. package/std/Thread.zig +2 -2
  29. package/std/base64.zig +5 -5
  30. package/std/bit_set.zig +83 -66
  31. package/std/c.zig +19 -19
  32. package/std/compress/flate/Decompress.zig +1 -1
  33. package/std/crypto/25519/curve25519.zig +2 -2
  34. package/std/crypto/25519/edwards25519.zig +3 -3
  35. package/std/crypto/25519/ristretto255.zig +2 -2
  36. package/std/crypto/25519/scalar.zig +6 -6
  37. package/std/crypto/25519/x25519.zig +1 -1
  38. package/std/crypto/Certificate.zig +1 -1
  39. package/std/crypto/Sha1.zig +1 -1
  40. package/std/crypto/aegis.zig +45 -39
  41. package/std/crypto/aes_ccm.zig +20 -20
  42. package/std/crypto/aes_gcm.zig +10 -12
  43. package/std/crypto/aes_ocb.zig +9 -9
  44. package/std/crypto/argon2.zig +15 -15
  45. package/std/crypto/bcrypt.zig +20 -10
  46. package/std/crypto/benchmark.zig +7 -7
  47. package/std/crypto/blake2.zig +100 -64
  48. package/std/crypto/cbc_mac.zig +1 -1
  49. package/std/crypto/chacha20.zig +10 -10
  50. package/std/crypto/cmac.zig +2 -2
  51. package/std/crypto/codecs/asn1.zig +1 -1
  52. package/std/crypto/codecs/base64_hex_ct.zig +1 -1
  53. package/std/crypto/ecdsa.zig +9 -9
  54. package/std/crypto/ff.zig +2 -2
  55. package/std/crypto/ghash_polyval.zig +4 -4
  56. package/std/crypto/hkdf.zig +1 -1
  57. package/std/crypto/isap.zig +3 -3
  58. package/std/crypto/kangarootwelve.zig +1 -1
  59. package/std/crypto/keccak_p.zig +7 -7
  60. package/std/crypto/md5.zig +1 -1
  61. package/std/crypto/ml_dsa.zig +33 -33
  62. package/std/crypto/ml_kem.zig +4 -4
  63. package/std/crypto/modes.zig +1 -1
  64. package/std/crypto/pbkdf2.zig +1 -1
  65. package/std/crypto/pcurves/p256/scalar.zig +3 -3
  66. package/std/crypto/pcurves/p384/scalar.zig +2 -2
  67. package/std/crypto/pcurves/secp256k1/scalar.zig +3 -3
  68. package/std/crypto/pcurves/tests/p256.zig +5 -5
  69. package/std/crypto/pcurves/tests/p384.zig +5 -5
  70. package/std/crypto/pcurves/tests/secp256k1.zig +3 -3
  71. package/std/crypto/salsa20.zig +8 -8
  72. package/std/crypto/sha2.zig +2 -2
  73. package/std/crypto/sha3.zig +2 -2
  74. package/std/crypto/siphash.zig +1 -1
  75. package/std/crypto/timing_safe.zig +5 -4
  76. package/std/crypto/tls/Client.zig +10 -9
  77. package/std/crypto.zig +3 -3
  78. package/std/debug/Dwarf.zig +1 -1
  79. package/std/debug.zig +6 -4
  80. package/std/elf.zig +1 -1
  81. package/std/enums.zig +3 -3
  82. package/std/fmt/parse_float/decimal.zig +1 -1
  83. package/std/fmt.zig +5 -1
  84. package/std/fs/path.zig +1 -1
  85. package/std/hash/Adler32.zig +3 -3
  86. package/std/hash/benchmark.zig +2 -2
  87. package/std/hash/wyhash.zig +1 -1
  88. package/std/heap/debug_allocator.zig +1 -1
  89. package/std/http.zig +1 -1
  90. package/std/json/static.zig +2 -2
  91. package/std/math/big/int.zig +3 -3
  92. package/std/math/float.zig +62 -0
  93. package/std/math/nextafter.zig +1 -2
  94. package/std/math/powi.zig +2 -3
  95. package/std/math/signbit.zig +0 -1
  96. package/std/math.zig +13 -18
  97. package/std/mem.zig +9 -8
  98. package/std/meta.zig +1 -1
  99. package/std/os/emscripten.zig +2 -2
  100. package/std/os/linux.zig +4 -4
  101. package/std/os/uefi/hii.zig +1 -1
  102. package/std/std.zig +3 -0
  103. package/std/tar/Writer.zig +39 -33
  104. package/std/tar.zig +8 -4
  105. package/std/testing.zig +1 -1
  106. package/std/unicode.zig +13 -8
  107. package/std/zig/Ast/Render.zig +1 -25
  108. package/std/zig/Ast.zig +5 -28
  109. package/std/zig/AstGen.zig +75 -184
  110. package/std/zig/AstRlAnnotate.zig +1 -11
  111. package/std/zig/AstSmith.zig +5 -11
  112. package/std/zig/LibCInstallation.zig +1 -1
  113. package/std/zig/Parse.zig +4 -69
  114. package/std/zig/TokenSmith.zig +0 -6
  115. package/std/zig/WindowsSdk.zig +1 -1
  116. package/std/zig/Zir.zig +0 -54
  117. package/std/zig/ZonGen.zig +0 -1
  118. package/std/zig/llvm/Builder.zig +3 -7
  119. package/std/zig/tokenizer.zig +4 -43
  120. package/std/zig.zig +0 -2
  121. package/compiler_rt/long_double.zig +0 -37
  122. package/libc/mingw/math/lrintl.c +0 -18
  123. package/libc/mingw/math/rintl.c +0 -16
  124. package/libc/musl/src/math/i386/lrintl.c +0 -8
  125. package/libc/musl/src/math/i386/rintl.c +0 -7
  126. package/libc/musl/src/math/lrintl.c +0 -36
  127. package/libc/musl/src/math/rintl.c +0 -29
  128. package/libc/musl/src/math/s390x/rintl.c +0 -15
  129. package/libc/musl/src/math/x32/lrintl.s +0 -7
  130. package/libc/musl/src/math/x32/rintl.s +0 -6
  131. package/libc/musl/src/math/x86_64/lrintl.c +0 -8
  132. package/libc/musl/src/math/x86_64/rintl.c +0 -7
@@ -55,6 +55,14 @@ pub const Aegis256X2_256 = Aegis256XGeneric(2, 256);
55
55
  /// AEGIS-256 with a 256 bit tag
56
56
  pub const Aegis256_256 = Aegis256XGeneric(1, 256);
57
57
 
58
+ /// `inline` to avoid needless binary bloat from generic instantiations since the arguments are
59
+ /// usually comptime-known and the function is a trivial leaf function.
60
+ inline fn repeat16u8(comptime count: usize, part: [16]u8) [16 * count]u8 {
61
+ const buf: [count][part.len]u8 = @splat(part);
62
+ const ptr: *const [16 * count]u8 = @ptrCast(&buf);
63
+ return ptr.*;
64
+ }
65
+
58
66
  fn State128X(comptime degree: u7) type {
59
67
  return struct {
60
68
  const AesBlockVec = crypto.core.aes.BlockVec(degree);
@@ -67,10 +75,10 @@ fn State128X(comptime degree: u7) type {
67
75
  const alignment = AesBlockVec.native_word_size;
68
76
 
69
77
  fn init(key: [16]u8, nonce: [16]u8) State {
70
- const c1 = AesBlockVec.fromBytes(&[16]u8{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd } ** degree);
71
- const c2 = AesBlockVec.fromBytes(&[16]u8{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 } ** degree);
72
- const key_block = AesBlockVec.fromBytes(&(key ** degree));
73
- const nonce_block = AesBlockVec.fromBytes(&(nonce ** degree));
78
+ const c1 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd }));
79
+ const c2 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 }));
80
+ const key_block = AesBlockVec.fromBytes(&repeat16u8(degree, key));
81
+ const nonce_block = AesBlockVec.fromBytes(&repeat16u8(degree, nonce));
74
82
  const blocks = [8]AesBlockVec{
75
83
  key_block.xorBlocks(nonce_block),
76
84
  c1,
@@ -84,7 +92,7 @@ fn State128X(comptime degree: u7) type {
84
92
  var state = State{ .blocks = blocks };
85
93
  if (degree > 1) {
86
94
  const context_block = ctx: {
87
- var contexts_bytes = [_]u8{0} ** aes_block_length;
95
+ var contexts_bytes: [aes_block_length]u8 = @splat(0);
88
96
  for (0..degree) |i| {
89
97
  contexts_bytes[i * 16] = @intCast(i);
90
98
  contexts_bytes[i * 16 + 1] = @intCast(degree - 1);
@@ -150,7 +158,7 @@ fn State128X(comptime degree: u7) type {
150
158
  const blocks = &state.blocks;
151
159
  const z0 = blocks[6].xorBlocks(blocks[1]).xorBlocks(blocks[2].andBlocks(blocks[3]));
152
160
  const z1 = blocks[2].xorBlocks(blocks[5]).xorBlocks(blocks[6].andBlocks(blocks[7]));
153
- var pad = [_]u8{0} ** rate;
161
+ var pad: [rate]u8 = @splat(0);
154
162
  pad[0..aes_block_length].* = z0.toBytes();
155
163
  pad[aes_block_length..].* = z1.toBytes();
156
164
  for (pad[0..src.len], src) |*p, x| p.* ^= x;
@@ -214,7 +222,7 @@ fn State128X(comptime degree: u7) type {
214
222
  state.update(t, t);
215
223
  }
216
224
  if (degree > 1) {
217
- var v = [_]u8{0} ** rate;
225
+ var v: [rate]u8 = @splat(0);
218
226
  switch (tag_bits) {
219
227
  128 => {
220
228
  const tags = blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).xorBlocks(blocks[5]).xorBlocks(blocks[6]).toBytes();
@@ -362,12 +370,12 @@ fn State256X(comptime degree: u7) type {
362
370
  const alignment = AesBlockVec.native_word_size;
363
371
 
364
372
  fn init(key: [32]u8, nonce: [32]u8) State {
365
- const c1 = AesBlockVec.fromBytes(&[16]u8{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd } ** degree);
366
- const c2 = AesBlockVec.fromBytes(&[16]u8{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 } ** degree);
367
- const key_block1 = AesBlockVec.fromBytes(key[0..16] ** degree);
368
- const key_block2 = AesBlockVec.fromBytes(key[16..32] ** degree);
369
- const nonce_block1 = AesBlockVec.fromBytes(nonce[0..16] ** degree);
370
- const nonce_block2 = AesBlockVec.fromBytes(nonce[16..32] ** degree);
373
+ const c1 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd }));
374
+ const c2 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 }));
375
+ const key_block1 = AesBlockVec.fromBytes(&repeat16u8(degree, key[0..16].*));
376
+ const key_block2 = AesBlockVec.fromBytes(&repeat16u8(degree, key[16..32].*));
377
+ const nonce_block1 = AesBlockVec.fromBytes(&repeat16u8(degree, nonce[0..16].*));
378
+ const nonce_block2 = AesBlockVec.fromBytes(&repeat16u8(degree, nonce[16..32].*));
371
379
  const kxn1 = key_block1.xorBlocks(nonce_block1);
372
380
  const kxn2 = key_block2.xorBlocks(nonce_block2);
373
381
  const blocks = [6]AesBlockVec{
@@ -381,7 +389,7 @@ fn State256X(comptime degree: u7) type {
381
389
  var state = State{ .blocks = blocks };
382
390
  if (degree > 1) {
383
391
  const context_block = ctx: {
384
- var contexts_bytes = [_]u8{0} ** aes_block_length;
392
+ var contexts_bytes: [aes_block_length]u8 = @splat(0);
385
393
  for (0..degree) |i| {
386
394
  contexts_bytes[i * 16] = @intCast(i);
387
395
  contexts_bytes[i * 16 + 1] = @intCast(degree - 1);
@@ -509,7 +517,7 @@ fn State256X(comptime degree: u7) type {
509
517
  state.update(t);
510
518
  }
511
519
  if (degree > 1) {
512
- var v = [_]u8{0} ** rate;
520
+ var v: [rate]u8 = @splat(0);
513
521
  switch (tag_bits) {
514
522
  128 => {
515
523
  const tags = blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).xorBlocks(blocks[5]).toBytes();
@@ -746,9 +754,7 @@ fn AegisMac(comptime T: type) type {
746
754
 
747
755
  /// Initialize a state for the MAC function, with a default nonce
748
756
  pub fn init(key: *const [key_length]u8) Mac {
749
- return Mac{
750
- .state = T.State.init(key.*, [_]u8{0} ** nonce_length),
751
- };
757
+ return .{ .state = .init(key.*, @splat(0)) };
752
758
  }
753
759
 
754
760
  /// Add data to the state
@@ -781,7 +787,7 @@ fn AegisMac(comptime T: type) type {
781
787
  /// Return an authentication tag for the current state
782
788
  pub fn final(self: *Mac, out: *[mac_length]u8) void {
783
789
  if (self.off > 0) {
784
- var pad = [_]u8{0} ** block_length;
790
+ var pad: [block_length]u8 = @splat(0);
785
791
  @memcpy(pad[0..self.off], self.buf[0..self.off]);
786
792
  self.state.absorb(&pad);
787
793
  }
@@ -808,8 +814,8 @@ const htest = @import("test.zig");
808
814
  const testing = std.testing;
809
815
 
810
816
  test "Aegis128L test vector 1" {
811
- const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 14;
812
- const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 13;
817
+ const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ @as([14]u8, @splat(0x00));
818
+ const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([13]u8, @splat(0x00));
813
819
  const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
814
820
  const m = [32]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };
815
821
  var c: [m.len]u8 = undefined;
@@ -831,10 +837,10 @@ test "Aegis128L test vector 1" {
831
837
  }
832
838
 
833
839
  test "Aegis128L test vector 2" {
834
- const key: [Aegis128L.key_length]u8 = [_]u8{0x00} ** 16;
835
- const nonce: [Aegis128L.nonce_length]u8 = [_]u8{0x00} ** 16;
836
- const ad = [_]u8{};
837
- const m = [_]u8{0x00} ** 16;
840
+ const key: [Aegis128L.key_length]u8 = @splat(0x00);
841
+ const nonce: [Aegis128L.nonce_length]u8 = @splat(0x00);
842
+ const ad: [0]u8 = .{};
843
+ const m: [16]u8 = @splat(0x00);
838
844
  var c: [m.len]u8 = undefined;
839
845
  var m2: [m.len]u8 = undefined;
840
846
  var tag: [Aegis128L.tag_length]u8 = undefined;
@@ -848,8 +854,8 @@ test "Aegis128L test vector 2" {
848
854
  }
849
855
 
850
856
  test "Aegis128L test vector 3" {
851
- const key: [Aegis128L.key_length]u8 = [_]u8{0x00} ** 16;
852
- const nonce: [Aegis128L.nonce_length]u8 = [_]u8{0x00} ** 16;
857
+ const key: [Aegis128L.key_length]u8 = @splat(0x00);
858
+ const nonce: [Aegis128L.nonce_length]u8 = @splat(0x00);
853
859
  const ad = [_]u8{};
854
860
  const m = [_]u8{};
855
861
  var c: [m.len]u8 = undefined;
@@ -881,8 +887,8 @@ test "Aegis128X2 test vector 1" {
881
887
  }
882
888
 
883
889
  test "Aegis256 test vector 1" {
884
- const key: [Aegis256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 30;
885
- const nonce: [Aegis256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 29;
890
+ const key: [Aegis256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ @as([30]u8, @splat(0x00));
891
+ const nonce: [Aegis256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([29]u8, @splat(0x00));
886
892
  const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
887
893
  const m = [32]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };
888
894
  var c: [m.len]u8 = undefined;
@@ -904,10 +910,10 @@ test "Aegis256 test vector 1" {
904
910
  }
905
911
 
906
912
  test "Aegis256 test vector 2" {
907
- const key: [Aegis256.key_length]u8 = [_]u8{0x00} ** 32;
908
- const nonce: [Aegis256.nonce_length]u8 = [_]u8{0x00} ** 32;
913
+ const key: [Aegis256.key_length]u8 = @splat(0x00);
914
+ const nonce: [Aegis256.nonce_length]u8 = @splat(0x00);
909
915
  const ad = [_]u8{};
910
- const m = [_]u8{0x00} ** 16;
916
+ const m: [16]u8 = @splat(0x00);
911
917
  var c: [m.len]u8 = undefined;
912
918
  var m2: [m.len]u8 = undefined;
913
919
  var tag: [Aegis256.tag_length]u8 = undefined;
@@ -921,8 +927,8 @@ test "Aegis256 test vector 2" {
921
927
  }
922
928
 
923
929
  test "Aegis256 test vector 3" {
924
- const key: [Aegis256.key_length]u8 = [_]u8{0x00} ** 32;
925
- const nonce: [Aegis256.nonce_length]u8 = [_]u8{0x00} ** 32;
930
+ const key: [Aegis256.key_length]u8 = @splat(0x00);
931
+ const nonce: [Aegis256.nonce_length]u8 = @splat(0x00);
926
932
  const ad = [_]u8{};
927
933
  const m = [_]u8{};
928
934
  var c: [m.len]u8 = undefined;
@@ -954,7 +960,7 @@ test "Aegis256X4 test vector 1" {
954
960
  }
955
961
 
956
962
  test "Aegis MAC" {
957
- const key = [_]u8{0x00} ** Aegis128LMac.key_length;
963
+ const key: [Aegis128LMac.key_length]u8 = @splat(0x00);
958
964
  var msg: [64]u8 = undefined;
959
965
  for (&msg, 0..) |*m, i| {
960
966
  m.* = @as(u8, @truncate(i));
@@ -989,8 +995,8 @@ test "Aegis MAC" {
989
995
  }
990
996
 
991
997
  test "AEGISMAC-128* test vectors" {
992
- const key = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** (16 - 2);
993
- const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** (16 - 3);
998
+ const key = [_]u8{ 0x10, 0x01 } ++ @as([16 - 2]u8, @splat(0x00));
999
+ const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([16 - 3]u8, @splat(0x00));
994
1000
  var msg: [35]u8 = undefined;
995
1001
  for (&msg, 0..) |*byte, i| byte.* = @truncate(i);
996
1002
  var mac128: [16]u8 = undefined;
@@ -1013,8 +1019,8 @@ test "AEGISMAC-128* test vectors" {
1013
1019
  }
1014
1020
 
1015
1021
  test "AEGISMAC-256* test vectors" {
1016
- const key = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** (32 - 2);
1017
- const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** (32 - 3);
1022
+ const key = [_]u8{ 0x10, 0x01 } ++ @as([32 - 2]u8, @splat(0x00));
1023
+ const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([32 - 3]u8, @splat(0x00));
1018
1024
  var msg: [35]u8 = undefined;
1019
1025
  for (&msg, 0..) |*byte, i| byte.* = @truncate(i);
1020
1026
  var mac128: [16]u8 = undefined;
@@ -201,7 +201,7 @@ fn AesCcm(comptime BlockCipher: type, comptime tag_len: usize, comptime nonce_le
201
201
  const total_ad_size = ad_len_size + ad.len;
202
202
  const remainder = total_ad_size % block_length;
203
203
  if (remainder > 0) {
204
- const padding = [_]u8{0} ** block_length;
204
+ const padding: [block_length]u8 = @splat(0);
205
205
  ctx.update(padding[0 .. block_length - remainder]);
206
206
  }
207
207
  }
@@ -264,8 +264,8 @@ const fmt = std.fmt;
264
264
  const hexToBytes = fmt.hexToBytes;
265
265
 
266
266
  test "Aes256Ccm8 - Encrypt decrypt round-trip" {
267
- const key: [32]u8 = [_]u8{0x42} ** 32;
268
- const nonce: [13]u8 = [_]u8{0x11} ** 13;
267
+ const key: [32]u8 = @splat(0x42);
268
+ const nonce: [13]u8 = @splat(0x11);
269
269
  const m = "Hello, World! This is a test message.";
270
270
  var c: [m.len]u8 = undefined;
271
271
  var m2: [m.len]u8 = undefined;
@@ -279,8 +279,8 @@ test "Aes256Ccm8 - Encrypt decrypt round-trip" {
279
279
  }
280
280
 
281
281
  test "Aes256Ccm8 - Associated data" {
282
- const key: [32]u8 = [_]u8{0x42} ** 32;
283
- const nonce: [13]u8 = [_]u8{0x11} ** 13;
282
+ const key: [32]u8 = @splat(0x42);
283
+ const nonce: [13]u8 = @splat(0x11);
284
284
  const m = "secret message";
285
285
  const ad = "additional authenticated data";
286
286
  var c: [m.len]u8 = undefined;
@@ -299,9 +299,9 @@ test "Aes256Ccm8 - Associated data" {
299
299
  }
300
300
 
301
301
  test "Aes256Ccm8 - Wrong key" {
302
- const key: [32]u8 = [_]u8{0x42} ** 32;
303
- const wrong_key: [32]u8 = [_]u8{0x43} ** 32;
304
- const nonce: [13]u8 = [_]u8{0x11} ** 13;
302
+ const key: [32]u8 = @splat(0x42);
303
+ const wrong_key: [32]u8 = @splat(0x43);
304
+ const nonce: [13]u8 = @splat(0x11);
305
305
  const m = "secret";
306
306
  var c: [m.len]u8 = undefined;
307
307
  var m2: [m.len]u8 = undefined;
@@ -314,8 +314,8 @@ test "Aes256Ccm8 - Wrong key" {
314
314
  }
315
315
 
316
316
  test "Aes256Ccm8 - Corrupted ciphertext" {
317
- const key: [32]u8 = [_]u8{0x42} ** 32;
318
- const nonce: [13]u8 = [_]u8{0x11} ** 13;
317
+ const key: [32]u8 = @splat(0x42);
318
+ const nonce: [13]u8 = @splat(0x11);
319
319
  const m = "secret message";
320
320
  var c: [m.len]u8 = undefined;
321
321
  var m2: [m.len]u8 = undefined;
@@ -330,8 +330,8 @@ test "Aes256Ccm8 - Corrupted ciphertext" {
330
330
  }
331
331
 
332
332
  test "Aes256Ccm8 - Empty plaintext" {
333
- const key: [32]u8 = [_]u8{0x42} ** 32;
334
- const nonce: [13]u8 = [_]u8{0x11} ** 13;
333
+ const key: [32]u8 = @splat(0x42);
334
+ const nonce: [13]u8 = @splat(0x11);
335
335
  const m = "";
336
336
  var c: [m.len]u8 = undefined;
337
337
  var m2: [m.len]u8 = undefined;
@@ -345,8 +345,8 @@ test "Aes256Ccm8 - Empty plaintext" {
345
345
  }
346
346
 
347
347
  test "Aes128Ccm8 - Basic functionality" {
348
- const key: [16]u8 = [_]u8{0x42} ** 16;
349
- const nonce: [13]u8 = [_]u8{0x11} ** 13;
348
+ const key: [16]u8 = @splat(0x42);
349
+ const nonce: [13]u8 = @splat(0x11);
350
350
  const m = "Test AES-128-CCM";
351
351
  var c: [m.len]u8 = undefined;
352
352
  var m2: [m.len]u8 = undefined;
@@ -360,8 +360,8 @@ test "Aes128Ccm8 - Basic functionality" {
360
360
  }
361
361
 
362
362
  test "Aes256Ccm16 - 16-byte tag" {
363
- const key: [32]u8 = [_]u8{0x42} ** 32;
364
- const nonce: [13]u8 = [_]u8{0x11} ** 13;
363
+ const key: [32]u8 = @splat(0x42);
364
+ const nonce: [13]u8 = @splat(0x11);
365
365
  const m = "Test 16-byte tag";
366
366
  var c: [m.len]u8 = undefined;
367
367
  var m2: [m.len]u8 = undefined;
@@ -845,8 +845,8 @@ test "Aes128Ccm0 - IEEE 802.15.4 Data Frame (Encryption-only)" {
845
845
  }
846
846
 
847
847
  test "Aes128Ccm0 - Zero-length plaintext with encryption-only" {
848
- const key: [16]u8 = [_]u8{0x42} ** 16;
849
- const nonce: [13]u8 = [_]u8{0x11} ** 13;
848
+ const key: [16]u8 = @splat(0x42);
849
+ const nonce: [13]u8 = @splat(0x11);
850
850
  const m = "";
851
851
  const ad = "some associated data";
852
852
  var c: [m.len]u8 = undefined;
@@ -861,8 +861,8 @@ test "Aes128Ccm0 - Zero-length plaintext with encryption-only" {
861
861
  }
862
862
 
863
863
  test "Aes256Ccm0 - Basic encryption-only round-trip" {
864
- const key: [32]u8 = [_]u8{0x42} ** 32;
865
- const nonce: [13]u8 = [_]u8{0x11} ** 13;
864
+ const key: [32]u8 = @splat(0x42);
865
+ const nonce: [13]u8 = @splat(0x11);
866
866
  const m = "Hello, CCM* encryption-only mode!";
867
867
  var c: [m.len]u8 = undefined;
868
868
  var m2: [m.len]u8 = undefined;
@@ -19,8 +19,6 @@ fn AesGcm(comptime Aes: anytype) type {
19
19
  pub const nonce_length = 12;
20
20
  pub const key_length = Aes.key_bits / 8;
21
21
 
22
- const zeros = [_]u8{0} ** 16;
23
-
24
22
  /// `c`: The ciphertext buffer to write the encrypted data to.
25
23
  /// `tag`: The authentication tag buffer to write the computed tag to.
26
24
  /// `m`: The plaintext message to encrypt.
@@ -33,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type {
33
31
 
34
32
  const aes = Aes.initEnc(key);
35
33
  var h: [16]u8 = undefined;
36
- aes.encrypt(&h, &zeros);
34
+ aes.encrypt(&h, &@splat(0));
37
35
 
38
36
  var t: [16]u8 = undefined;
39
37
  var j: [16]u8 = undefined;
@@ -75,7 +73,7 @@ fn AesGcm(comptime Aes: anytype) type {
75
73
 
76
74
  const aes = Aes.initEnc(key);
77
75
  var h: [16]u8 = undefined;
78
- aes.encrypt(&h, &zeros);
76
+ aes.encrypt(&h, &@splat(0));
79
77
 
80
78
  var t: [16]u8 = undefined;
81
79
  var j: [16]u8 = undefined;
@@ -118,8 +116,8 @@ const htest = @import("test.zig");
118
116
  const testing = std.testing;
119
117
 
120
118
  test "Aes256Gcm - Empty message and no associated data" {
121
- const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length;
122
- const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length;
119
+ const key: [Aes256Gcm.key_length]u8 = @splat(0x69);
120
+ const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42);
123
121
  const ad = "";
124
122
  const m = "";
125
123
  var c: [m.len]u8 = undefined;
@@ -130,8 +128,8 @@ test "Aes256Gcm - Empty message and no associated data" {
130
128
  }
131
129
 
132
130
  test "Aes256Gcm - Associated data only" {
133
- const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length;
134
- const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length;
131
+ const key: [Aes256Gcm.key_length]u8 = @splat(0x69);
132
+ const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42);
135
133
  const m = "";
136
134
  const ad = "Test with associated data";
137
135
  var c: [m.len]u8 = undefined;
@@ -142,8 +140,8 @@ test "Aes256Gcm - Associated data only" {
142
140
  }
143
141
 
144
142
  test "Aes256Gcm - Message only" {
145
- const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length;
146
- const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length;
143
+ const key: [Aes256Gcm.key_length]u8 = @splat(0x69);
144
+ const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42);
147
145
  const m = "Test with message only";
148
146
  const ad = "";
149
147
  var c: [m.len]u8 = undefined;
@@ -159,8 +157,8 @@ test "Aes256Gcm - Message only" {
159
157
  }
160
158
 
161
159
  test "Aes256Gcm - Message and associated data" {
162
- const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length;
163
- const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length;
160
+ const key: [Aes256Gcm.key_length]u8 = @splat(0x69);
161
+ const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42);
164
162
  const m = "Test with message";
165
163
  const ad = "Test with associated data";
166
164
  var c: [m.len]u8 = undefined;
@@ -48,7 +48,7 @@ fn AesOcb(comptime Aes: anytype) type {
48
48
  }
49
49
 
50
50
  fn init(aes_enc_ctx: EncryptCtx) Lx {
51
- const zeros = [_]u8{0} ** 16;
51
+ const zeros: [16]u8 = @splat(0);
52
52
  var star: Block = undefined;
53
53
  aes_enc_ctx.encrypt(&star, &zeros);
54
54
  const dol = double(star);
@@ -62,8 +62,8 @@ fn AesOcb(comptime Aes: anytype) type {
62
62
  const full_blocks: usize = a.len / 16;
63
63
  const x_max = if (full_blocks > 0) math.log2_int(usize, full_blocks) else 0;
64
64
  const lt = lx.precomp(x_max);
65
- var sum = [_]u8{0} ** 16;
66
- var offset = [_]u8{0} ** 16;
65
+ var sum: [16]u8 = @splat(0);
66
+ var offset: [16]u8 = @splat(0);
67
67
  var i: usize = 0;
68
68
  while (i < full_blocks) : (i += 1) {
69
69
  xorWith(&offset, lt[@ctz(i + 1)]);
@@ -74,7 +74,7 @@ fn AesOcb(comptime Aes: anytype) type {
74
74
  const leftover = a.len % 16;
75
75
  if (leftover > 0) {
76
76
  xorWith(&offset, lx.star);
77
- var padded = [_]u8{0} ** 16;
77
+ var padded: [16]u8 = @splat(0);
78
78
  @memcpy(padded[0..leftover], a[i * 16 ..][0..leftover]);
79
79
  padded[leftover] = 0x80;
80
80
  var e = xorBlocks(offset, padded);
@@ -85,7 +85,7 @@ fn AesOcb(comptime Aes: anytype) type {
85
85
  }
86
86
 
87
87
  fn getOffset(aes_enc_ctx: EncryptCtx, npub: [nonce_length]u8) Block {
88
- var nx = [_]u8{0} ** 16;
88
+ var nx: [16]u8 = @splat(0);
89
89
  nx[0] = @as(u8, @intCast(@as(u7, @truncate(tag_length * 8)) << 1));
90
90
  nx[16 - nonce_length - 1] = 1;
91
91
  nx[nx.len - nonce_length ..].* = npub;
@@ -121,7 +121,7 @@ fn AesOcb(comptime Aes: anytype) type {
121
121
  const lt = lx.precomp(x_max);
122
122
 
123
123
  var offset = getOffset(aes_enc_ctx, npub);
124
- var sum = [_]u8{0} ** 16;
124
+ var sum: [16]u8 = @splat(0);
125
125
  var i: usize = 0;
126
126
 
127
127
  while (wb > 0 and i + wb <= full_blocks) : (i += wb) {
@@ -155,7 +155,7 @@ fn AesOcb(comptime Aes: anytype) type {
155
155
  xorWith(&offset, lx.star);
156
156
  var pad = offset;
157
157
  aes_enc_ctx.encrypt(&pad, &pad);
158
- var e = [_]u8{0} ** 16;
158
+ var e: [16]u8 = @splat(0);
159
159
  @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
160
160
  e[leftover] = 0x80;
161
161
  for (m[i * 16 ..], 0..) |x, j| {
@@ -188,7 +188,7 @@ fn AesOcb(comptime Aes: anytype) type {
188
188
  const lt = lx.precomp(x_max);
189
189
 
190
190
  var offset = getOffset(aes_enc_ctx, npub);
191
- var sum = [_]u8{0} ** 16;
191
+ var sum: [16]u8 = @splat(0);
192
192
  var i: usize = 0;
193
193
 
194
194
  while (wb > 0 and i + wb <= full_blocks) : (i += wb) {
@@ -226,7 +226,7 @@ fn AesOcb(comptime Aes: anytype) type {
226
226
  for (c[i * 16 ..], 0..) |x, j| {
227
227
  m[i * 16 + j] = pad[j] ^ x;
228
228
  }
229
- var e = [_]u8{0} ** 16;
229
+ var e: [16]u8 = @splat(0);
230
230
  @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
231
231
  e[leftover] = 0x80;
232
232
  xorWith(&sum, e);
@@ -281,9 +281,9 @@ fn processSegment(
281
281
  slice: u32,
282
282
  lane: u24,
283
283
  ) void {
284
- var addresses align(16) = [_]u64{0} ** block_length;
285
- var in align(16) = [_]u64{0} ** block_length;
286
- const zero align(16) = [_]u64{0} ** block_length;
284
+ var addresses: [block_length]u64 align(16) = @splat(0);
285
+ var in: [block_length]u64 align(16) = @splat(0);
286
+ const zero: [block_length]u64 align(16) = @splat(0);
287
287
  if (mode == .argon2i or (mode == .argon2id and n == 0 and slice < sync_points / 2)) {
288
288
  in[0] = n;
289
289
  in[1] = lane;
@@ -629,10 +629,10 @@ pub fn strVerify(
629
629
  test "argon2d" {
630
630
  if (true) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/30074
631
631
 
632
- const password = [_]u8{0x01} ** 32;
633
- const salt = [_]u8{0x02} ** 16;
634
- const secret = [_]u8{0x03} ** 8;
635
- const ad = [_]u8{0x04} ** 12;
632
+ const password: [32]u8 = @splat(0x01);
633
+ const salt: [16]u8 = @splat(0x02);
634
+ const secret: [8]u8 = @splat(0x03);
635
+ const ad: [12]u8 = @splat(0x04);
636
636
 
637
637
  var dk: [32]u8 = undefined;
638
638
  try kdf(
@@ -655,10 +655,10 @@ test "argon2d" {
655
655
  }
656
656
 
657
657
  test "argon2i" {
658
- const password = [_]u8{0x01} ** 32;
659
- const salt = [_]u8{0x02} ** 16;
660
- const secret = [_]u8{0x03} ** 8;
661
- const ad = [_]u8{0x04} ** 12;
658
+ const password: [32]u8 = @splat(0x01);
659
+ const salt: [16]u8 = @splat(0x02);
660
+ const secret: [8]u8 = @splat(0x03);
661
+ const ad: [12]u8 = @splat(0x04);
662
662
 
663
663
  var dk: [32]u8 = undefined;
664
664
  try kdf(
@@ -681,10 +681,10 @@ test "argon2i" {
681
681
  }
682
682
 
683
683
  test "argon2id" {
684
- const password = [_]u8{0x01} ** 32;
685
- const salt = [_]u8{0x02} ** 16;
686
- const secret = [_]u8{0x03} ** 8;
687
- const ad = [_]u8{0x04} ** 12;
684
+ const password: [32]u8 = @splat(0x01);
685
+ const salt: [16]u8 = @splat(0x02);
686
+ const secret: [8]u8 = @splat(0x03);
687
+ const ad: [12]u8 = @splat(0x04);
688
688
 
689
689
  var dk: [32]u8 = undefined;
690
690
  try kdf(
@@ -868,20 +868,25 @@ test "bcrypt crypt format" {
868
868
  strVerify(s, "invalid password", verify_options),
869
869
  );
870
870
 
871
+ const password_100: []const u8 = password: {
872
+ const arr: [100][8]u8 = @splat("password".*);
873
+ break :password @ptrCast(&arr);
874
+ };
875
+
871
876
  var long_buf: [hash_length]u8 = undefined;
872
- var long_s = try strHash("password" ** 100, hash_options, &long_buf, io);
877
+ var long_s = try strHash(password_100, hash_options, &long_buf, io);
873
878
 
874
879
  try testing.expect(mem.startsWith(u8, long_s, crypt_format.prefix));
875
- try strVerify(long_s, "password" ** 100, verify_options);
880
+ try strVerify(long_s, password_100, verify_options);
876
881
  try testing.expectError(
877
882
  error.PasswordVerificationFailed,
878
- strVerify(long_s, "password" ** 101, verify_options),
883
+ strVerify(long_s, password_100 ++ "password", verify_options),
879
884
  );
880
885
 
881
886
  hash_options.params.silently_truncate_password = true;
882
887
  verify_options.silently_truncate_password = true;
883
- long_s = try strHash("password" ** 100, hash_options, &long_buf, io);
884
- try strVerify(long_s, "password" ** 101, verify_options);
888
+ long_s = try strHash(password_100, hash_options, &long_buf, io);
889
+ try strVerify(long_s, password_100 ++ "password", verify_options);
885
890
 
886
891
  try strVerify(
887
892
  "$2b$08$WUQKyBCaKpziCwUXHiMVvu40dYVjkTxtWJlftl0PpjY2BxWSvFIEe",
@@ -909,20 +914,25 @@ test "bcrypt phc format" {
909
914
  strVerify(s, "invalid password", verify_options),
910
915
  );
911
916
 
917
+ const password_100: []const u8 = password: {
918
+ const arr: [100][8]u8 = @splat("password".*);
919
+ break :password @ptrCast(&arr);
920
+ };
921
+
912
922
  var long_buf: [hash_length * 2]u8 = undefined;
913
- var long_s = try strHash("password" ** 100, hash_options, &long_buf, io);
923
+ var long_s = try strHash(password_100, hash_options, &long_buf, io);
914
924
 
915
925
  try testing.expect(mem.startsWith(u8, long_s, prefix));
916
- try strVerify(long_s, "password" ** 100, verify_options);
926
+ try strVerify(long_s, password_100, verify_options);
917
927
  try testing.expectError(
918
928
  error.PasswordVerificationFailed,
919
- strVerify(long_s, "password" ** 101, verify_options),
929
+ strVerify(long_s, password_100 ++ "password", verify_options),
920
930
  );
921
931
 
922
932
  hash_options.params.silently_truncate_password = true;
923
933
  verify_options.silently_truncate_password = true;
924
- long_s = try strHash("password" ** 100, hash_options, &long_buf, io);
925
- try strVerify(long_s, "password" ** 101, verify_options);
934
+ long_s = try strHash(password_100, hash_options, &long_buf, io);
935
+ try strVerify(long_s, password_100 ++ "password", verify_options);
926
936
 
927
937
  try strVerify(
928
938
  "$bcrypt$r=5$2NopntlgE2lX3cTwr4qz8A$r3T7iKYQNnY4hAhGjk9RmuyvgrYJZwc",
@@ -173,7 +173,7 @@ const signatures = [_]Crypto{
173
173
  };
174
174
 
175
175
  pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 {
176
- const msg = [_]u8{0} ** 64;
176
+ const msg: [64]u8 = @splat(0);
177
177
  const key_pair = Signature.KeyPair.generate(io);
178
178
 
179
179
  const start = benchTime(io);
@@ -200,7 +200,7 @@ const signature_verifications = [_]Crypto{
200
200
  };
201
201
 
202
202
  pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 {
203
- const msg = [_]u8{0} ** 64;
203
+ const msg: [64]u8 = @splat(0);
204
204
  const key_pair = Signature.KeyPair.generate(io);
205
205
  const sig = try key_pair.sign(&msg, null);
206
206
 
@@ -223,7 +223,7 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign
223
223
  const batch_signature_verifications = [_]Crypto{Crypto{ .ty = crypto.sign.Ed25519, .name = "ed25519" }};
224
224
 
225
225
  pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 {
226
- const msg = [_]u8{0} ** 64;
226
+ const msg: [64]u8 = @splat(0);
227
227
  const key_pair = Signature.KeyPair.generate(io);
228
228
  const sig = try key_pair.sign(&msg, null);
229
229
 
@@ -367,7 +367,7 @@ pub fn benchmarkAes(comptime Aes: anytype, comptime count: comptime_int, io: Io)
367
367
  random.bytes(key[0..]);
368
368
  const ctx = Aes.initEnc(key);
369
369
 
370
- var in = [_]u8{0} ** 16;
370
+ var in: [16]u8 = @splat(0);
371
371
 
372
372
  const start = benchTime(io);
373
373
  {
@@ -395,7 +395,7 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int, io: Io
395
395
  random.bytes(key[0..]);
396
396
  const ctx = Aes.initEnc(key);
397
397
 
398
- var in = [_]u8{0} ** (8 * 16);
398
+ var in: [8 * 16]u8 = @splat(0);
399
399
 
400
400
  const start = benchTime(io);
401
401
  {
@@ -444,7 +444,7 @@ fn benchmarkPwhash(
444
444
  comptime count: comptime_int,
445
445
  io: std.Io,
446
446
  ) !f64 {
447
- const password = "testpass" ** 2;
447
+ const password = "testpasstestpass";
448
448
  const opts = ty.HashOptions{
449
449
  .allocator = allocator,
450
450
  .params = @as(*const ty.Params, @ptrCast(@alignCast(params))).*,
@@ -456,7 +456,7 @@ fn benchmarkPwhash(
456
456
  const strHashFnInfo = @typeInfo(@TypeOf(strHash)).@"fn";
457
457
  const needs_io = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type == std.Io;
458
458
  const needs_salt = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type != std.Io;
459
- const salt: [16]u8 = .{0} ** 16;
459
+ const salt: [16]u8 = @splat(0);
460
460
 
461
461
  const start = benchTime(io);
462
462
  {