Skip to content

Commit 60a17d1

Browse files
committed
Add support for P-521 curve
Sadly Deno doesn't support it. See: denoland/deno#13449 (comment)
1 parent 65704c7 commit 60a17d1

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

fixtures/p521.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sure, here is P-265 fixture ;)

fixtures/p521.txt.sig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-----BEGIN SSH SIGNATURE-----
2+
U1NIU0lHAAAAAQAAAKwAAAATZWNkc2Etc2hhMi1uaXN0cDUyMQAAAAhuaXN0cDUyMQAAAI
3+
UEABon2x0D7m1Dxnfxp9HhV3VddppTwwIpGxjj1u3ukoP/mEsH+LGMTu+ZMacofZpZRiGZ
4+
5TyghUKep6pErZjffhnwAaMUI1M9kgK/QJVDpqiwiaRjRD4QXzVjxRhIsGPx11bCrxiuHJ
5+
muoPPo8tibOuq8PHvYB9RIz3IZjy6BrV8w6cqlAAAABGZpbGUAAAAAAAAABnNoYTUxMgAA
6+
AKcAAAATZWNkc2Etc2hhMi1uaXN0cDUyMQAAAIwAAABCAd0AAb8B0I3EziNuDnVnRKNk4t
7+
3qtJqQ4w0fZhaguZ3LbSSwj4qAsIytsIdyD8MF04hm6lh+NzJa24Kt5uHSh7PbAAAAQgH+
8+
fCBwwS5/AWWrtEdrlxK5Tu2pVFLofJRoO5mDn80pHidM8IHQhecJmGY02e/G5dUpSoY/q3
9+
r6xnimpmfqKKrKUw==
10+
-----END SSH SIGNATURE-----

formats.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type Pubkey = {
1010
key: Uint8Array;
1111
toString(): string;
1212
} | {
13-
pk_algo: "ecdsa-sha2-nistp256" | "ecdsa-sha2-nistp384";
13+
pk_algo: "ecdsa-sha2-nistp256" | "ecdsa-sha2-nistp384" | "ecdsa-sha2-nistp521";
1414
curve: string;
1515
point: Uint8Array;
1616
toString(): string;
@@ -40,8 +40,7 @@ export function parsePubkey(
4040
},
4141
};
4242
} else if (
43-
pk_algo === "ecdsa-sha2-nistp256" || pk_algo === "ecdsa-sha2-nistp384"
44-
) {
43+
pk_algo === "ecdsa-sha2-nistp256" || pk_algo === "ecdsa-sha2-nistp384" || pk_algo === "ecdsa-sha2-nistp521" ) {
4544
const curve = publickey.readString().toString();
4645
pubkey = {
4746
pk_algo,
@@ -92,7 +91,7 @@ export function convertPublicKey(publickey: Pubkey): {
9291
};
9392
} else if (
9493
pk_algo === "ecdsa-sha2-nistp256" || pk_algo === "ecdsa-sha2-nistp384"
95-
) {
94+
|| pk_algo === "ecdsa-sha2-nistp521" ) {
9695
if (publickey.point[0] !== 0x04) {
9796
throw new Error("Only uncompressed (0x04) format is supported");
9897
}
@@ -102,8 +101,10 @@ export function convertPublicKey(publickey: Pubkey): {
102101
let crv;
103102
if (pk_algo === "ecdsa-sha2-nistp256") {
104103
crv = "P-256";
105-
} else {
104+
} else if (pk_algo === "ecdsa-sha2-nistp384") {
106105
crv = "P-384";
106+
} {
107+
crv = "P-521";
107108
}
108109
return {
109110
keyData: {
@@ -142,6 +143,12 @@ export function convertAlgorithm(sig_algo: string) {
142143
namedCurve: "P-384",
143144
hash: { name: "SHA-384" },
144145
};
146+
} else if (sig_algo === "ecdsa-sha2-nistp521") {
147+
return {
148+
name: "ECDSA",
149+
namedCurve: "P-521",
150+
hash: { name: "SHA-512" },
151+
};
145152
} else {
146153
throw new Error(`Unsupported algo: ${sig_algo}`);
147154
}

sig_parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function parse(signature: DataView | string): Sig {
3434
let bytes;
3535
if (
3636
sig_algo === "ecdsa-sha2-nistp256" || sig_algo === "ecdsa-sha2-nistp384"
37-
) {
37+
|| sig_algo === "ecdsa-sha2-nistp512" ) {
3838
let r = new Uint8Array(sig_bytes.readString().bytes());
3939
if (r[0] === 0x00 && r.length % 2 == 1) {
4040
r = r.slice(1);

0 commit comments

Comments
 (0)