| ... | ... | @@ -62,13 +62,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /// 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(); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /// 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(); |
| 72 | 72 | } |
| 73 | 73 | }; |
| 74 | 74 | |
| ... | ... | @@ -743,3 +743,15 @@ fn tvTry(vector: TestVector) !void { |
| 743 | 743 | const sig = try Scheme.Signature.fromDer(sig_der); |
| 744 | 744 | try sig.verify(msg, pk); |
| 745 | 745 | } |
| 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 | } |