diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-10-22 08:06:47 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-22 08:06:47 -0400 |
| commit | 0c99ba1eab63865592bb084feb271cd4e4b0357e (patch) | |
| tree | 7004c99fc0619ff94317cc176900d1d3a3c88335 /lib/std/crypto | |
| parent | 5f92b070bf284f1493b1b5d433dd3adde2f46727 (diff) | |
| parent | 920e9668ddb16fbb98cd08b43ed2364062a4b102 (diff) | |
| download | zig-0c99ba1eab63865592bb084feb271cd4e4b0357e.tar.gz zig-0c99ba1eab63865592bb084feb271cd4e4b0357e.zip | |
Merge pull request #17637 from jacobly0/x86_64-test-std
x86_64: start to enable `test-std` and `test-compiler-rt` testing
Diffstat (limited to 'lib/std/crypto')
32 files changed, 293 insertions, 16 deletions
diff --git a/lib/std/crypto/25519/curve25519.zig b/lib/std/crypto/25519/curve25519.zig index 7c3343ba8c..5377a9d141 100644 --- a/lib/std/crypto/25519/curve25519.zig +++ b/lib/std/crypto/25519/curve25519.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const crypto = std.crypto; const IdentityElementError = crypto.errors.IdentityElementError; @@ -111,6 +112,8 @@ pub const Curve25519 = struct { }; test "curve25519" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var s = [32]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 }; const p = try Curve25519.basePoint.clampedMul(s); try p.rejectIdentity(); @@ -125,6 +128,8 @@ test "curve25519" { } test "curve25519 small order check" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var s: [32]u8 = [_]u8{1} ++ [_]u8{0} ** 31; const small_order_ss: [7][32]u8 = .{ .{ diff --git a/lib/std/crypto/25519/ed25519.zig b/lib/std/crypto/25519/ed25519.zig index fc123386f8..43051fb5bf 100644 --- a/lib/std/crypto/25519/ed25519.zig +++ b/lib/std/crypto/25519/ed25519.zig @@ -1,5 +1,5 @@ -const builtin = @import("builtin"); const std = @import("std"); +const builtin = @import("builtin"); const crypto = std.crypto; const debug = std.debug; const fmt = std.fmt; @@ -484,6 +484,8 @@ pub const Ed25519 = struct { }; test "ed25519 key pair creation" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var seed: [32]u8 = undefined; _ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166"); const key_pair = try Ed25519.KeyPair.create(seed); @@ -493,6 +495,8 @@ test "ed25519 key pair creation" { } test "ed25519 signature" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var seed: [32]u8 = undefined; _ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166"); const key_pair = try Ed25519.KeyPair.create(seed); @@ -505,6 +509,8 @@ test "ed25519 signature" { } test "ed25519 batch verification" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var i: usize = 0; while (i < 100) : (i += 1) { const key_pair = try Ed25519.KeyPair.create(null); @@ -534,6 +540,8 @@ test "ed25519 batch verification" { } test "ed25519 test vectors" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const Vec = struct { msg_hex: *const [64:0]u8, public_key_hex: *const [64:0]u8, @@ -636,6 +644,8 @@ test "ed25519 test vectors" { } test "ed25519 with blind keys" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const BlindKeyPair = Ed25519.key_blinding.BlindKeyPair; // Create a standard Ed25519 key pair @@ -659,6 +669,8 @@ test "ed25519 with blind keys" { } test "ed25519 signatures with streaming" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const kp = try Ed25519.KeyPair.create(null); var signer = try kp.signer(null); @@ -675,6 +687,8 @@ test "ed25519 signatures with streaming" { } test "ed25519 key pair from secret key" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const kp = try Ed25519.KeyPair.create(null); const kp2 = try Ed25519.KeyPair.fromSecretKey(kp.secret_key); try std.testing.expectEqualSlices(u8, &kp.secret_key.toBytes(), &kp2.secret_key.toBytes()); diff --git a/lib/std/crypto/25519/edwards25519.zig b/lib/std/crypto/25519/edwards25519.zig index 0d42073705..7e099fcf4c 100644 --- a/lib/std/crypto/25519/edwards25519.zig +++ b/lib/std/crypto/25519/edwards25519.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const crypto = std.crypto; const debug = std.debug; const fmt = std.fmt; @@ -494,6 +495,8 @@ pub const Edwards25519 = struct { const htest = @import("../test.zig"); test "edwards25519 packing/unpacking" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const s = [_]u8{170} ++ [_]u8{0} ** 31; var b = Edwards25519.basePoint; const pk = try b.mul(s); @@ -530,6 +533,8 @@ test "edwards25519 packing/unpacking" { } test "edwards25519 point addition/subtraction" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var s1: [32]u8 = undefined; var s2: [32]u8 = undefined; crypto.random.bytes(&s1); @@ -544,6 +549,8 @@ test "edwards25519 point addition/subtraction" { } test "edwards25519 uniform-to-point" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var r = [32]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }; var p = Edwards25519.fromUniform(r); try htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]); @@ -555,6 +562,8 @@ test "edwards25519 uniform-to-point" { // Test vectors from draft-irtf-cfrg-hash-to-curve-12 test "edwards25519 hash-to-curve operation" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var p = Edwards25519.fromString(true, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_RO_", "abc"); try htest.assertEqual("31558a26887f23fb8218f143e69d5f0af2e7831130bd5b432ef23883b895839a", p.toBytes()[0..]); @@ -563,6 +572,8 @@ test "edwards25519 hash-to-curve operation" { } test "edwards25519 implicit reduction of invalid scalars" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const s = [_]u8{0} ** 31 ++ [_]u8{255}; const p1 = try Edwards25519.basePoint.mulPublic(s); const p2 = try Edwards25519.basePoint.mul(s); diff --git a/lib/std/crypto/25519/ristretto255.zig b/lib/std/crypto/25519/ristretto255.zig index d12a672e7d..d3482f278f 100644 --- a/lib/std/crypto/25519/ristretto255.zig +++ b/lib/std/crypto/25519/ristretto255.zig @@ -168,6 +168,8 @@ pub const Ristretto255 = struct { }; test "ristretto255" { + if (@import("builtin").zig_backend == .stage2_x86_64) return error.SkipZigTest; + const p = Ristretto255.basePoint; var buf: [256]u8 = undefined; try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76"); diff --git a/lib/std/crypto/25519/x25519.zig b/lib/std/crypto/25519/x25519.zig index b746a51968..7da73f2480 100644 --- a/lib/std/crypto/25519/x25519.zig +++ b/lib/std/crypto/25519/x25519.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const crypto = std.crypto; const mem = std.mem; const fmt = std.fmt; @@ -82,6 +83,8 @@ pub const X25519 = struct { const htest = @import("../test.zig"); test "x25519 public key calculation from secret key" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var sk: [32]u8 = undefined; var pk_expected: [32]u8 = undefined; _ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166"); @@ -91,6 +94,8 @@ test "x25519 public key calculation from secret key" { } test "x25519 rfc7748 vector1" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const secret_key = [32]u8{ 0xa5, 0x46, 0xe3, 0x6b, 0xf0, 0x52, 0x7c, 0x9d, 0x3b, 0x16, 0x15, 0x4b, 0x82, 0x46, 0x5e, 0xdd, 0x62, 0x14, 0x4c, 0x0a, 0xc1, 0xfc, 0x5a, 0x18, 0x50, 0x6a, 0x22, 0x44, 0xba, 0x44, 0x9a, 0xc4 }; const public_key = [32]u8{ 0xe6, 0xdb, 0x68, 0x67, 0x58, 0x30, 0x30, 0xdb, 0x35, 0x94, 0xc1, 0xa4, 0x24, 0xb1, 0x5f, 0x7c, 0x72, 0x66, 0x24, 0xec, 0x26, 0xb3, 0x35, 0x3b, 0x10, 0xa9, 0x03, 0xa6, 0xd0, 0xab, 0x1c, 0x4c }; @@ -101,6 +106,8 @@ test "x25519 rfc7748 vector1" { } test "x25519 rfc7748 vector2" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const secret_key = [32]u8{ 0x4b, 0x66, 0xe9, 0xd4, 0xd1, 0xb4, 0x67, 0x3c, 0x5a, 0xd2, 0x26, 0x91, 0x95, 0x7d, 0x6a, 0xf5, 0xc1, 0x1b, 0x64, 0x21, 0xe0, 0xea, 0x01, 0xd4, 0x2c, 0xa4, 0x16, 0x9e, 0x79, 0x18, 0xba, 0x0d }; const public_key = [32]u8{ 0xe5, 0x21, 0x0f, 0x12, 0x78, 0x68, 0x11, 0xd3, 0xf4, 0xb7, 0x95, 0x9d, 0x05, 0x38, 0xae, 0x2c, 0x31, 0xdb, 0xe7, 0x10, 0x6f, 0xc0, 0x3c, 0x3e, 0xfc, 0x4c, 0xd5, 0x49, 0xc7, 0x15, 0xa4, 0x93 }; @@ -111,6 +118,8 @@ test "x25519 rfc7748 vector2" { } test "x25519 rfc7748 one iteration" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const initial_value = [32]u8{ 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; const expected_output = [32]u8{ 0x42, 0x2c, 0x8e, 0x7a, 0x62, 0x27, 0xd7, 0xbc, 0xa1, 0x35, 0x0b, 0x3e, 0x2b, 0xb7, 0x27, 0x9f, 0x78, 0x97, 0xb8, 0x7b, 0xb6, 0x85, 0x4b, 0x78, 0x3c, 0x60, 0xe8, 0x03, 0x11, 0xae, 0x30, 0x79 }; @@ -128,6 +137,8 @@ test "x25519 rfc7748 one iteration" { } test "x25519 rfc7748 1,000 iterations" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + // These iteration tests are slow so we always skip them. Results have been verified. if (true) { return error.SkipZigTest; @@ -150,6 +161,8 @@ test "x25519 rfc7748 1,000 iterations" { } test "x25519 rfc7748 1,000,000 iterations" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (true) { return error.SkipZigTest; } @@ -171,6 +184,8 @@ test "x25519 rfc7748 1,000,000 iterations" { } test "edwards25519 -> curve25519 map" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const ed_kp = try crypto.sign.Ed25519.KeyPair.create([_]u8{0x42} ** 32); const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp); try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key); diff --git a/lib/std/crypto/Certificate.zig b/lib/std/crypto/Certificate.zig index f28894fc0d..1b1d4812d3 100644 --- a/lib/std/crypto/Certificate.zig +++ b/lib/std/crypto/Certificate.zig @@ -624,6 +624,8 @@ pub fn parseTimeDigits(text: *const [2]u8, min: u8, max: u8) !u8 { } test parseTimeDigits { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const expectEqual = std.testing.expectEqual; try expectEqual(@as(u8, 0), try parseTimeDigits("00", 0, 99)); try expectEqual(@as(u8, 99), try parseTimeDigits("99", 0, 99)); @@ -645,6 +647,8 @@ pub fn parseYear4(text: *const [4]u8) !u16 { } test parseYear4 { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const expectEqual = std.testing.expectEqual; try expectEqual(@as(u16, 0), try parseYear4("0000")); try expectEqual(@as(u16, 9999), try parseYear4("9999")); @@ -1119,3 +1123,5 @@ pub const rsa = struct { return res; } }; + +const builtin = @import("builtin"); diff --git a/lib/std/crypto/Certificate/Bundle.zig b/lib/std/crypto/Certificate/Bundle.zig index b5a3832115..1bffa325bd 100644 --- a/lib/std/crypto/Certificate/Bundle.zig +++ b/lib/std/crypto/Certificate/Bundle.zig @@ -318,6 +318,8 @@ const MapContext = struct { test "scan for OS-provided certificates" { if (builtin.os.tag == .wasi) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var bundle: Bundle = .{}; defer bundle.deinit(std.testing.allocator); diff --git a/lib/std/crypto/aegis.zig b/lib/std/crypto/aegis.zig index 18047a13b5..5a7f2ec017 100644 --- a/lib/std/crypto/aegis.zig +++ b/lib/std/crypto/aegis.zig @@ -17,6 +17,7 @@ //! https://datatracker.ietf.org/doc/draft-irtf-cfrg-aegis-aead/ const std = @import("std"); +const builtin = @import("builtin"); const crypto = std.crypto; const mem = std.mem; const assert = std.debug.assert; @@ -513,6 +514,8 @@ const htest = @import("test.zig"); const testing = std.testing; test "Aegis128L test vector 1" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 14; const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 13; const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; @@ -536,6 +539,8 @@ test "Aegis128L test vector 1" { } test "Aegis128L test vector 2" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key: [Aegis128L.key_length]u8 = [_]u8{0x00} ** 16; const nonce: [Aegis128L.nonce_length]u8 = [_]u8{0x00} ** 16; const ad = [_]u8{}; @@ -553,6 +558,8 @@ test "Aegis128L test vector 2" { } test "Aegis128L test vector 3" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key: [Aegis128L.key_length]u8 = [_]u8{0x00} ** 16; const nonce: [Aegis128L.nonce_length]u8 = [_]u8{0x00} ** 16; const ad = [_]u8{}; @@ -569,6 +576,8 @@ test "Aegis128L test vector 3" { } test "Aegis256 test vector 1" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key: [Aegis256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 30; const nonce: [Aegis256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 29; const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; @@ -592,6 +601,8 @@ test "Aegis256 test vector 1" { } test "Aegis256 test vector 2" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key: [Aegis256.key_length]u8 = [_]u8{0x00} ** 32; const nonce: [Aegis256.nonce_length]u8 = [_]u8{0x00} ** 32; const ad = [_]u8{}; @@ -609,6 +620,8 @@ test "Aegis256 test vector 2" { } test "Aegis256 test vector 3" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key: [Aegis256.key_length]u8 = [_]u8{0x00} ** 32; const nonce: [Aegis256.nonce_length]u8 = [_]u8{0x00} ** 32; const ad = [_]u8{}; @@ -625,6 +638,8 @@ test "Aegis256 test vector 3" { } test "Aegis MAC" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{0x00} ** Aegis128LMac.key_length; var msg: [64]u8 = undefined; for (&msg, 0..) |*m, i| { diff --git a/lib/std/crypto/aes.zig b/lib/std/crypto/aes.zig index 70246e6630..875898d2e5 100644 --- a/lib/std/crypto/aes.zig +++ b/lib/std/crypto/aes.zig @@ -28,6 +28,8 @@ pub const Aes128 = impl.Aes128; pub const Aes256 = impl.Aes256; test "ctr" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + // NIST SP 800-38A pp 55-58 const ctr = @import("modes.zig").ctr; @@ -53,6 +55,8 @@ test "ctr" { } test "encrypt" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + // Appendix B { const key = [_]u8{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; @@ -82,6 +86,8 @@ test "encrypt" { } test "decrypt" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + // Appendix B { const key = [_]u8{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; @@ -111,6 +117,8 @@ test "decrypt" { } test "expand 128-bit key" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; const exp_enc = [_]*const [32:0]u8{ "2b7e151628aed2a6abf7158809cf4f3c", "a0fafe1788542cb123a339392a6c7605", "f2c295f27a96b9435935807a7359f67f", "3d80477d4716fe3e1e237e446d7a883b", "ef44a541a8525b7fb671253bdb0bad00", "d4d1c6f87c839d87caf2b8bc11f915bc", "6d88a37a110b3efddbf98641ca0093fd", "4e54f70e5f5fc9f384a64fb24ea6dc4f", "ead27321b58dbad2312bf5607f8d292f", "ac7766f319fadc2128d12941575c006e", "d014f9a8c9ee2589e13f0cc8b6630ca6", @@ -133,6 +141,8 @@ test "expand 128-bit key" { } test "expand 256-bit key" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, diff --git a/lib/std/crypto/aes_gcm.zig b/lib/std/crypto/aes_gcm.zig index fdc42997ad..1715636bed 100644 --- a/lib/std/crypto/aes_gcm.zig +++ b/lib/std/crypto/aes_gcm.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const assert = std.debug.assert; const crypto = std.crypto; const debug = std.debug; @@ -112,6 +113,8 @@ const htest = @import("test.zig"); const testing = std.testing; test "Aes256Gcm - Empty message and no associated data" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; const ad = ""; @@ -124,6 +127,8 @@ test "Aes256Gcm - Empty message and no associated data" { } test "Aes256Gcm - Associated data only" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; const m = ""; @@ -136,6 +141,8 @@ test "Aes256Gcm - Associated data only" { } test "Aes256Gcm - Message only" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; const m = "Test with message only"; @@ -153,6 +160,8 @@ test "Aes256Gcm - Message only" { } test "Aes256Gcm - Message and associated data" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; const m = "Test with message"; diff --git a/lib/std/crypto/aes_ocb.zig b/lib/std/crypto/aes_ocb.zig index 3f0a98a5d7..0209d07ec6 100644 --- a/lib/std/crypto/aes_ocb.zig +++ b/lib/std/crypto/aes_ocb.zig @@ -261,7 +261,10 @@ inline fn xorWith(x: *Block, y: Block) void { const hexToBytes = std.fmt.hexToBytes; test "AesOcb test vector 1" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + switch (builtin.zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } var k: [Aes128Ocb.key_length]u8 = undefined; var nonce: [Aes128Ocb.nonce_length]u8 = undefined; @@ -280,7 +283,10 @@ test "AesOcb test vector 1" { } test "AesOcb test vector 2" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + switch (builtin.zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } var k: [Aes128Ocb.key_length]u8 = undefined; var nonce: [Aes128Ocb.nonce_length]u8 = undefined; @@ -301,7 +307,10 @@ test "AesOcb test vector 2" { } test "AesOcb test vector 3" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + switch (builtin.zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } var k: [Aes128Ocb.key_length]u8 = undefined; var nonce: [Aes128Ocb.nonce_length]u8 = undefined; @@ -325,7 +334,10 @@ test "AesOcb test vector 3" { } test "AesOcb test vector 4" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + switch (builtin.zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } var k: [Aes128Ocb.key_length]u8 = undefined; var nonce: [Aes128Ocb.nonce_length]u8 = undefined; diff --git a/lib/std/crypto/argon2.zig b/lib/std/crypto/argon2.zig index 898bc24e6f..05dd686aac 100644 --- a/lib/std/crypto/argon2.zig +++ b/lib/std/crypto/argon2.zig @@ -622,6 +622,8 @@ pub fn strVerify( } test "argon2d" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const password = [_]u8{0x01} ** 32; const salt = [_]u8{0x02} ** 16; const secret = [_]u8{0x03} ** 8; @@ -647,6 +649,8 @@ test "argon2d" { } test "argon2i" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const password = [_]u8{0x01} ** 32; const salt = [_]u8{0x02} ** 16; const secret = [_]u8{0x03} ** 8; @@ -672,6 +676,8 @@ test "argon2i" { } test "argon2id" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const password = [_]u8{0x01} ** 32; const salt = [_]u8{0x02} ** 16; const secret = [_]u8{0x03} ** 8; @@ -697,6 +703,8 @@ test "argon2id" { } test "kdf" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const password = "password"; const salt = "somesalt"; @@ -896,6 +904,8 @@ test "kdf" { } test "phc format hasher" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const allocator = std.testing.allocator; const password = "testpass"; @@ -911,6 +921,8 @@ test "phc format hasher" { } test "password hash and password verify" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const allocator = std.testing.allocator; const password = "testpass"; @@ -924,6 +936,8 @@ test "password hash and password verify" { } test "kdf derived key length" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const allocator = std.testing.allocator; const password = "testpass"; diff --git a/lib/std/crypto/bcrypt.zig b/lib/std/crypto/bcrypt.zig index 87d2eef79a..ce3a5aec79 100644 --- a/lib/std/crypto/bcrypt.zig +++ b/lib/std/crypto/bcrypt.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const base64 = std.base64; const crypto = std.crypto; const debug = std.debug; @@ -753,6 +754,8 @@ pub fn strVerify( } test "bcrypt codec" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var salt: [salt_length]u8 = undefined; crypto.random.bytes(&salt); var salt_str: [salt_str_length]u8 = undefined; @@ -763,6 +766,8 @@ test "bcrypt codec" { } test "bcrypt crypt format" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var hash_options = HashOptions{ .params = .{ .rounds_log = 5 }, .encoding = .crypt, @@ -803,6 +808,8 @@ test "bcrypt crypt format" { } test "bcrypt phc format" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var hash_options = HashOptions{ .params = .{ .rounds_log = 5 }, .encoding = .phc, diff --git a/lib/std/crypto/blake3.zig b/lib/std/crypto/blake3.zig index fc1859b99d..08c38ec63b 100644 --- a/lib/std/crypto/blake3.zig +++ b/lib/std/crypto/blake3.zig @@ -200,7 +200,7 @@ const CompressGeneric = struct { } }; -const compress = if (builtin.cpu.arch == .x86_64) +const compress = if (builtin.cpu.arch == .x86_64 and builtin.zig_backend != .stage2_x86_64) CompressVectorized.compress else CompressGeneric.compress; @@ -682,6 +682,8 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void { } test "BLAKE3 reference test cases" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var hash_state = Blake3.init(.{}); const hash = &hash_state; var keyed_hash_state = Blake3.init(.{ .key = reference_test.key.* }); diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig index b45d1c5295..c6a2ddafe7 100644 --- a/lib/std/crypto/chacha20.zig +++ b/lib/std/crypto/chacha20.zig @@ -499,6 +499,8 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { fn ChaChaImpl(comptime rounds_nb: usize) type { switch (builtin.cpu.arch) { .x86_64 => { + if (builtin.zig_backend == .stage2_x86_64) return ChaChaNonVecImpl(rounds_nb); + const has_avx2 = std.Target.x86.featureSetHas(builtin.cpu.features, .avx2); const has_avx512f = std.Target.x86.featureSetHas(builtin.cpu.features, .avx512f); if (has_avx512f) return ChaChaVecImpl(rounds_nb, 4); @@ -757,6 +759,8 @@ fn XChaChaPoly1305(comptime rounds_nb: usize) type { } test "chacha20 AEAD API" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const aeads = [_]type{ ChaCha20Poly1305, XChaCha20Poly1305 }; 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."; const ad = "Additional data"; @@ -778,6 +782,8 @@ test "chacha20 AEAD API" { // https://tools.ietf.org/html/rfc7539#section-2.4.2 test "crypto.chacha20 test vector sunscreen" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const expected_result = [_]u8{ 0x6e, 0x2e, 0x35, 0x9a, 0x25, 0x68, 0xf9, 0x80, 0x41, 0xba, 0x07, 0x28, 0xdd, 0x0d, 0x69, 0x81, @@ -819,6 +825,8 @@ test "crypto.chacha20 test vector sunscreen" { // https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7 test "crypto.chacha20 test vector 1" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const expected_result = [_]u8{ 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, 0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28, @@ -853,6 +861,8 @@ test "crypto.chacha20 test vector 1" { } test "crypto.chacha20 test vector 2" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const expected_result = [_]u8{ 0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96, 0xd7, 0x73, 0x6e, 0x7b, 0x20, 0x8e, 0x3c, 0x96, @@ -887,6 +897,8 @@ test "crypto.chacha20 test vector 2" { } test "crypto.chacha20 test vector 3" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const expected_result = [_]u8{ 0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5, 0xe7, 0x86, 0xdc, 0x63, 0x97, 0x3f, 0x65, 0x3a, @@ -921,6 +933,8 @@ test "crypto.chacha20 test vector 3" { } test "crypto.chacha20 test vector 4" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const expected_result = [_]u8{ 0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb, 0xf5, 0xcf, 0x35, 0xbd, 0x3d, 0xd3, 0x3b, 0x80, @@ -955,6 +969,8 @@ test "crypto.chacha20 test vector 4" { } test "crypto.chacha20 test vector 5" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const expected_result = [_]u8{ 0xf7, 0x98, 0xa1, 0x89, 0xf1, 0x95, 0xe6, 0x69, 0x82, 0x10, 0x5f, 0xfb, 0x64, 0x0b, 0xb7, 0x75, @@ -1027,6 +1043,8 @@ test "crypto.chacha20 test vector 5" { } test "seal" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + { const m = ""; const ad = ""; @@ -1077,6 +1095,8 @@ test "seal" { } test "open" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + { const c = [_]u8{ 0xa0, 0x78, 0x4d, 0x7a, 0x47, 0x16, 0xf3, 0xfe, 0xb4, 0xf6, 0x4e, 0x7f, 0x4b, 0x39, 0xbf, 0x4 }; const ad = ""; @@ -1141,6 +1161,8 @@ test "open" { } test "crypto.xchacha20" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{69} ** 32; const nonce = [_]u8{42} ** 24; 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."; diff --git a/lib/std/crypto/cmac.zig b/lib/std/crypto/cmac.zig index fd00461858..5f2d332c01 100644 --- a/lib/std/crypto/cmac.zig +++ b/lib/std/crypto/cmac.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const crypto = std.crypto; const mem = std.mem; @@ -93,6 +94,8 @@ pub fn Cmac(comptime BlockCipher: type) type { const testing = std.testing; test "CmacAes128 - Example 1: len = 0" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c, }; @@ -106,6 +109,8 @@ test "CmacAes128 - Example 1: len = 0" { } test "CmacAes128 - Example 2: len = 16" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c, }; @@ -121,6 +126,8 @@ test "CmacAes128 - Example 2: len = 16" { } test "CmacAes128 - Example 3: len = 40" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c, }; @@ -138,6 +145,8 @@ test "CmacAes128 - Example 3: len = 40" { } test "CmacAes128 - Example 4: len = 64" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c, }; diff --git a/lib/std/crypto/ecdsa.zig b/lib/std/crypto/ecdsa.zig index 1a5335b07e..acb054d8cd 100644 --- a/lib/std/crypto/ecdsa.zig +++ b/lib/std/crypto/ecdsa.zig @@ -372,7 +372,10 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { } test "ECDSA - Basic operations over EcdsaP384Sha384" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + switch (builtin.zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } const Scheme = EcdsaP384Sha384; const kp = try Scheme.KeyPair.create(null); @@ -388,7 +391,10 @@ test "ECDSA - Basic operations over EcdsaP384Sha384" { } test "ECDSA - Basic operations over Secp256k1" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + switch (builtin.zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } const Scheme = EcdsaSecp256k1Sha256oSha256; const kp = try Scheme.KeyPair.create(null); @@ -404,7 +410,10 @@ test "ECDSA - Basic operations over Secp256k1" { } test "ECDSA - Basic operations over EcdsaP384Sha256" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + switch (builtin.zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } const Scheme = Ecdsa(crypto.ecc.P384, crypto.hash.sha2.Sha256); const kp = try Scheme.KeyPair.create(null); @@ -420,7 +429,10 @@ test "ECDSA - Basic operations over EcdsaP384Sha256" { } test "ECDSA - Verifying a existing signature with EcdsaP384Sha256" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + switch (builtin.zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } const Scheme = Ecdsa(crypto.ecc.P384, crypto.hash.sha2.Sha256); // zig fmt: off @@ -464,7 +476,10 @@ const TestVector = struct { }; test "ECDSA - Test vectors from Project Wycheproof" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + switch (builtin.zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } const vectors = [_]TestVector{ .{ .key = "042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e", .msg = "313233343030", .sig = "304402202ba3a8be6b94d5ec80a6d9d1190a436effe50d85a1eee859b8cc6af9bd5c2e1802204cd60b855d442f5b3c7b11eb6c4e0ae7525fe710fab9aa7c77a67f79e6fadd76", .result = .valid }, @@ -878,7 +893,10 @@ fn tvTry(vector: TestVector) !void { } test "ECDSA - Sec1 encoding/decoding" { - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + switch (builtin.zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } const Scheme = EcdsaP384Sha384; const kp = try Scheme.KeyPair.create(null); diff --git a/lib/std/crypto/ff.zig b/lib/std/crypto/ff.zig index 287d37544f..037feae5ed 100644 --- a/lib/std/crypto/ff.zig +++ b/lib/std/crypto/ff.zig @@ -912,7 +912,10 @@ const ct_unprotected = struct { }; test { - if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; + switch (@import("builtin").zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } const M = Modulus(256); const m = try M.fromPrimitive(u256, 3429938563481314093726330772853735541133072814650493833233); diff --git a/lib/std/crypto/ghash_polyval.zig b/lib/std/crypto/ghash_polyval.zig index 11379cc8e3..3a78db6214 100644 --- a/lib/std/crypto/ghash_polyval.zig +++ b/lib/std/crypto/ghash_polyval.zig @@ -422,6 +422,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { const htest = @import("test.zig"); test "ghash" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{0x42} ** 16; const m = [_]u8{0x69} ** 256; @@ -439,6 +441,8 @@ test "ghash" { } test "ghash2" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var key: [16]u8 = undefined; var i: usize = 0; while (i < key.len) : (i += 1) { @@ -472,6 +476,8 @@ test "ghash2" { } test "polyval" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{0x42} ** 16; const m = [_]u8{0x69} ** 256; diff --git a/lib/std/crypto/hash_composition.zig b/lib/std/crypto/hash_composition.zig index 1ffa3d4c47..234a990a83 100644 --- a/lib/std/crypto/hash_composition.zig +++ b/lib/std/crypto/hash_composition.zig @@ -65,6 +65,8 @@ pub const Sha384oSha384 = Composition(sha2.Sha384, sha2.Sha384); pub const Sha512oSha512 = Composition(sha2.Sha512, sha2.Sha512); test "Hash composition" { + if (@import("builtin").zig_backend == .stage2_x86_64) return error.SkipZigTest; + const Sha256 = sha2.Sha256; const msg = "test"; diff --git a/lib/std/crypto/hkdf.zig b/lib/std/crypto/hkdf.zig index 9163ba9d15..f0865a9d5e 100644 --- a/lib/std/crypto/hkdf.zig +++ b/lib/std/crypto/hkdf.zig @@ -72,6 +72,8 @@ pub fn Hkdf(comptime Hmac: type) type { const htest = @import("test.zig"); test "Hkdf" { + if (@import("builtin").zig_backend == .stage2_x86_64) return error.SkipZigTest; + const ikm = [_]u8{0x0b} ** 22; const salt = [_]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c }; const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; diff --git a/lib/std/crypto/kyber_d00.zig b/lib/std/crypto/kyber_d00.zig index ba6ed67ec8..fa1627dbd1 100644 --- a/lib/std/crypto/kyber_d00.zig +++ b/lib/std/crypto/kyber_d00.zig @@ -553,6 +553,8 @@ const inv_ntt_reductions = [_]i16{ }; test "invNTTReductions bounds" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + // Checks whether the reductions proposed by invNTTReductions // don't overflow during invNTT(). var xs = [_]i32{1} ** 256; // start at |x| ≤ q @@ -656,6 +658,8 @@ fn montReduce(x: i32) i16 { } test "Test montReduce" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var rnd = RndGen.init(0); for (0..1000) |_| { const bound = comptime @as(i32, Q) * (1 << 15); @@ -674,6 +678,8 @@ fn feToMont(x: i16) i16 { } test "Test feToMont" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var x: i32 = -(1 << 15); while (x < 1 << 15) : (x += 1) { const y = feToMont(@as(i16, @intCast(x))); @@ -707,6 +713,8 @@ fn feBarrettReduce(x: i16) i16 { } test "Test Barrett reduction" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var x: i32 = -(1 << 15); while (x < 1 << 15) : (x += 1) { var y1 = feBarrettReduce(@as(i16, @intCast(x))); @@ -727,6 +735,8 @@ fn csubq(x: i16) i16 { } test "Test csubq" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var x: i32 = -29439; while (x < 1 << 15) : (x += 1) { const y1 = csubq(@as(i16, @intCast(x))); @@ -1466,6 +1476,8 @@ fn cmov(comptime len: usize, dst: *[len]u8, src: [len]u8, b: u1) void { } test "MulHat" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var rnd = RndGen.init(0); for (0..100) |_| { @@ -1497,6 +1509,8 @@ test "MulHat" { } test "NTT" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var rnd = RndGen.init(0); for (0..1000) |_| { @@ -1520,6 +1534,8 @@ test "NTT" { } test "Compression" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var rnd = RndGen.init(0); inline for (.{ 1, 4, 5, 10, 11 }) |d| { for (0..1000) |_| { @@ -1532,6 +1548,8 @@ test "Compression" { } test "noise" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var seed: [32]u8 = undefined; for (&seed, 0..) |*s, i| { s.* = @as(u8, @intCast(i)); @@ -1578,6 +1596,8 @@ test "noise" { } test "uniform sampling" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var seed: [32]u8 = undefined; for (&seed, 0..) |*s, i| { s.* = @as(u8, @intCast(i)); @@ -1611,6 +1631,8 @@ test "uniform sampling" { } test "Polynomial packing" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var rnd = RndGen.init(0); for (0..1000) |_| { @@ -1620,6 +1642,8 @@ test "Polynomial packing" { } test "Test inner PKE" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var seed: [32]u8 = undefined; var pt: [32]u8 = undefined; for (&seed, &pt, 0..) |*s, *p, i| { @@ -1641,6 +1665,8 @@ test "Test inner PKE" { } test "Test happy flow" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var seed: [64]u8 = undefined; for (&seed, 0..) |*s, i| { s.* = @as(u8, @intCast(i)); @@ -1667,6 +1693,8 @@ test "Test happy flow" { const sha2 = crypto.hash.sha2; test "NIST KAT test" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + inline for (.{ .{ Kyber512, "e9c2bd37133fcb40772f81559f14b1f58dccd1c816701be9ba6214d43baf4547" }, .{ Kyber1024, "89248f2f33f7f4f7051729111f3049c409a933ec904aedadf035f30fa5646cd5" }, diff --git a/lib/std/crypto/pbkdf2.zig b/lib/std/crypto/pbkdf2.zig index 2e0318369b..126935f02c 100644 --- a/lib/std/crypto/pbkdf2.zig +++ b/lib/std/crypto/pbkdf2.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const mem = std.mem; const maxInt = std.math.maxInt; const OutputTooLongError = std.crypto.errors.OutputTooLongError; @@ -151,6 +152,8 @@ const HmacSha1 = std.crypto.auth.hmac.HmacSha1; // RFC 6070 PBKDF2 HMAC-SHA1 Test Vectors test "RFC 6070 one iteration" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const p = "password"; const s = "salt"; const c = 1; @@ -166,6 +169,8 @@ test "RFC 6070 one iteration" { } test "RFC 6070 two iterations" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const p = "password"; const s = "salt"; const c = 2; @@ -181,6 +186,8 @@ test "RFC 6070 two iterations" { } test "RFC 6070 4096 iterations" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const p = "password"; const s = "salt"; const c = 4096; @@ -196,6 +203,8 @@ test "RFC 6070 4096 iterations" { } test "RFC 6070 16,777,216 iterations" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + // These iteration tests are slow so we always skip them. Results have been verified. if (true) { return error.SkipZigTest; @@ -216,6 +225,8 @@ test "RFC 6070 16,777,216 iterations" { } test "RFC 6070 multi-block salt and password" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const p = "passwordPASSWORDpassword"; const s = "saltSALTsaltSALTsaltSALTsaltSALTsalt"; const c = 4096; @@ -231,6 +242,8 @@ test "RFC 6070 multi-block salt and password" { } test "RFC 6070 embedded NUL" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const p = "pass\x00word"; const s = "sa\x00lt"; const c = 4096; @@ -246,6 +259,8 @@ test "RFC 6070 embedded NUL" { } test "Very large dk_len" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + // This test allocates 8GB of memory and is expected to take several hours to run. if (true) { return error.SkipZigTest; diff --git a/lib/std/crypto/pcurves/p256.zig b/lib/std/crypto/pcurves/p256.zig index 668c0115b2..87c963f834 100644 --- a/lib/std/crypto/pcurves/p256.zig +++ b/lib/std/crypto/pcurves/p256.zig @@ -478,5 +478,7 @@ pub const AffineCoordinates = struct { }; test { + if (@import("builtin").zig_backend == .stage2_x86_64) return error.SkipZigTest; + _ = @import("tests/p256.zig"); } diff --git a/lib/std/crypto/pcurves/p384.zig b/lib/std/crypto/pcurves/p384.zig index d5afd6eb4d..44dd4e50b7 100644 --- a/lib/std/crypto/pcurves/p384.zig +++ b/lib/std/crypto/pcurves/p384.zig @@ -478,7 +478,10 @@ pub const AffineCoordinates = struct { }; test { - if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; + switch (@import("builtin").zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } _ = @import("tests/p384.zig"); } diff --git a/lib/std/crypto/pcurves/secp256k1.zig b/lib/std/crypto/pcurves/secp256k1.zig index cd7f1faf75..6286b96249 100644 --- a/lib/std/crypto/pcurves/secp256k1.zig +++ b/lib/std/crypto/pcurves/secp256k1.zig @@ -556,7 +556,10 @@ pub const AffineCoordinates = struct { }; test { - if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; + switch (@import("builtin").zig_backend) { + .stage2_c, .stage2_x86_64 => return error.SkipZigTest, + else => {}, + } _ = @import("tests/secp256k1.zig"); } diff --git a/lib/std/crypto/phc_encoding.zig b/lib/std/crypto/phc_encoding.zig index fecd7f1239..58757cec28 100644 --- a/lib/std/crypto/phc_encoding.zig +++ b/lib/std/crypto/phc_encoding.zig @@ -1,6 +1,7 @@ // https://github.com/P-H-C/phc-string-format const std = @import("std"); +const builtin = @import("builtin"); const fmt = std.fmt; const io = std.io; const mem = std.mem; @@ -263,6 +264,8 @@ fn kvSplit(str: []const u8) !struct { key: []const u8, value: []const u8 } { } test "phc format - encoding/decoding" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const Input = struct { str: []const u8, HashResult: type, @@ -348,18 +351,24 @@ test "phc format - encoding/decoding" { } test "phc format - empty input string" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const s = ""; const v = deserialize(struct { alg_id: []const u8 }, s); try std.testing.expectError(Error.InvalidEncoding, v); } test "phc format - hash without salt" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const s = "$scrypt"; const v = deserialize(struct { alg_id: []const u8, hash: BinValue(16) }, s); try std.testing.expectError(Error.InvalidEncoding, v); } test "phc format - calcSize" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const s = "$scrypt$v=1$ln=15,r=8,p=1$c2FsdHNhbHQ$dGVzdHBhc3M"; const v = try deserialize(struct { alg_id: []const u8, diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig index 5bcb75169d..7bdbabae49 100644 --- a/lib/std/crypto/poly1305.zig +++ b/lib/std/crypto/poly1305.zig @@ -196,6 +196,8 @@ pub const Poly1305 = struct { }; test "poly1305 rfc7439 vector1" { + if (@import("builtin").zig_backend == .stage2_x86_64) return error.SkipZigTest; + const expected_mac = "\xa8\x06\x1d\xc1\x30\x51\x36\xc6\xc2\x2b\x8b\xaf\x0c\x01\x27\xa9"; const msg = "Cryptographic Forum Research Group"; diff --git a/lib/std/crypto/salsa20.zig b/lib/std/crypto/salsa20.zig index 9d95331839..a253bf5dd9 100644 --- a/lib/std/crypto/salsa20.zig +++ b/lib/std/crypto/salsa20.zig @@ -555,6 +555,8 @@ pub const SealedBox = struct { const htest = @import("test.zig"); test "(x)salsa20" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{0x69} ** 32; const nonce = [_]u8{0x42} ** 8; const msg = [_]u8{0} ** 20; @@ -569,6 +571,8 @@ test "(x)salsa20" { } test "xsalsa20poly1305" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var msg: [100]u8 = undefined; var msg2: [msg.len]u8 = undefined; var c: [msg.len]u8 = undefined; @@ -584,6 +588,8 @@ test "xsalsa20poly1305" { } test "xsalsa20poly1305 secretbox" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var msg: [100]u8 = undefined; var msg2: [msg.len]u8 = undefined; var key: [XSalsa20Poly1305.key_length]u8 = undefined; @@ -598,6 +604,8 @@ test "xsalsa20poly1305 secretbox" { } test "xsalsa20poly1305 box" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var msg: [100]u8 = undefined; var msg2: [msg.len]u8 = undefined; var nonce: [Box.nonce_length]u8 = undefined; @@ -612,6 +620,8 @@ test "xsalsa20poly1305 box" { } test "xsalsa20poly1305 sealedbox" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var msg: [100]u8 = undefined; var msg2: [msg.len]u8 = undefined; var boxed: [msg.len + SealedBox.seal_length]u8 = undefined; @@ -623,6 +633,8 @@ test "xsalsa20poly1305 sealedbox" { } test "secretbox twoblocks" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const key = [_]u8{ 0xc9, 0xc9, 0x4d, 0xcf, 0x68, 0xbe, 0x00, 0xe4, 0x7f, 0xe6, 0x13, 0x26, 0xfc, 0xc4, 0x2f, 0xd0, 0xdb, 0x93, 0x91, 0x1c, 0x09, 0x94, 0x89, 0xe1, 0x1b, 0x88, 0x63, 0x18, 0x86, 0x64, 0x8b, 0x7b }; const nonce = [_]u8{ 0xa4, 0x33, 0xe9, 0x0a, 0x07, 0x68, 0x6e, 0x9a, 0x2b, 0x6d, 0xd4, 0x59, 0x04, 0x72, 0x3e, 0xd3, 0x8a, 0x67, 0x55, 0xc7, 0x9e, 0x3e, 0x77, 0xdc }; const msg = [_]u8{'a'} ** 97; diff --git a/lib/std/crypto/scrypt.zig b/lib/std/crypto/scrypt.zig index 8745a3b34e..f830e8f120 100644 --- a/lib/std/crypto/scrypt.zig +++ b/lib/std/crypto/scrypt.zig @@ -3,6 +3,7 @@ // https://github.com/Tarsnap/scrypt const std = @import("std"); +const builtin = @import("builtin"); const crypto = std.crypto; const fmt = std.fmt; const io = std.io; @@ -683,6 +684,8 @@ test "unix-scrypt" { } test "crypt format" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const str = "$7$C6..../....SodiumChloride$kBGj9fHznVYFQMEn/qDCfrDevf9YDtcDdKvEqHJLV8D"; const params = try crypt_format.deserialize(crypt_format.HashResult(32), str); var buf: [str.len]u8 = undefined; @@ -691,6 +694,8 @@ test "crypt format" { } test "kdf fast" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + const TestVector = struct { password: []const u8, salt: []const u8, diff --git a/lib/std/crypto/sha2.zig b/lib/std/crypto/sha2.zig index f87ea90d92..4f09294a30 100644 --- a/lib/std/crypto/sha2.zig +++ b/lib/std/crypto/sha2.zig @@ -238,7 +238,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { return; }, // C backend doesn't currently support passing vectors to inline asm. - .x86_64 => if (builtin.zig_backend != .stage2_c and comptime std.Target.x86.featureSetHasAll(builtin.cpu.features, .{ .sha, .avx2 })) { + .x86_64 => if (builtin.zig_backend != .stage2_c and builtin.zig_backend != .stage2_x86_64 and comptime std.Target.x86.featureSetHasAll(builtin.cpu.features, .{ .sha, .avx2 })) { var x: v4u32 = [_]u32{ d.s[5], d.s[4], d.s[1], d.s[0] }; var y: v4u32 = [_]u32{ d.s[7], d.s[6], d.s[3], d.s[2] }; const s_v = @as(*[16]v4u32, @ptrCast(&s)); @@ -406,12 +406,16 @@ fn Sha2x32(comptime params: Sha2Params32) type { } test "sha224 single" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + try htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", ""); try htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc"); try htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); } test "sha224 streaming" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var h = Sha224.init(.{}); var out: [28]u8 = undefined; @@ -432,12 +436,16 @@ test "sha224 streaming" { } test "sha256 single" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + try htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""); try htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc"); try htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); } test "sha256 streaming" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var h = Sha256.init(.{}); var out: [32]u8 = undefined; @@ -458,6 +466,8 @@ test "sha256 streaming" { } test "sha256 aligned final" { + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + var block = [_]u8{0} ** Sha256.block_length; var out: [Sha256.digest_length]u8 = undefined; diff --git a/lib/std/crypto/utils.zig b/lib/std/crypto/utils.zig index ab1b6eab6a..4eb7281bc8 100644 --- a/lib/std/crypto/utils.zig +++ b/lib/std/crypto/utils.zig @@ -149,6 +149,8 @@ test "crypto.utils.timingSafeEql" { } test "crypto.utils.timingSafeEql (vectors)" { + if (@import("builtin").zig_backend == .stage2_x86_64) return error.SkipZigTest; + var a: [100]u8 = undefined; var b: [100]u8 = undefined; random.bytes(a[0..]); |
