Skip to content

Commit fa40bdd

Browse files
committed
Merge remote-tracking branch 'origin/master' into llvm14
2 parents 38e3063 + aab1284 commit fa40bdd

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/std/crypto/ecdsa.zig

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
747+
test "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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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");

0 commit comments

Comments
 (0)