commit fa40bddf27a485e57d0758426cd806711e14b3ee (tree)
parent 38e30632960500c626ea3c110468f4a0185e8aac
Author: Andrew Kelley <andrew@ziglang.org>
Date: Wed, 6 Jul 2022 02:40:05 -0700
Merge remote-tracking branch 'origin/master' into llvm14
Diffstat:
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/lib/std/crypto/ecdsa.zig b/lib/std/crypto/ecdsa.zig
@@ -62,13 +62,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
}
/// Encode the public key using the compressed SEC-1 format.
- pub fn toCompressedSec1(p: Curve) [compressed_sec1_encoded_length]u8 {
- return p.toCompressedSec1();
+ pub fn toCompressedSec1(pk: PublicKey) [compressed_sec1_encoded_length]u8 {
+ return pk.p.toCompressedSec1();
}
/// Encoding the public key using the uncompressed SEC-1 format.
- pub fn toUncompressedSec1(p: Curve) [uncompressed_sec1_encoded_length]u8 {
- return p.toUncompressedSec1();
+ pub fn toUncompressedSec1(pk: PublicKey) [uncompressed_sec1_encoded_length]u8 {
+ return pk.p.toUncompressedSec1();
}
};
@@ -743,3 +743,15 @@ fn tvTry(vector: TestVector) !void {
const sig = try Scheme.Signature.fromDer(sig_der);
try sig.verify(msg, pk);
}
+
+test "ECDSA - Sec1 encoding/decoding" {
+ const Scheme = EcdsaP384Sha384;
+ const kp = try Scheme.KeyPair.create(null);
+ const pk = kp.public_key;
+ const pk_compressed_sec1 = pk.toCompressedSec1();
+ const pk_recovered1 = try Scheme.PublicKey.fromSec1(&pk_compressed_sec1);
+ try testing.expectEqualSlices(u8, &pk_recovered1.toCompressedSec1(), &pk_compressed_sec1);
+ const pk_uncompressed_sec1 = pk.toUncompressedSec1();
+ const pk_recovered2 = try Scheme.PublicKey.fromSec1(&pk_uncompressed_sec1);
+ try testing.expectEqualSlices(u8, &pk_recovered2.toUncompressedSec1(), &pk_uncompressed_sec1);
+}
diff --git a/test/standalone.zig b/test/standalone.zig
@@ -52,7 +52,11 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
}
// Ensure the development tools are buildable.
- cases.add("tools/gen_spirv_spec.zig");
+
+ // Disabled due to tripping LLVM 13 assertion:
+ // https://github.com/ziglang/zig/issues/12015
+ //cases.add("tools/gen_spirv_spec.zig");
+
cases.add("tools/gen_stubs.zig");
cases.add("tools/generate_linux_syscalls.zig");
cases.add("tools/process_headers.zig");