@zigc/lib 0.17.0-dev.228 → 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 (106) hide show
  1. package/compiler/build_runner.zig +1 -1
  2. package/compiler/reduce/Walk.zig +1 -6
  3. package/compiler/resinator/cvtres.zig +4 -4
  4. package/compiler/resinator/ico.zig +4 -4
  5. package/compiler/resinator/parse.zig +2 -2
  6. package/compiler/resinator/res.zig +1 -1
  7. package/compiler/translate-c/ast.zig +11 -21
  8. package/compiler_rt/atomics.zig +1 -1
  9. package/compiler_rt/ssp.zig +2 -2
  10. package/docs/wasm/Walk.zig +1 -3
  11. package/docs/wasm/html_render.zig +1 -2
  12. package/package.json +1 -1
  13. package/std/Io/Reader.zig +0 -5
  14. package/std/Io/Threaded.zig +4 -4
  15. package/std/Io/Writer.zig +1 -2
  16. package/std/Io/net/HostName.zig +11 -6
  17. package/std/Random/ChaCha.zig +2 -2
  18. package/std/Random/benchmark.zig +2 -2
  19. package/std/Thread.zig +2 -2
  20. package/std/base64.zig +5 -5
  21. package/std/bit_set.zig +7 -7
  22. package/std/c.zig +17 -17
  23. package/std/compress/flate/Decompress.zig +1 -1
  24. package/std/crypto/25519/curve25519.zig +2 -2
  25. package/std/crypto/25519/edwards25519.zig +3 -3
  26. package/std/crypto/25519/ristretto255.zig +2 -2
  27. package/std/crypto/25519/scalar.zig +6 -6
  28. package/std/crypto/25519/x25519.zig +1 -1
  29. package/std/crypto/Certificate.zig +1 -1
  30. package/std/crypto/Sha1.zig +1 -1
  31. package/std/crypto/aegis.zig +45 -39
  32. package/std/crypto/aes_ccm.zig +20 -20
  33. package/std/crypto/aes_gcm.zig +10 -12
  34. package/std/crypto/aes_ocb.zig +9 -9
  35. package/std/crypto/argon2.zig +15 -15
  36. package/std/crypto/bcrypt.zig +20 -10
  37. package/std/crypto/benchmark.zig +7 -7
  38. package/std/crypto/blake2.zig +100 -64
  39. package/std/crypto/cbc_mac.zig +1 -1
  40. package/std/crypto/chacha20.zig +10 -10
  41. package/std/crypto/cmac.zig +2 -2
  42. package/std/crypto/codecs/asn1.zig +1 -1
  43. package/std/crypto/ecdsa.zig +9 -9
  44. package/std/crypto/ff.zig +2 -2
  45. package/std/crypto/ghash_polyval.zig +4 -4
  46. package/std/crypto/hkdf.zig +1 -1
  47. package/std/crypto/isap.zig +3 -3
  48. package/std/crypto/kangarootwelve.zig +1 -1
  49. package/std/crypto/keccak_p.zig +7 -7
  50. package/std/crypto/md5.zig +1 -1
  51. package/std/crypto/ml_dsa.zig +33 -33
  52. package/std/crypto/ml_kem.zig +4 -4
  53. package/std/crypto/modes.zig +1 -1
  54. package/std/crypto/pbkdf2.zig +1 -1
  55. package/std/crypto/pcurves/p256/scalar.zig +3 -3
  56. package/std/crypto/pcurves/p384/scalar.zig +2 -2
  57. package/std/crypto/pcurves/secp256k1/scalar.zig +3 -3
  58. package/std/crypto/pcurves/tests/p256.zig +5 -5
  59. package/std/crypto/pcurves/tests/p384.zig +5 -5
  60. package/std/crypto/pcurves/tests/secp256k1.zig +3 -3
  61. package/std/crypto/salsa20.zig +8 -8
  62. package/std/crypto/sha2.zig +2 -2
  63. package/std/crypto/sha3.zig +2 -2
  64. package/std/crypto/siphash.zig +1 -1
  65. package/std/crypto/timing_safe.zig +5 -4
  66. package/std/crypto/tls/Client.zig +10 -9
  67. package/std/crypto.zig +3 -3
  68. package/std/debug/Dwarf.zig +1 -1
  69. package/std/debug.zig +6 -4
  70. package/std/elf.zig +1 -1
  71. package/std/enums.zig +1 -1
  72. package/std/fmt/parse_float/decimal.zig +1 -1
  73. package/std/fmt.zig +5 -1
  74. package/std/hash/Adler32.zig +3 -3
  75. package/std/hash/benchmark.zig +2 -2
  76. package/std/hash/wyhash.zig +1 -1
  77. package/std/heap/debug_allocator.zig +1 -1
  78. package/std/http.zig +1 -1
  79. package/std/json/static.zig +2 -2
  80. package/std/math/big/int.zig +3 -3
  81. package/std/math/nextafter.zig +1 -2
  82. package/std/math/powi.zig +2 -3
  83. package/std/math/signbit.zig +0 -1
  84. package/std/math.zig +12 -18
  85. package/std/mem.zig +9 -8
  86. package/std/meta.zig +1 -1
  87. package/std/os/emscripten.zig +2 -2
  88. package/std/os/linux.zig +4 -4
  89. package/std/os/uefi/hii.zig +1 -1
  90. package/std/tar/Writer.zig +39 -33
  91. package/std/tar.zig +8 -4
  92. package/std/unicode.zig +13 -8
  93. package/std/zig/Ast/Render.zig +1 -25
  94. package/std/zig/Ast.zig +5 -28
  95. package/std/zig/AstGen.zig +75 -184
  96. package/std/zig/AstRlAnnotate.zig +1 -11
  97. package/std/zig/AstSmith.zig +5 -11
  98. package/std/zig/LibCInstallation.zig +1 -1
  99. package/std/zig/Parse.zig +4 -69
  100. package/std/zig/TokenSmith.zig +0 -6
  101. package/std/zig/WindowsSdk.zig +1 -1
  102. package/std/zig/Zir.zig +0 -54
  103. package/std/zig/ZonGen.zig +0 -1
  104. package/std/zig/llvm/Builder.zig +3 -7
  105. package/std/zig/tokenizer.zig +4 -43
  106. package/std/zig.zig +0 -2
@@ -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
  {
@@ -199,7 +199,9 @@ test "blake2s160 single" {
199
199
  try htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog");
200
200
 
201
201
  const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
202
- try htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
202
+ const repeat_a_32: [32]u8 = @splat('a');
203
+ const repeat_b_32: [32]u8 = @splat('b');
204
+ try htest.assertEqualHash(Blake2s160, h4, &repeat_a_32 ++ &repeat_b_32);
203
205
  }
204
206
 
205
207
  test "blake2s160 streaming" {
@@ -227,27 +229,30 @@ test "blake2s160 streaming" {
227
229
 
228
230
  const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
229
231
 
232
+ const repeat_a_32: [32]u8 = @splat('a');
233
+ const repeat_b_32: [32]u8 = @splat('b');
234
+
230
235
  h = Blake2s160.init(.{});
231
- h.update("a" ** 32);
232
- h.update("b" ** 32);
236
+ h.update(&repeat_a_32);
237
+ h.update(&repeat_b_32);
233
238
  h.final(out[0..]);
234
239
  try htest.assertEqual(h3, out[0..]);
235
240
 
236
241
  h = Blake2s160.init(.{});
237
- h.update("a" ** 32 ++ "b" ** 32);
242
+ h.update(&repeat_a_32 ++ &repeat_b_32);
238
243
  h.final(out[0..]);
239
244
  try htest.assertEqual(h3, out[0..]);
240
245
 
241
246
  const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68";
242
247
 
243
- h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
244
- h.update("a" ** 32);
245
- h.update("b" ** 32);
248
+ h = Blake2s160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
249
+ h.update(&repeat_a_32);
250
+ h.update(&repeat_b_32);
246
251
  h.final(out[0..]);
247
252
  try htest.assertEqual(h4, out[0..]);
248
253
 
249
- h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
250
- h.update("a" ** 32 ++ "b" ** 32);
254
+ h = Blake2s160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
255
+ h.update(&repeat_a_32 ++ &repeat_b_32);
251
256
  h.final(out[0..]);
252
257
  try htest.assertEqual(h4, out[0..]);
253
258
  }
@@ -256,7 +261,7 @@ test "comptime blake2s160" {
256
261
  //comptime
257
262
  {
258
263
  @setEvalBranchQuota(10000);
259
- var block = [_]u8{0} ** Blake2s160.block_length;
264
+ var block: [Blake2s160.block_length]u8 = @splat(0);
260
265
  var out: [Blake2s160.digest_length]u8 = undefined;
261
266
 
262
267
  const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f";
@@ -282,7 +287,9 @@ test "blake2s224 single" {
282
287
  try htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog");
283
288
 
284
289
  const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
285
- try htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
290
+ const repeat_a_32: [32]u8 = @splat('a');
291
+ const repeat_b_32: [32]u8 = @splat('b');
292
+ try htest.assertEqualHash(Blake2s224, h4, &repeat_a_32 ++ &repeat_b_32);
286
293
  }
287
294
 
288
295
  test "blake2s224 streaming" {
@@ -308,29 +315,32 @@ test "blake2s224 streaming" {
308
315
  h.final(out[0..]);
309
316
  try htest.assertEqual(h2, out[0..]);
310
317
 
318
+ const repeat_a_32: [32]u8 = @splat('a');
319
+ const repeat_b_32: [32]u8 = @splat('b');
320
+
311
321
  const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
312
322
 
313
323
  h = Blake2s224.init(.{});
314
- h.update("a" ** 32);
315
- h.update("b" ** 32);
324
+ h.update(&repeat_a_32);
325
+ h.update(&repeat_b_32);
316
326
  h.final(out[0..]);
317
327
  try htest.assertEqual(h3, out[0..]);
318
328
 
319
329
  h = Blake2s224.init(.{});
320
- h.update("a" ** 32 ++ "b" ** 32);
330
+ h.update(&repeat_a_32 ++ &repeat_b_32);
321
331
  h.final(out[0..]);
322
332
  try htest.assertEqual(h3, out[0..]);
323
333
 
324
334
  const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3";
325
335
 
326
- h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
327
- h.update("a" ** 32);
328
- h.update("b" ** 32);
336
+ h = Blake2s224.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
337
+ h.update(&repeat_a_32);
338
+ h.update(&repeat_b_32);
329
339
  h.final(out[0..]);
330
340
  try htest.assertEqual(h4, out[0..]);
331
341
 
332
- h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
333
- h.update("a" ** 32 ++ "b" ** 32);
342
+ h = Blake2s224.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
343
+ h.update(&repeat_a_32 ++ &repeat_b_32);
334
344
  h.final(out[0..]);
335
345
  try htest.assertEqual(h4, out[0..]);
336
346
  }
@@ -338,7 +348,7 @@ test "blake2s224 streaming" {
338
348
  test "comptime blake2s224" {
339
349
  comptime {
340
350
  @setEvalBranchQuota(10000);
341
- var block = [_]u8{0} ** Blake2s224.block_length;
351
+ var block: [Blake2s224.block_length]u8 = @splat(0);
342
352
  var out: [Blake2s224.digest_length]u8 = undefined;
343
353
 
344
354
  const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576";
@@ -364,7 +374,9 @@ test "blake2s256 single" {
364
374
  try htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog");
365
375
 
366
376
  const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
367
- try htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
377
+ const repeat_a_32: [32]u8 = @splat('a');
378
+ const repeat_b_32: [32]u8 = @splat('b');
379
+ try htest.assertEqualHash(Blake2s256, h4, &repeat_a_32 ++ &repeat_b_32);
368
380
  }
369
381
 
370
382
  test "blake2s256 streaming" {
@@ -390,16 +402,19 @@ test "blake2s256 streaming" {
390
402
  h.final(out[0..]);
391
403
  try htest.assertEqual(h2, out[0..]);
392
404
 
405
+ const repeat_a_32: [32]u8 = @splat('a');
406
+ const repeat_b_32: [32]u8 = @splat('b');
407
+
393
408
  const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
394
409
 
395
410
  h = Blake2s256.init(.{});
396
- h.update("a" ** 32);
397
- h.update("b" ** 32);
411
+ h.update(&repeat_a_32);
412
+ h.update(&repeat_b_32);
398
413
  h.final(out[0..]);
399
414
  try htest.assertEqual(h3, out[0..]);
400
415
 
401
416
  h = Blake2s256.init(.{});
402
- h.update("a" ** 32 ++ "b" ** 32);
417
+ h.update(&repeat_a_32 ++ &repeat_b_32);
403
418
  h.final(out[0..]);
404
419
  try htest.assertEqual(h3, out[0..]);
405
420
  }
@@ -410,18 +425,21 @@ test "blake2s256 keyed" {
410
425
  const h1 = "10f918da4d74fab3302e48a5d67d03804b1ec95372a62a0f33b7c9fa28ba1ae6";
411
426
  const key = "secret_key";
412
427
 
413
- Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
428
+ const repeat_a_64: [64]u8 = @splat('a');
429
+ const repeat_b_64: [64]u8 = @splat('b');
430
+
431
+ Blake2s256.hash(&repeat_a_64 ++ &repeat_b_64, &out, .{ .key = key });
414
432
  try htest.assertEqual(h1, out[0..]);
415
433
 
416
434
  var h = Blake2s256.init(.{ .key = key });
417
- h.update("a" ** 64 ++ "b" ** 64);
435
+ h.update(&repeat_a_64 ++ &repeat_b_64);
418
436
  h.final(out[0..]);
419
437
 
420
438
  try htest.assertEqual(h1, out[0..]);
421
439
 
422
440
  h = Blake2s256.init(.{ .key = key });
423
- h.update("a" ** 64);
424
- h.update("b" ** 64);
441
+ h.update(&repeat_a_64);
442
+ h.update(&repeat_b_64);
425
443
  h.final(out[0..]);
426
444
 
427
445
  try htest.assertEqual(h1, out[0..]);
@@ -430,7 +448,7 @@ test "blake2s256 keyed" {
430
448
  test "comptime blake2s256" {
431
449
  comptime {
432
450
  @setEvalBranchQuota(10000);
433
- var block = [_]u8{0} ** Blake2s256.block_length;
451
+ var block: [Blake2s256.block_length]u8 = @splat(0);
434
452
  var out: [Blake2s256.digest_length]u8 = undefined;
435
453
 
436
454
  const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3";
@@ -623,7 +641,9 @@ test "blake2b160 single" {
623
641
  try htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog");
624
642
 
625
643
  const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
626
- try htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
644
+ const repeat_a_64: [64]u8 = @splat('a');
645
+ const repeat_b_64: [64]u8 = @splat('b');
646
+ try htest.assertEqualHash(Blake2b160, h4, &repeat_a_64 ++ &repeat_b_64);
627
647
  }
628
648
 
629
649
  test "blake2b160 streaming" {
@@ -649,36 +669,39 @@ test "blake2b160 streaming" {
649
669
  h.final(out[0..]);
650
670
  try htest.assertEqual(h2, out[0..]);
651
671
 
672
+ const repeat_a_64: [64]u8 = @splat('a');
673
+ const repeat_b_64: [64]u8 = @splat('b');
674
+
652
675
  const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
653
676
 
654
677
  h = Blake2b160.init(.{});
655
- h.update("a" ** 64 ++ "b" ** 64);
678
+ h.update(&repeat_a_64 ++ &repeat_b_64);
656
679
  h.final(out[0..]);
657
680
  try htest.assertEqual(h3, out[0..]);
658
681
 
659
682
  h = Blake2b160.init(.{});
660
- h.update("a" ** 64);
661
- h.update("b" ** 64);
683
+ h.update(&repeat_a_64);
684
+ h.update(&repeat_b_64);
662
685
  h.final(out[0..]);
663
686
  try htest.assertEqual(h3, out[0..]);
664
687
 
665
688
  h = Blake2b160.init(.{});
666
- h.update("a" ** 64);
667
- h.update("b" ** 64);
689
+ h.update(&repeat_a_64);
690
+ h.update(&repeat_b_64);
668
691
  h.final(out[0..]);
669
692
  try htest.assertEqual(h3, out[0..]);
670
693
 
671
694
  const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc";
672
695
 
673
- h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
674
- h.update("a" ** 64);
675
- h.update("b" ** 64);
696
+ h = Blake2b160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
697
+ h.update(&repeat_a_64);
698
+ h.update(&repeat_b_64);
676
699
  h.final(out[0..]);
677
700
  try htest.assertEqual(h4, out[0..]);
678
701
 
679
- h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
680
- h.update("a" ** 64);
681
- h.update("b" ** 64);
702
+ h = Blake2b160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
703
+ h.update(&repeat_a_64);
704
+ h.update(&repeat_b_64);
682
705
  h.final(out[0..]);
683
706
  try htest.assertEqual(h4, out[0..]);
684
707
  }
@@ -686,7 +709,7 @@ test "blake2b160 streaming" {
686
709
  test "comptime blake2b160" {
687
710
  comptime {
688
711
  @setEvalBranchQuota(10000);
689
- var block = [_]u8{0} ** Blake2b160.block_length;
712
+ var block: [Blake2b160.block_length]u8 = @splat(0);
690
713
  var out: [Blake2b160.digest_length]u8 = undefined;
691
714
 
692
715
  const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9";
@@ -712,7 +735,9 @@ test "blake2b384 single" {
712
735
  try htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog");
713
736
 
714
737
  const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
715
- try htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
738
+ const repeat_a_64: [64]u8 = @splat('a');
739
+ const repeat_b_64: [64]u8 = @splat('b');
740
+ try htest.assertEqualHash(Blake2b384, h4, &repeat_a_64 ++ &repeat_b_64);
716
741
  }
717
742
 
718
743
  test "blake2b384 streaming" {
@@ -738,36 +763,39 @@ test "blake2b384 streaming" {
738
763
  h.final(out[0..]);
739
764
  try htest.assertEqual(h2, out[0..]);
740
765
 
766
+ const repeat_a_64: [64]u8 = @splat('a');
767
+ const repeat_b_64: [64]u8 = @splat('b');
768
+
741
769
  const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
742
770
 
743
771
  h = Blake2b384.init(.{});
744
- h.update("a" ** 64 ++ "b" ** 64);
772
+ h.update(&repeat_a_64 ++ &repeat_b_64);
745
773
  h.final(out[0..]);
746
774
  try htest.assertEqual(h3, out[0..]);
747
775
 
748
776
  h = Blake2b384.init(.{});
749
- h.update("a" ** 64);
750
- h.update("b" ** 64);
777
+ h.update(&repeat_a_64);
778
+ h.update(&repeat_b_64);
751
779
  h.final(out[0..]);
752
780
  try htest.assertEqual(h3, out[0..]);
753
781
 
754
782
  h = Blake2b384.init(.{});
755
- h.update("a" ** 64);
756
- h.update("b" ** 64);
783
+ h.update(&repeat_a_64);
784
+ h.update(&repeat_b_64);
757
785
  h.final(out[0..]);
758
786
  try htest.assertEqual(h3, out[0..]);
759
787
 
760
788
  const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c";
761
789
 
762
- h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
763
- h.update("a" ** 64);
764
- h.update("b" ** 64);
790
+ h = Blake2b384.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
791
+ h.update(&repeat_a_64);
792
+ h.update(&repeat_b_64);
765
793
  h.final(out[0..]);
766
794
  try htest.assertEqual(h4, out[0..]);
767
795
 
768
- h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
769
- h.update("a" ** 64);
770
- h.update("b" ** 64);
796
+ h = Blake2b384.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
797
+ h.update(&repeat_a_64);
798
+ h.update(&repeat_b_64);
771
799
  h.final(out[0..]);
772
800
  try htest.assertEqual(h4, out[0..]);
773
801
  }
@@ -775,7 +803,7 @@ test "blake2b384 streaming" {
775
803
  test "comptime blake2b384" {
776
804
  comptime {
777
805
  @setEvalBranchQuota(20000);
778
- var block = [_]u8{0} ** Blake2b384.block_length;
806
+ var block: [Blake2b384.block_length]u8 = @splat(0);
779
807
  var out: [Blake2b384.digest_length]u8 = undefined;
780
808
 
781
809
  const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d";
@@ -801,7 +829,9 @@ test "blake2b512 single" {
801
829
  try htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog");
802
830
 
803
831
  const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
804
- try htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
832
+ const repeat_a_64: [64]u8 = @splat('a');
833
+ const repeat_b_64: [64]u8 = @splat('b');
834
+ try htest.assertEqualHash(Blake2b512, h4, &repeat_a_64 ++ &repeat_b_64);
805
835
  }
806
836
 
807
837
  test "blake2b512 streaming" {
@@ -827,16 +857,19 @@ test "blake2b512 streaming" {
827
857
  h.final(out[0..]);
828
858
  try htest.assertEqual(h2, out[0..]);
829
859
 
860
+ const repeat_a_64: [64]u8 = @splat('a');
861
+ const repeat_b_64: [64]u8 = @splat('b');
862
+
830
863
  const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
831
864
 
832
865
  h = Blake2b512.init(.{});
833
- h.update("a" ** 64 ++ "b" ** 64);
866
+ h.update(&repeat_a_64 ++ &repeat_b_64);
834
867
  h.final(out[0..]);
835
868
  try htest.assertEqual(h3, out[0..]);
836
869
 
837
870
  h = Blake2b512.init(.{});
838
- h.update("a" ** 64);
839
- h.update("b" ** 64);
871
+ h.update(&repeat_a_64);
872
+ h.update(&repeat_b_64);
840
873
  h.final(out[0..]);
841
874
  try htest.assertEqual(h3, out[0..]);
842
875
  }
@@ -847,18 +880,21 @@ test "blake2b512 keyed" {
847
880
  const h1 = "8a978060ccaf582f388f37454363071ac9a67e3a704585fd879fb8a419a447e389c7c6de790faa20a7a7dccf197de736bc5b40b98a930b36df5bee7555750c4d";
848
881
  const key = "secret_key";
849
882
 
850
- Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
883
+ const repeat_a_64: [64]u8 = @splat('a');
884
+ const repeat_b_64: [64]u8 = @splat('b');
885
+
886
+ Blake2b512.hash(&repeat_a_64 ++ &repeat_b_64, &out, .{ .key = key });
851
887
  try htest.assertEqual(h1, out[0..]);
852
888
 
853
889
  var h = Blake2b512.init(.{ .key = key });
854
- h.update("a" ** 64 ++ "b" ** 64);
890
+ h.update(&repeat_a_64 ++ &repeat_b_64);
855
891
  h.final(out[0..]);
856
892
 
857
893
  try htest.assertEqual(h1, out[0..]);
858
894
 
859
895
  h = Blake2b512.init(.{ .key = key });
860
- h.update("a" ** 64);
861
- h.update("b" ** 64);
896
+ h.update(&repeat_a_64);
897
+ h.update(&repeat_b_64);
862
898
  h.final(out[0..]);
863
899
 
864
900
  try htest.assertEqual(h1, out[0..]);
@@ -867,7 +903,7 @@ test "blake2b512 keyed" {
867
903
  test "comptime blake2b512" {
868
904
  comptime {
869
905
  @setEvalBranchQuota(12000);
870
- var block = [_]u8{0} ** Blake2b512.block_length;
906
+ var block: [Blake2b512.block_length]u8 = @splat(0);
871
907
  var out: [Blake2b512.digest_length]u8 = undefined;
872
908
 
873
909
  const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41";
@@ -21,7 +21,7 @@ pub fn CbcMac(comptime BlockCipher: type) type {
21
21
  pub const mac_length = block_length;
22
22
 
23
23
  cipher_ctx: BlockCipherCtx,
24
- buf: Block = [_]u8{0} ** block_length,
24
+ buf: Block = @splat(0),
25
25
  pos: usize = 0,
26
26
 
27
27
  pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void {
@@ -648,7 +648,7 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type {
648
648
  assert(c.len == m.len);
649
649
  assert(m.len <= 64 * (@as(u39, 1 << 32) - 1));
650
650
 
651
- var polyKey = [_]u8{0} ** 32;
651
+ var polyKey: [32]u8 = @splat(0);
652
652
  ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub);
653
653
 
654
654
  ChaChaIETF(rounds_nb).xor(c[0..m.len], m, 1, k, npub);
@@ -656,13 +656,13 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type {
656
656
  var mac = Poly1305.init(polyKey[0..]);
657
657
  mac.update(ad);
658
658
  if (ad.len % 16 != 0) {
659
- const zeros = [_]u8{0} ** 16;
659
+ const zeros: [16]u8 = @splat(0);
660
660
  const padding = 16 - (ad.len % 16);
661
661
  mac.update(zeros[0..padding]);
662
662
  }
663
663
  mac.update(c[0..m.len]);
664
664
  if (m.len % 16 != 0) {
665
- const zeros = [_]u8{0} ** 16;
665
+ const zeros: [16]u8 = @splat(0);
666
666
  const padding = 16 - (m.len % 16);
667
667
  mac.update(zeros[0..padding]);
668
668
  }
@@ -685,20 +685,20 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type {
685
685
  pub fn decrypt(m: []u8, c: []const u8, tag: [tag_length]u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) AuthenticationError!void {
686
686
  assert(c.len == m.len);
687
687
 
688
- var polyKey = [_]u8{0} ** 32;
688
+ var polyKey: [32]u8 = @splat(0);
689
689
  ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub);
690
690
 
691
691
  var mac = Poly1305.init(polyKey[0..]);
692
692
 
693
693
  mac.update(ad);
694
694
  if (ad.len % 16 != 0) {
695
- const zeros = [_]u8{0} ** 16;
695
+ const zeros: [16]u8 = @splat(0);
696
696
  const padding = 16 - (ad.len % 16);
697
697
  mac.update(zeros[0..padding]);
698
698
  }
699
699
  mac.update(c);
700
700
  if (c.len % 16 != 0) {
701
- const zeros = [_]u8{0} ** 16;
701
+ const zeros: [16]u8 = @splat(0);
702
702
  const padding = 16 - (c.len % 16);
703
703
  mac.update(zeros[0..padding]);
704
704
  }
@@ -759,8 +759,8 @@ test "AEAD API" {
759
759
  const ad = "Additional data";
760
760
 
761
761
  inline for (aeads) |aead| {
762
- const key = [_]u8{69} ** aead.key_length;
763
- const nonce = [_]u8{42} ** aead.nonce_length;
762
+ const key: [aead.key_length]u8 = @splat(69);
763
+ const nonce: [aead.nonce_length]u8 = @splat(42);
764
764
  var c: [m.len]u8 = undefined;
765
765
  var tag: [aead.tag_length]u8 = undefined;
766
766
  var out: [m.len]u8 = undefined;
@@ -1138,8 +1138,8 @@ test "open" {
1138
1138
  }
1139
1139
 
1140
1140
  test "xchacha20" {
1141
- const key = [_]u8{69} ** 32;
1142
- const nonce = [_]u8{42} ** 24;
1141
+ const key: [32]u8 = @splat(69);
1142
+ const nonce: [24]u8 = @splat(42);
1143
1143
  const m = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.";
1144
1144
  {
1145
1145
  var c: [m.len]u8 = undefined;
@@ -20,7 +20,7 @@ pub fn Cmac(comptime BlockCipher: type) type {
20
20
  cipher_ctx: BlockCipherCtx,
21
21
  k1: Block,
22
22
  k2: Block,
23
- buf: Block = [_]u8{0} ** block_length,
23
+ buf: Block = @splat(0),
24
24
  pos: usize = 0,
25
25
 
26
26
  pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void {
@@ -31,7 +31,7 @@ pub fn Cmac(comptime BlockCipher: type) type {
31
31
 
32
32
  pub fn init(key: *const [key_length]u8) Self {
33
33
  const cipher_ctx = BlockCipher.initEnc(key.*);
34
- const zeros = [_]u8{0} ** block_length;
34
+ const zeros: [block_length]u8 = @splat(0);
35
35
  var k1: Block = undefined;
36
36
  cipher_ctx.encrypt(&k1, &zeros);
37
37
  k1 = double(k1);
@@ -233,7 +233,7 @@ test Element {
233
233
  .slice = Element.Slice{ .start = 2, .end = short_form.len },
234
234
  }, Element.decode(&short_form, 0));
235
235
 
236
- const long_form = [_]u8{ 0x30, 129, 129 } ++ [_]u8{0} ** 129;
236
+ const long_form = [_]u8{ 0x30, 129, 129 } ++ @as([129]u8, @splat(0));
237
237
  try std.testing.expectEqual(Element{
238
238
  .tag = Tag.universal(.sequence, true),
239
239
  .slice = Element.Slice{ .start = 3, .end = long_form.len },