authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-06 02:40:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-06 02:40:05-07:00
logfa40bddf27a485e57d0758426cd806711e14b3ee
treef32fe91e898b1201c7834422e8274e6f3582fbb8
parent38e30632960500c626ea3c110468f4a0185e8aac
parentaab1284e10f962af300f495c5e3feccb54bd4964

Merge remote-tracking branch 'origin/master' into llvm14


2 files changed, 21 insertions(+), 5 deletions(-)

lib/std/crypto/ecdsa.zig+16-4
......@@ -62,13 +62,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
6262 }
6363
6464 /// Encode the public key using the compressed SEC-1 format.
65 pub fn toCompressedSec1(p: Curve) [compressed_sec1_encoded_length]u8 {
66 return p.toCompressedSec1();
65 pub fn toCompressedSec1(pk: PublicKey) [compressed_sec1_encoded_length]u8 {
66 return pk.p.toCompressedSec1();
6767 }
6868
6969 /// Encoding the public key using the uncompressed SEC-1 format.
70 pub fn toUncompressedSec1(p: Curve) [uncompressed_sec1_encoded_length]u8 {
71 return p.toUncompressedSec1();
70 pub fn toUncompressedSec1(pk: PublicKey) [uncompressed_sec1_encoded_length]u8 {
71 return pk.p.toUncompressedSec1();
7272 }
7373 };
7474
......@@ -743,3 +743,15 @@ fn tvTry(vector: TestVector) !void {
743743 const sig = try Scheme.Signature.fromDer(sig_der);
744744 try sig.verify(msg, pk);
745745}
746
747test "ECDSA - Sec1 encoding/decoding" {
748 const Scheme = EcdsaP384Sha384;
749 const kp = try Scheme.KeyPair.create(null);
750 const pk = kp.public_key;
751 const pk_compressed_sec1 = pk.toCompressedSec1();
752 const pk_recovered1 = try Scheme.PublicKey.fromSec1(&pk_compressed_sec1);
753 try testing.expectEqualSlices(u8, &pk_recovered1.toCompressedSec1(), &pk_compressed_sec1);
754 const pk_uncompressed_sec1 = pk.toUncompressedSec1();
755 const pk_recovered2 = try Scheme.PublicKey.fromSec1(&pk_uncompressed_sec1);
756 try testing.expectEqualSlices(u8, &pk_recovered2.toUncompressedSec1(), &pk_uncompressed_sec1);
757}
test/standalone.zig+5-1
......@@ -52,7 +52,11 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
5252 }
5353
5454 // Ensure the development tools are buildable.
55 cases.add("tools/gen_spirv_spec.zig");
55
56 // Disabled due to tripping LLVM 13 assertion:
57 // https://github.com/ziglang/zig/issues/12015
58 //cases.add("tools/gen_spirv_spec.zig");
59
5660 cases.add("tools/gen_stubs.zig");
5761 cases.add("tools/generate_linux_syscalls.zig");
5862 cases.add("tools/process_headers.zig");