@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.
- package/compiler/build_runner.zig +1 -1
- package/compiler/reduce/Walk.zig +1 -6
- package/compiler/resinator/cvtres.zig +4 -4
- package/compiler/resinator/ico.zig +4 -4
- package/compiler/resinator/parse.zig +2 -2
- package/compiler/resinator/res.zig +1 -1
- package/compiler/translate-c/ast.zig +11 -21
- package/compiler_rt/atomics.zig +1 -1
- package/compiler_rt/ssp.zig +2 -2
- package/docs/wasm/Walk.zig +1 -3
- package/docs/wasm/html_render.zig +1 -2
- package/package.json +1 -1
- package/std/Io/Reader.zig +0 -5
- package/std/Io/Threaded.zig +4 -4
- package/std/Io/Writer.zig +1 -2
- package/std/Io/net/HostName.zig +11 -6
- package/std/Random/ChaCha.zig +2 -2
- package/std/Random/benchmark.zig +2 -2
- package/std/Thread.zig +2 -2
- package/std/base64.zig +5 -5
- package/std/bit_set.zig +7 -7
- package/std/c.zig +17 -17
- package/std/compress/flate/Decompress.zig +1 -1
- package/std/crypto/25519/curve25519.zig +2 -2
- package/std/crypto/25519/edwards25519.zig +3 -3
- package/std/crypto/25519/ristretto255.zig +2 -2
- package/std/crypto/25519/scalar.zig +6 -6
- package/std/crypto/25519/x25519.zig +1 -1
- package/std/crypto/Certificate.zig +1 -1
- package/std/crypto/Sha1.zig +1 -1
- package/std/crypto/aegis.zig +45 -39
- package/std/crypto/aes_ccm.zig +20 -20
- package/std/crypto/aes_gcm.zig +10 -12
- package/std/crypto/aes_ocb.zig +9 -9
- package/std/crypto/argon2.zig +15 -15
- package/std/crypto/bcrypt.zig +20 -10
- package/std/crypto/benchmark.zig +7 -7
- package/std/crypto/blake2.zig +100 -64
- package/std/crypto/cbc_mac.zig +1 -1
- package/std/crypto/chacha20.zig +10 -10
- package/std/crypto/cmac.zig +2 -2
- package/std/crypto/codecs/asn1.zig +1 -1
- package/std/crypto/ecdsa.zig +9 -9
- package/std/crypto/ff.zig +2 -2
- package/std/crypto/ghash_polyval.zig +4 -4
- package/std/crypto/hkdf.zig +1 -1
- package/std/crypto/isap.zig +3 -3
- package/std/crypto/kangarootwelve.zig +1 -1
- package/std/crypto/keccak_p.zig +7 -7
- package/std/crypto/md5.zig +1 -1
- package/std/crypto/ml_dsa.zig +33 -33
- package/std/crypto/ml_kem.zig +4 -4
- package/std/crypto/modes.zig +1 -1
- package/std/crypto/pbkdf2.zig +1 -1
- package/std/crypto/pcurves/p256/scalar.zig +3 -3
- package/std/crypto/pcurves/p384/scalar.zig +2 -2
- package/std/crypto/pcurves/secp256k1/scalar.zig +3 -3
- package/std/crypto/pcurves/tests/p256.zig +5 -5
- package/std/crypto/pcurves/tests/p384.zig +5 -5
- package/std/crypto/pcurves/tests/secp256k1.zig +3 -3
- package/std/crypto/salsa20.zig +8 -8
- package/std/crypto/sha2.zig +2 -2
- package/std/crypto/sha3.zig +2 -2
- package/std/crypto/siphash.zig +1 -1
- package/std/crypto/timing_safe.zig +5 -4
- package/std/crypto/tls/Client.zig +10 -9
- package/std/crypto.zig +3 -3
- package/std/debug/Dwarf.zig +1 -1
- package/std/debug.zig +6 -4
- package/std/elf.zig +1 -1
- package/std/enums.zig +1 -1
- package/std/fmt/parse_float/decimal.zig +1 -1
- package/std/fmt.zig +5 -1
- package/std/hash/Adler32.zig +3 -3
- package/std/hash/benchmark.zig +2 -2
- package/std/hash/wyhash.zig +1 -1
- package/std/heap/debug_allocator.zig +1 -1
- package/std/http.zig +1 -1
- package/std/json/static.zig +2 -2
- package/std/math/big/int.zig +3 -3
- package/std/math/nextafter.zig +1 -2
- package/std/math/powi.zig +2 -3
- package/std/math/signbit.zig +0 -1
- package/std/math.zig +12 -18
- package/std/mem.zig +9 -8
- package/std/meta.zig +1 -1
- package/std/os/emscripten.zig +2 -2
- package/std/os/linux.zig +4 -4
- package/std/os/uefi/hii.zig +1 -1
- package/std/tar/Writer.zig +39 -33
- package/std/tar.zig +8 -4
- package/std/unicode.zig +13 -8
- package/std/zig/Ast/Render.zig +1 -25
- package/std/zig/Ast.zig +5 -28
- package/std/zig/AstGen.zig +75 -184
- package/std/zig/AstRlAnnotate.zig +1 -11
- package/std/zig/AstSmith.zig +5 -11
- package/std/zig/LibCInstallation.zig +1 -1
- package/std/zig/Parse.zig +4 -69
- package/std/zig/TokenSmith.zig +0 -6
- package/std/zig/WindowsSdk.zig +1 -1
- package/std/zig/Zir.zig +0 -54
- package/std/zig/ZonGen.zig +0 -1
- package/std/zig/llvm/Builder.zig +3 -7
- package/std/zig/tokenizer.zig +4 -43
- package/std/zig.zig +0 -2
package/std/crypto/ecdsa.zig
CHANGED
|
@@ -212,7 +212,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
|
|
|
212
212
|
fn finalizePrehashed(self: *Signer, msg_hash: [Hash.digest_length]u8) (IdentityElementError || NonCanonicalError)!Signature {
|
|
213
213
|
const scalar_encoded_length = Curve.scalar.encoded_length;
|
|
214
214
|
const h_len = @max(Hash.digest_length, scalar_encoded_length);
|
|
215
|
-
var h: [h_len]u8 = [
|
|
215
|
+
var h: [h_len]u8 = @as([h_len - Hash.digest_length]u8, @splat(0)) ++ msg_hash;
|
|
216
216
|
|
|
217
217
|
std.debug.assert(h.len >= scalar_encoded_length);
|
|
218
218
|
const z = reduceToScalar(scalar_encoded_length, h[0..scalar_encoded_length].*);
|
|
@@ -275,7 +275,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
|
|
|
275
275
|
fn verifyPrehashed(self: *Verifier, msg_hash: [Hash.digest_length]u8) VerifyError!void {
|
|
276
276
|
const ht = Curve.scalar.encoded_length;
|
|
277
277
|
const h_len = @max(Hash.digest_length, ht);
|
|
278
|
-
var h: [h_len]u8 = [
|
|
278
|
+
var h: [h_len]u8 = @as([h_len - Hash.digest_length]u8, @splat(0)) ++ msg_hash;
|
|
279
279
|
|
|
280
280
|
const z = reduceToScalar(ht, h[0..ht].*);
|
|
281
281
|
if (z.isZero()) {
|
|
@@ -316,8 +316,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
|
|
|
316
316
|
///
|
|
317
317
|
/// Except in tests, applications should generally call `generate()` instead of this function.
|
|
318
318
|
pub fn generateDeterministic(seed: [seed_length]u8) IdentityElementError!KeyPair {
|
|
319
|
-
const h
|
|
320
|
-
const k0
|
|
319
|
+
const h: [Hash.digest_length]u8 = @splat(0x00);
|
|
320
|
+
const k0: [SecretKey.encoded_length]u8 = @splat(0x01);
|
|
321
321
|
const secret_key = deterministicScalar(h, k0, seed).toBytes(.big);
|
|
322
322
|
return fromSecretKey(SecretKey{ .bytes = secret_key });
|
|
323
323
|
}
|
|
@@ -367,11 +367,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
|
|
|
367
367
|
// Reduce the coordinate of a field element to the scalar field.
|
|
368
368
|
fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar {
|
|
369
369
|
if (unreduced_len >= 48) {
|
|
370
|
-
var xs
|
|
370
|
+
var xs: [64]u8 = @splat(0);
|
|
371
371
|
@memcpy(xs[xs.len - s.len ..], s[0..]);
|
|
372
372
|
return Curve.scalar.Scalar.fromBytes64(xs, .big);
|
|
373
373
|
}
|
|
374
|
-
var xs
|
|
374
|
+
var xs: [48]u8 = @splat(0);
|
|
375
375
|
@memcpy(xs[xs.len - s.len ..], s[0..]);
|
|
376
376
|
return Curve.scalar.Scalar.fromBytes48(xs, .big);
|
|
377
377
|
}
|
|
@@ -379,9 +379,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
|
|
|
379
379
|
// Create a deterministic scalar according to a secret key and optional noise.
|
|
380
380
|
// This uses the overly conservative scheme from the "Deterministic ECDSA and EdDSA Signatures with Additional Randomness" draft.
|
|
381
381
|
fn deterministicScalar(h: [Hash.digest_length]u8, secret_key: Curve.scalar.CompressedScalar, noise: ?[noise_length]u8) Curve.scalar.Scalar {
|
|
382
|
-
var k
|
|
383
|
-
var m
|
|
384
|
-
var t
|
|
382
|
+
var k: [h.len]u8 = @splat(0);
|
|
383
|
+
var m: [h.len + 1 + noise_length + secret_key.len + h.len]u8 = @splat(0);
|
|
384
|
+
var t: [Curve.scalar.encoded_length]u8 = @splat(0);
|
|
385
385
|
const m_v = m[0..h.len];
|
|
386
386
|
const m_i = &m[m_v.len];
|
|
387
387
|
const m_z = m[m_v.len + 1 ..][0..noise_length];
|
package/std/crypto/ff.zig
CHANGED
|
@@ -96,7 +96,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
|
|
|
96
96
|
|
|
97
97
|
/// The zero integer.
|
|
98
98
|
pub const zero: Self = .{
|
|
99
|
-
.limbs_buffer =
|
|
99
|
+
.limbs_buffer = @splat(0),
|
|
100
100
|
.limbs_len = max_limbs_count,
|
|
101
101
|
};
|
|
102
102
|
|
|
@@ -738,7 +738,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
|
|
|
738
738
|
}
|
|
739
739
|
} else {
|
|
740
740
|
// Use a precomputation table for large exponents
|
|
741
|
-
var pc = [1]Fe{x} ++ [
|
|
741
|
+
var pc: [15]Fe = [1]Fe{x} ++ @as([14]Fe, @splat(self.zero));
|
|
742
742
|
if (!x.montgomery) {
|
|
743
743
|
self.toMontgomery(&pc[0]) catch unreachable;
|
|
744
744
|
}
|
|
@@ -417,8 +417,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
|
|
|
417
417
|
const htest = @import("test.zig");
|
|
418
418
|
|
|
419
419
|
test "ghash" {
|
|
420
|
-
const key
|
|
421
|
-
const m
|
|
420
|
+
const key: [16]u8 = @splat(0x42);
|
|
421
|
+
const m: [256]u8 = @splat(0x69);
|
|
422
422
|
|
|
423
423
|
var st = Ghash.init(&key);
|
|
424
424
|
st.update(&m);
|
|
@@ -467,8 +467,8 @@ test "ghash2" {
|
|
|
467
467
|
}
|
|
468
468
|
|
|
469
469
|
test "polyval" {
|
|
470
|
-
const key
|
|
471
|
-
const m
|
|
470
|
+
const key: [16]u8 = @splat(0x42);
|
|
471
|
+
const m: [256]u8 = @splat(0x69);
|
|
472
472
|
|
|
473
473
|
var st = Polyval.init(&key);
|
|
474
474
|
st.update(&m);
|
package/std/crypto/hkdf.zig
CHANGED
|
@@ -72,7 +72,7 @@ pub fn Hkdf(comptime Hmac: type) type {
|
|
|
72
72
|
const htest = @import("test.zig");
|
|
73
73
|
|
|
74
74
|
test "Hkdf" {
|
|
75
|
-
const ikm
|
|
75
|
+
const ikm: [22]u8 = @splat(0x0b);
|
|
76
76
|
const salt = [_]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c };
|
|
77
77
|
const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
|
|
78
78
|
const kdf = HkdfSha256;
|
package/std/crypto/isap.zig
CHANGED
|
@@ -42,7 +42,7 @@ pub const IsapA128A = struct {
|
|
|
42
42
|
break;
|
|
43
43
|
}
|
|
44
44
|
} else {
|
|
45
|
-
var padded
|
|
45
|
+
var padded: [8]u8 = @splat(0);
|
|
46
46
|
@memcpy(padded[0..left], m[i..]);
|
|
47
47
|
padded[left] = 0x80;
|
|
48
48
|
isap.st.addBytes(&padded);
|
|
@@ -169,8 +169,8 @@ pub const IsapA128A = struct {
|
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
test "ISAP" {
|
|
172
|
-
const k
|
|
173
|
-
const n
|
|
172
|
+
const k: [16]u8 = @splat(1);
|
|
173
|
+
const n: [16]u8 = @splat(2);
|
|
174
174
|
var tag: [16]u8 = undefined;
|
|
175
175
|
const ad = "ad";
|
|
176
176
|
var msg = "test";
|
|
@@ -881,7 +881,7 @@ fn ktMultiThreaded(
|
|
|
881
881
|
// Buffer for out-of-order results (select_buf slots get reused)
|
|
882
882
|
const pending_cv_buf = try allocator.alloc([leaves_per_batch * cv_size]u8, max_concurrent);
|
|
883
883
|
defer allocator.free(pending_cv_buf);
|
|
884
|
-
var pending_cv_lens: [256]usize =
|
|
884
|
+
var pending_cv_lens: [256]usize = @splat(0);
|
|
885
885
|
|
|
886
886
|
var select_outstanding: usize = 0;
|
|
887
887
|
var select: Select = .init(io, select_buf);
|
package/std/crypto/keccak_p.zig
CHANGED
|
@@ -40,7 +40,7 @@ pub fn KeccakF(comptime f: u11) type {
|
|
|
40
40
|
break :rc rc;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
st: Block =
|
|
43
|
+
st: Block = @splat(0),
|
|
44
44
|
|
|
45
45
|
/// Initialize the state from a slice of bytes.
|
|
46
46
|
pub fn init(bytes: [block_bytes]u8) Self {
|
|
@@ -70,7 +70,7 @@ pub fn KeccakF(comptime f: u11) type {
|
|
|
70
70
|
self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little);
|
|
71
71
|
}
|
|
72
72
|
if (i < bytes.len) {
|
|
73
|
-
var padded
|
|
73
|
+
var padded: [@sizeOf(T)]u8 = @splat(0);
|
|
74
74
|
@memcpy(padded[0 .. bytes.len - i], bytes[i..]);
|
|
75
75
|
self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .little);
|
|
76
76
|
}
|
|
@@ -89,7 +89,7 @@ pub fn KeccakF(comptime f: u11) type {
|
|
|
89
89
|
self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little);
|
|
90
90
|
}
|
|
91
91
|
if (i < bytes.len) {
|
|
92
|
-
var padded
|
|
92
|
+
var padded: [@sizeOf(T)]u8 = @splat(0);
|
|
93
93
|
@memcpy(padded[0 .. bytes.len - i], bytes[i..]);
|
|
94
94
|
self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .little);
|
|
95
95
|
}
|
|
@@ -102,7 +102,7 @@ pub fn KeccakF(comptime f: u11) type {
|
|
|
102
102
|
mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .little);
|
|
103
103
|
}
|
|
104
104
|
if (i < out.len) {
|
|
105
|
-
var padded
|
|
105
|
+
var padded: [@sizeOf(T)]u8 = @splat(0);
|
|
106
106
|
mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .little);
|
|
107
107
|
@memcpy(out[i..], padded[0 .. out.len - i]);
|
|
108
108
|
}
|
|
@@ -118,7 +118,7 @@ pub fn KeccakF(comptime f: u11) type {
|
|
|
118
118
|
mem.writeInt(T, out[i..][0..@sizeOf(T)], x, native_endian);
|
|
119
119
|
}
|
|
120
120
|
if (i < in.len) {
|
|
121
|
-
var padded
|
|
121
|
+
var padded: [@sizeOf(T)]u8 = @splat(0);
|
|
122
122
|
@memcpy(padded[0 .. in.len - i], in[i..]);
|
|
123
123
|
const x = mem.readInt(T, &padded, native_endian) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
|
|
124
124
|
mem.writeInt(T, &padded, x, native_endian);
|
|
@@ -140,7 +140,7 @@ pub fn KeccakF(comptime f: u11) type {
|
|
|
140
140
|
const st = &self.st;
|
|
141
141
|
|
|
142
142
|
// theta
|
|
143
|
-
var t
|
|
143
|
+
var t: [5]T = @splat(0);
|
|
144
144
|
inline for (0..5) |i| {
|
|
145
145
|
inline for (0..5) |j| {
|
|
146
146
|
t[i] ^= st[j * 5 + i];
|
|
@@ -382,7 +382,7 @@ test "Keccak-f800" {
|
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
test "squeeze" {
|
|
385
|
-
var st
|
|
385
|
+
var st: State(800, 256, 22) = .init(@splat(0x80), 0x01);
|
|
386
386
|
|
|
387
387
|
var out0: [15]u8 = undefined;
|
|
388
388
|
var out1: [out0.len]u8 = undefined;
|
package/std/crypto/md5.zig
CHANGED
package/std/crypto/ml_dsa.zig
CHANGED
|
@@ -156,7 +156,7 @@ const Params = struct {
|
|
|
156
156
|
const Poly = struct {
|
|
157
157
|
cs: [N]u32,
|
|
158
158
|
|
|
159
|
-
const zero: Poly = .{ .cs =
|
|
159
|
+
const zero: Poly = .{ .cs = @splat(0) };
|
|
160
160
|
|
|
161
161
|
// Add two polynomials (no normalization)
|
|
162
162
|
fn add(a: Poly, b: Poly) Poly {
|
|
@@ -302,7 +302,7 @@ fn PolyVec(comptime len: u8) type {
|
|
|
302
302
|
ps: [len]Poly,
|
|
303
303
|
|
|
304
304
|
const Self = @This();
|
|
305
|
-
const zero: Self = .{ .ps = .
|
|
305
|
+
const zero: Self = .{ .ps = @splat(.zero) };
|
|
306
306
|
|
|
307
307
|
/// Apply a unary operation to each polynomial in the vector
|
|
308
308
|
fn map(v: Self, comptime op: fn (Poly) Poly) Self {
|
|
@@ -581,7 +581,7 @@ fn PolyVec(comptime len: u8) type {
|
|
|
581
581
|
|
|
582
582
|
/// Unpack hints from bytes
|
|
583
583
|
fn unpackHint(comptime omega: u16, buf: []const u8) ?Self {
|
|
584
|
-
var result: Self = .{ .ps = .
|
|
584
|
+
var result: Self = .{ .ps = @splat(.zero) };
|
|
585
585
|
var prev_sop: u8 = 0; // previous switch-over-point
|
|
586
586
|
|
|
587
587
|
for (0..len) |i| {
|
|
@@ -1839,7 +1839,7 @@ fn MLDSAImpl(comptime p: Params) type {
|
|
|
1839
1839
|
return Signer{
|
|
1840
1840
|
.h = h,
|
|
1841
1841
|
.secret_key = secret_key,
|
|
1842
|
-
.rnd = noise orelse
|
|
1842
|
+
.rnd = noise orelse @splat(0),
|
|
1843
1843
|
};
|
|
1844
1844
|
}
|
|
1845
1845
|
|
|
@@ -2324,7 +2324,7 @@ test "decompose correctness for ML-DSA-87" {
|
|
|
2324
2324
|
|
|
2325
2325
|
test "polyDeriveUniform deterministic" {
|
|
2326
2326
|
// Test that polyDeriveUniform produces deterministic results
|
|
2327
|
-
const seed: [32]u8 = .{0x01} ++
|
|
2327
|
+
const seed: [32]u8 = .{0x01} ++ @as([31]u8, @splat(0x00));
|
|
2328
2328
|
const nonce: u16 = 0;
|
|
2329
2329
|
|
|
2330
2330
|
const p1 = polyDeriveUniform(&seed, nonce);
|
|
@@ -2343,7 +2343,7 @@ test "polyDeriveUniform deterministic" {
|
|
|
2343
2343
|
|
|
2344
2344
|
test "polyDeriveUniform different nonces" {
|
|
2345
2345
|
// Test that different nonces produce different polynomials
|
|
2346
|
-
const seed: [32]u8 = .{0x01} ++
|
|
2346
|
+
const seed: [32]u8 = .{0x01} ++ @as([31]u8, @splat(0x00));
|
|
2347
2347
|
|
|
2348
2348
|
const p1 = polyDeriveUniform(&seed, 0);
|
|
2349
2349
|
const p2 = polyDeriveUniform(&seed, 1);
|
|
@@ -2361,7 +2361,7 @@ test "polyDeriveUniform different nonces" {
|
|
|
2361
2361
|
|
|
2362
2362
|
test "expandS with eta=2" {
|
|
2363
2363
|
// Test eta=2 sampling
|
|
2364
|
-
const seed: [64]u8 = .{0x02} ++
|
|
2364
|
+
const seed: [64]u8 = .{0x02} ++ @as([63]u8, @splat(0x00));
|
|
2365
2365
|
const nonce: u16 = 0;
|
|
2366
2366
|
|
|
2367
2367
|
const p = expandS(2, &seed, nonce);
|
|
@@ -2378,7 +2378,7 @@ test "expandS with eta=2" {
|
|
|
2378
2378
|
|
|
2379
2379
|
test "expandS with eta=4" {
|
|
2380
2380
|
// Test eta=4 sampling
|
|
2381
|
-
const seed: [64]u8 = .{0x03} ++
|
|
2381
|
+
const seed: [64]u8 = .{0x03} ++ @as([63]u8, @splat(0x00));
|
|
2382
2382
|
const nonce: u16 = 0;
|
|
2383
2383
|
|
|
2384
2384
|
const p = expandS(4, &seed, nonce);
|
|
@@ -2395,7 +2395,7 @@ test "expandS with eta=4" {
|
|
|
2395
2395
|
test "sampleInBall has correct weight" {
|
|
2396
2396
|
// Test that ball polynomial has exactly tau non-zero coefficients
|
|
2397
2397
|
const tau = 39; // From ML-DSA-44
|
|
2398
|
-
const seed: [32]u8 = .{
|
|
2398
|
+
const seed: [32]u8 = .{0x03} ++ @as([31]u8, @splat(0x00));
|
|
2399
2399
|
|
|
2400
2400
|
const p = sampleInBall(tau, &seed);
|
|
2401
2401
|
|
|
@@ -2415,7 +2415,7 @@ test "sampleInBall has correct weight" {
|
|
|
2415
2415
|
test "sampleInBall deterministic" {
|
|
2416
2416
|
// Test that ball sampling is deterministic
|
|
2417
2417
|
const tau = 49; // From ML-DSA-65
|
|
2418
|
-
const seed: [32]u8 = .{0x05} ++
|
|
2418
|
+
const seed: [32]u8 = .{0x05} ++ @as([31]u8, @splat(0x00));
|
|
2419
2419
|
|
|
2420
2420
|
const p1 = sampleInBall(tau, &seed);
|
|
2421
2421
|
const p2 = sampleInBall(tau, &seed);
|
|
@@ -2851,13 +2851,13 @@ test "Key generation basic - all variants" {
|
|
|
2851
2851
|
.{ .variant = MLDSA65, .seed_byte = 0x65 },
|
|
2852
2852
|
.{ .variant = MLDSA87, .seed_byte = 0x87 },
|
|
2853
2853
|
}) |config| {
|
|
2854
|
-
const seed
|
|
2854
|
+
const seed: [32]u8 = @splat(config.seed_byte);
|
|
2855
2855
|
try testKeyGenerationBasic(config.variant, seed);
|
|
2856
2856
|
}
|
|
2857
2857
|
}
|
|
2858
2858
|
|
|
2859
2859
|
test "Key generation determinism" {
|
|
2860
|
-
const seed = [_]u8{ 0x12, 0x34, 0x56, 0x78 } ++ [
|
|
2860
|
+
const seed = [_]u8{ 0x12, 0x34, 0x56, 0x78 } ++ @as([28]u8, @splat(0xAB));
|
|
2861
2861
|
|
|
2862
2862
|
// Generate two key pairs from the same seed
|
|
2863
2863
|
const result1 = MLDSA44.newKeyFromSeed(&seed);
|
|
@@ -2874,7 +2874,7 @@ test "Key generation determinism" {
|
|
|
2874
2874
|
}
|
|
2875
2875
|
|
|
2876
2876
|
test "Private key can compute public key" {
|
|
2877
|
-
const seed
|
|
2877
|
+
const seed: [32]u8 = @splat(0xFF);
|
|
2878
2878
|
const result = MLDSA44.newKeyFromSeed(&seed);
|
|
2879
2879
|
const pk = result.pk;
|
|
2880
2880
|
const sk = result.sk;
|
|
@@ -2907,13 +2907,13 @@ test "Sign and verify - all variants" {
|
|
|
2907
2907
|
.{ .variant = MLDSA65, .seed_byte = 0x65, .message = "Hello, ML-DSA-65!" },
|
|
2908
2908
|
.{ .variant = MLDSA87, .seed_byte = 0x87, .message = "Hello, ML-DSA-87!" },
|
|
2909
2909
|
}) |config| {
|
|
2910
|
-
const seed
|
|
2910
|
+
const seed: [32]u8 = @splat(config.seed_byte);
|
|
2911
2911
|
try testSignAndVerify(config.variant, seed, config.message);
|
|
2912
2912
|
}
|
|
2913
2913
|
}
|
|
2914
2914
|
|
|
2915
2915
|
test "Invalid signature rejection" {
|
|
2916
|
-
const seed
|
|
2916
|
+
const seed: [32]u8 = @splat(0x99);
|
|
2917
2917
|
const result = MLDSA44.newKeyFromSeed(&seed);
|
|
2918
2918
|
const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
|
|
2919
2919
|
|
|
@@ -2934,7 +2934,7 @@ test "Invalid signature rejection" {
|
|
|
2934
2934
|
}
|
|
2935
2935
|
|
|
2936
2936
|
test "Context string support" {
|
|
2937
|
-
const seed
|
|
2937
|
+
const seed: [32]u8 = @splat(0xAA);
|
|
2938
2938
|
const result = MLDSA44.newKeyFromSeed(&seed);
|
|
2939
2939
|
const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
|
|
2940
2940
|
|
|
@@ -2964,17 +2964,17 @@ test "Context string support" {
|
|
|
2964
2964
|
try testing.expectError(error.SignatureVerificationFailed, sig2.verifyWithContext(message, kp.public_key, context1));
|
|
2965
2965
|
|
|
2966
2966
|
// Test maximum context length (255 bytes)
|
|
2967
|
-
const max_context
|
|
2967
|
+
const max_context: [255]u8 = @splat(0xBB);
|
|
2968
2968
|
const sig3 = try kp.signWithContext(message, null, &max_context);
|
|
2969
2969
|
try sig3.verifyWithContext(message, kp.public_key, &max_context);
|
|
2970
2970
|
|
|
2971
2971
|
// Test context too long (256 bytes should fail)
|
|
2972
|
-
const too_long_context
|
|
2972
|
+
const too_long_context: [256]u8 = @splat(0xCC);
|
|
2973
2973
|
try testing.expectError(error.ContextTooLong, kp.signWithContext(message, null, &too_long_context));
|
|
2974
2974
|
}
|
|
2975
2975
|
|
|
2976
2976
|
test "Context string with streaming API" {
|
|
2977
|
-
const seed
|
|
2977
|
+
const seed: [32]u8 = @splat(0xDD);
|
|
2978
2978
|
const result = MLDSA44.newKeyFromSeed(&seed);
|
|
2979
2979
|
const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
|
|
2980
2980
|
|
|
@@ -3002,12 +3002,12 @@ test "Context string with streaming API" {
|
|
|
3002
3002
|
}
|
|
3003
3003
|
|
|
3004
3004
|
test "Signature determinism (same rnd)" {
|
|
3005
|
-
const seed
|
|
3005
|
+
const seed: [32]u8 = @splat(0x11);
|
|
3006
3006
|
const result = MLDSA44.newKeyFromSeed(&seed);
|
|
3007
3007
|
const sk = result.sk;
|
|
3008
3008
|
|
|
3009
3009
|
const message = "Deterministic test";
|
|
3010
|
-
const rnd
|
|
3010
|
+
const rnd: [32]u8 = @splat(0x22);
|
|
3011
3011
|
|
|
3012
3012
|
// Sign twice with same randomness using streaming API
|
|
3013
3013
|
var st1 = try sk.signer(rnd);
|
|
@@ -3023,7 +3023,7 @@ test "Signature determinism (same rnd)" {
|
|
|
3023
3023
|
}
|
|
3024
3024
|
|
|
3025
3025
|
test "Signature toBytes/fromBytes roundtrip" {
|
|
3026
|
-
const seed
|
|
3026
|
+
const seed: [32]u8 = @splat(0x33);
|
|
3027
3027
|
const result = MLDSA44.newKeyFromSeed(&seed);
|
|
3028
3028
|
const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
|
|
3029
3029
|
|
|
@@ -3043,7 +3043,7 @@ test "Signature toBytes/fromBytes roundtrip" {
|
|
|
3043
3043
|
}
|
|
3044
3044
|
|
|
3045
3045
|
test "Empty message signing" {
|
|
3046
|
-
const seed
|
|
3046
|
+
const seed: [32]u8 = @splat(0x44);
|
|
3047
3047
|
const result = MLDSA44.newKeyFromSeed(&seed);
|
|
3048
3048
|
const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
|
|
3049
3049
|
|
|
@@ -3057,12 +3057,12 @@ test "Empty message signing" {
|
|
|
3057
3057
|
}
|
|
3058
3058
|
|
|
3059
3059
|
test "Long message signing" {
|
|
3060
|
-
const seed
|
|
3060
|
+
const seed: [32]u8 = @splat(0x55);
|
|
3061
3061
|
const result = MLDSA44.newKeyFromSeed(&seed);
|
|
3062
3062
|
const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
|
|
3063
3063
|
|
|
3064
3064
|
// Create a long message (1KB)
|
|
3065
|
-
const long_message
|
|
3065
|
+
const long_message: [1024]u8 = @splat(0xAB);
|
|
3066
3066
|
|
|
3067
3067
|
// Sign long message
|
|
3068
3068
|
const sig = try kp.sign(&long_message, null);
|
|
@@ -3209,7 +3209,7 @@ test "KeyPair API - generate and sign" {
|
|
|
3209
3209
|
|
|
3210
3210
|
test "KeyPair API - generateDeterministic" {
|
|
3211
3211
|
// Test deterministic key generation
|
|
3212
|
-
const seed
|
|
3212
|
+
const seed: [32]u8 = @splat(42);
|
|
3213
3213
|
const kp1 = try MLDSA44.KeyPair.generateDeterministic(seed);
|
|
3214
3214
|
const kp2 = try MLDSA44.KeyPair.generateDeterministic(seed);
|
|
3215
3215
|
|
|
@@ -3240,7 +3240,7 @@ test "Signature verification with noise" {
|
|
|
3240
3240
|
const msg = "Message to be signed with randomness";
|
|
3241
3241
|
|
|
3242
3242
|
// Create some noise
|
|
3243
|
-
const noise = [_]u8{ 1, 2, 3, 4, 5 } ++ [
|
|
3243
|
+
const noise = [_]u8{ 1, 2, 3, 4, 5 } ++ @as([27]u8, @splat(0));
|
|
3244
3244
|
|
|
3245
3245
|
// Sign with noise
|
|
3246
3246
|
const sig = try kp.sign(msg, noise);
|
|
@@ -3262,7 +3262,7 @@ test "Signature verification failure" {
|
|
|
3262
3262
|
}
|
|
3263
3263
|
|
|
3264
3264
|
test "Streaming API - sign and verify" {
|
|
3265
|
-
const seed
|
|
3265
|
+
const seed: [32]u8 = @splat(0x55);
|
|
3266
3266
|
const kp = try MLDSA44.KeyPair.generateDeterministic(seed);
|
|
3267
3267
|
|
|
3268
3268
|
const msg = "Test message for streaming API";
|
|
@@ -3279,7 +3279,7 @@ test "Streaming API - sign and verify" {
|
|
|
3279
3279
|
}
|
|
3280
3280
|
|
|
3281
3281
|
test "Streaming API - chunked message" {
|
|
3282
|
-
const seed
|
|
3282
|
+
const seed: [32]u8 = @splat(0x66);
|
|
3283
3283
|
const kp = try MLDSA44.KeyPair.generateDeterministic(seed);
|
|
3284
3284
|
|
|
3285
3285
|
// Create a message in chunks
|
|
@@ -3313,7 +3313,7 @@ test "Streaming API - chunked message" {
|
|
|
3313
3313
|
}
|
|
3314
3314
|
|
|
3315
3315
|
test "Streaming API - large message" {
|
|
3316
|
-
const seed
|
|
3316
|
+
const seed: [32]u8 = @splat(0x77);
|
|
3317
3317
|
const kp = try MLDSA44.KeyPair.generateDeterministic(seed);
|
|
3318
3318
|
|
|
3319
3319
|
// Create a large message (1MB)
|
|
@@ -3344,7 +3344,7 @@ test "Streaming API - all parameter sets" {
|
|
|
3344
3344
|
|
|
3345
3345
|
// ML-DSA-44
|
|
3346
3346
|
{
|
|
3347
|
-
const seed
|
|
3347
|
+
const seed: [32]u8 = @splat(0x44);
|
|
3348
3348
|
const kp = try MLDSA44.KeyPair.generateDeterministic(seed);
|
|
3349
3349
|
var signer = try kp.signer(null);
|
|
3350
3350
|
signer.update(test_msg);
|
|
@@ -3356,7 +3356,7 @@ test "Streaming API - all parameter sets" {
|
|
|
3356
3356
|
|
|
3357
3357
|
// ML-DSA-65
|
|
3358
3358
|
{
|
|
3359
|
-
const seed
|
|
3359
|
+
const seed: [32]u8 = @splat(0x65);
|
|
3360
3360
|
const kp = try MLDSA65.KeyPair.generateDeterministic(seed);
|
|
3361
3361
|
var signer = try kp.signer(null);
|
|
3362
3362
|
signer.update(test_msg);
|
|
@@ -3368,7 +3368,7 @@ test "Streaming API - all parameter sets" {
|
|
|
3368
3368
|
|
|
3369
3369
|
// ML-DSA-87
|
|
3370
3370
|
{
|
|
3371
|
-
const seed
|
|
3371
|
+
const seed: [32]u8 = @splat(0x87);
|
|
3372
3372
|
const kp = try MLDSA87.KeyPair.generateDeterministic(seed);
|
|
3373
3373
|
var signer = try kp.signer(null);
|
|
3374
3374
|
signer.update(test_msg);
|
package/std/crypto/ml_kem.zig
CHANGED
|
@@ -615,7 +615,7 @@ const inv_ntt_reductions = [_]i16{
|
|
|
615
615
|
test "invNTTReductions bounds" {
|
|
616
616
|
// Checks whether the reductions proposed by invNTTReductions
|
|
617
617
|
// don't overflow during invNTT().
|
|
618
|
-
var xs
|
|
618
|
+
var xs: [256]i32 = @splat(1); // start at |x| ≤ q
|
|
619
619
|
|
|
620
620
|
var r: usize = 0;
|
|
621
621
|
var layer: math.Log2Int(usize) = 1;
|
|
@@ -797,7 +797,7 @@ const Poly = struct {
|
|
|
797
797
|
cs: [N]i16,
|
|
798
798
|
|
|
799
799
|
const encoded_length = N / 2 * 3;
|
|
800
|
-
const zero: Poly = .{ .cs =
|
|
800
|
+
const zero: Poly = .{ .cs = @splat(0) };
|
|
801
801
|
|
|
802
802
|
// Add two polynomials (coefficients not normalized)
|
|
803
803
|
fn add(a: Poly, b: Poly) Poly {
|
|
@@ -1011,7 +1011,7 @@ const Poly = struct {
|
|
|
1011
1011
|
|
|
1012
1012
|
const out_length: usize = comptime @divTrunc(N * d, 8);
|
|
1013
1013
|
comptime assert(out_length * 8 == d * N);
|
|
1014
|
-
var out
|
|
1014
|
+
var out: [out_length]u8 = @splat(0);
|
|
1015
1015
|
|
|
1016
1016
|
while (in_off < N) {
|
|
1017
1017
|
// First we compress into in.
|
|
@@ -1754,7 +1754,7 @@ const NistDRBG = struct {
|
|
|
1754
1754
|
}
|
|
1755
1755
|
|
|
1756
1756
|
fn init(seed: [48]u8) NistDRBG {
|
|
1757
|
-
var ret: NistDRBG = .{ .key =
|
|
1757
|
+
var ret: NistDRBG = .{ .key = @splat(0), .v = @splat(0) };
|
|
1758
1758
|
ret.update(seed);
|
|
1759
1759
|
return ret;
|
|
1760
1760
|
}
|
package/std/crypto/modes.zig
CHANGED
|
@@ -183,7 +183,7 @@ test "ctr mode" {
|
|
|
183
183
|
// Test 9: Large input (> 2*block_length, 100 bytes)
|
|
184
184
|
{
|
|
185
185
|
// Create a 100-byte input by extending with zeros
|
|
186
|
-
var in: [100]u8 =
|
|
186
|
+
var in: [100]u8 = @splat(0);
|
|
187
187
|
@memcpy(in[0..64], &[_]u8{
|
|
188
188
|
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
|
|
189
189
|
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
|
package/std/crypto/pbkdf2.zig
CHANGED
|
@@ -196,19 +196,19 @@ const ScalarDouble = struct {
|
|
|
196
196
|
}
|
|
197
197
|
var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
|
|
198
198
|
{
|
|
199
|
-
var b
|
|
199
|
+
var b: [encoded_length]u8 = @splat(0);
|
|
200
200
|
const len = @min(s.len, 24);
|
|
201
201
|
b[0..len].* = s[0..len].*;
|
|
202
202
|
t.x1 = Fe.fromBytes(b, .little) catch unreachable;
|
|
203
203
|
}
|
|
204
204
|
if (s_.len >= 24) {
|
|
205
|
-
var b
|
|
205
|
+
var b: [encoded_length]u8 = @splat(0);
|
|
206
206
|
const len = @min(s.len - 24, 24);
|
|
207
207
|
b[0..len].* = s[24..][0..len].*;
|
|
208
208
|
t.x2 = Fe.fromBytes(b, .little) catch unreachable;
|
|
209
209
|
}
|
|
210
210
|
if (s_.len >= 48) {
|
|
211
|
-
var b
|
|
211
|
+
var b: [encoded_length]u8 = @splat(0);
|
|
212
212
|
const len = s.len - 48;
|
|
213
213
|
b[0..len].* = s[48..][0..len].*;
|
|
214
214
|
t.x3 = Fe.fromBytes(b, .little) catch unreachable;
|
|
@@ -184,13 +184,13 @@ const ScalarDouble = struct {
|
|
|
184
184
|
}
|
|
185
185
|
var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };
|
|
186
186
|
{
|
|
187
|
-
var b
|
|
187
|
+
var b: [encoded_length]u8 = @splat(0);
|
|
188
188
|
const len = @min(s.len, 32);
|
|
189
189
|
b[0..len].* = s[0..len].*;
|
|
190
190
|
t.x1 = Fe.fromBytes(b, .little) catch unreachable;
|
|
191
191
|
}
|
|
192
192
|
if (s_.len >= 32) {
|
|
193
|
-
var b
|
|
193
|
+
var b: [encoded_length]u8 = @splat(0);
|
|
194
194
|
const len = @min(s.len - 32, 32);
|
|
195
195
|
b[0..len].* = s[32..][0..len].*;
|
|
196
196
|
t.x2 = Fe.fromBytes(b, .little) catch unreachable;
|
|
@@ -196,19 +196,19 @@ const ScalarDouble = struct {
|
|
|
196
196
|
}
|
|
197
197
|
var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
|
|
198
198
|
{
|
|
199
|
-
var b
|
|
199
|
+
var b: [encoded_length]u8 = @splat(0);
|
|
200
200
|
const len = @min(s.len, 24);
|
|
201
201
|
b[0..len].* = s[0..len].*;
|
|
202
202
|
t.x1 = Fe.fromBytes(b, .little) catch unreachable;
|
|
203
203
|
}
|
|
204
204
|
if (s_.len >= 24) {
|
|
205
|
-
var b
|
|
205
|
+
var b: [encoded_length]u8 = @splat(0);
|
|
206
206
|
const len = @min(s.len - 24, 24);
|
|
207
207
|
b[0..len].* = s[24..][0..len].*;
|
|
208
208
|
t.x2 = Fe.fromBytes(b, .little) catch unreachable;
|
|
209
209
|
}
|
|
210
210
|
if (s_.len >= 48) {
|
|
211
|
-
var b
|
|
211
|
+
var b: [encoded_length]u8 = @splat(0);
|
|
212
212
|
const len = s.len - 48;
|
|
213
213
|
b[0..len].* = s[48..][0..len].*;
|
|
214
214
|
t.x3 = Fe.fromBytes(b, .little) catch unreachable;
|
|
@@ -97,7 +97,7 @@ test "p256 public key is the neutral element (public verification)" {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
test "p256 field element non-canonical encoding" {
|
|
100
|
-
const s
|
|
100
|
+
const s: [32]u8 = @splat(0xff);
|
|
101
101
|
try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .little));
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -110,8 +110,8 @@ test "p256 neutral element decoding" {
|
|
|
110
110
|
test "p256 double base multiplication" {
|
|
111
111
|
const p1 = P256.basePoint;
|
|
112
112
|
const p2 = P256.basePoint.dbl();
|
|
113
|
-
const s1
|
|
114
|
-
const s2
|
|
113
|
+
const s1: [32]u8 = @splat(0x01);
|
|
114
|
+
const s2: [32]u8 = @splat(0x02);
|
|
115
115
|
const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little);
|
|
116
116
|
const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little));
|
|
117
117
|
try testing.expect(pr1.equivalent(pr2));
|
|
@@ -120,8 +120,8 @@ test "p256 double base multiplication" {
|
|
|
120
120
|
test "p256 double base multiplication with large scalars" {
|
|
121
121
|
const p1 = P256.basePoint;
|
|
122
122
|
const p2 = P256.basePoint.dbl();
|
|
123
|
-
const s1
|
|
124
|
-
const s2
|
|
123
|
+
const s1: [32]u8 = @splat(0xee);
|
|
124
|
+
const s2: [32]u8 = @splat(0xdd);
|
|
125
125
|
const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little);
|
|
126
126
|
const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little));
|
|
127
127
|
try testing.expect(pr1.equivalent(pr2));
|