Skip to content

Commit

Permalink
Add curve secp256K1
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Mar 1, 2024
1 parent d080e4f commit 9f91786
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ This specification is available in *doc* directory and at <https://g10code.com/p
The application supports:

- RSA with key up to 3072 bits
- ECDSA with secp256k1
- ECDSA with secp256R1 and secp256K1
- EDDSA with Ed25519 curve
- ECDH with secp256k1 and curve25519 curves
- ECDH with secp256R1, secp256K1 and curve25519 curves

## Installation and Usage

Expand Down
Binary file modified doc/user/app-openpgp.pdf
Binary file not shown.
5 changes: 3 additions & 2 deletions doc/user/app-openpgp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ This specification is available in doc directory at [G10CODE]_.
The application supports:

- RSA with key up to 3072 bits
- ECDSA with secp256R1
- ECDSA with secp256R1 and secp256K1
- EDDSA with Ed25519 curve
- ECDH with secp256R1 and curve25519 curves
- ECDH with secp256R1, secp256K1 and curve25519 curves

This release has known missing parts (see also [GPGADD]_):

Expand Down Expand Up @@ -290,6 +290,7 @@ This 3 commands fix, in that order, the template for Signature, Decryption, Auth
Supported curve name are:

- secp256k1 with tag 19
- secp256r1 with tag 19
- nistp256 with tag 19
- cv25519 (only for key 2)
- ed25519 with tag 22 (only for key 1 and 3)
Expand Down
37 changes: 15 additions & 22 deletions src/gpg_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ const unsigned char C_OID_SECP384R1[5] = {
const unsigned char C_OID_SECP521R1[5] = {
0x2B, 0x81, 0x04, 0x00, 0x23
};
//secp256k1: 1.3.132.0.10
const unsigned char C_OID_SECP256K1[5] = {
0x2B, 0x81, 0x04, 0x00, 0x0A
};
*/
// secp256k1: 1.3.132.0.10
const unsigned char C_OID_SECP256K1[5] = {0x2B, 0x81, 0x04, 0x00, 0x0A};

/*
//brainpool 256t1: 1.3.36.3.3.2.8.1.1.8
Expand Down Expand Up @@ -97,20 +94,23 @@ unsigned int gpg_oid2curve(unsigned char *oid, unsigned int len) {
if ((len == sizeof(C_OID_SECP256R1)) && (memcmp(oid, C_OID_SECP256R1, len) == 0)) {
return CX_CURVE_SECP256R1;
}
/*
if ( (len == sizeof(C_OID_SECP256K1)) && (memcmp(oid, C_OID_SECP256K1, len)==0) ) {
return CX_CURVE_SECP256K1;
}

if ((len == sizeof(C_OID_SECP256K1)) && (memcmp(oid, C_OID_SECP256K1, len) == 0)) {
return CX_CURVE_SECP256K1;
}
/*
if ( (len == sizeof(C_OID_SECP384R1)) && (memcmp(oid, C_OID_SECP384R1, len)==0) ) {
return CX_CURVE_SECP384R1;
}
if ( (len == sizeof(C_OID_SECP521R1)) && (memcmp(oid, C_OID_SECP521R1, len)==0) ) {
return CX_CURVE_SECP521R1;
}
*/
*/

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

/*
if ( (len == sizeof(C_OID_BRAINPOOL256T1)) && (memcmp(oid, C_OID_BRAINPOOL256T1, len)==0) ) {
return CX_CURVE_BrainPoolP256T1;
}
if ( (len == sizeof(C_OID_BRAINPOOL256R1)) && (memcmp(oid, C_OID_BRAINPOOL256R1, len)==0) ) {
return CX_CURVE_BrainPoolP256R1;
}
Expand All @@ -120,7 +120,7 @@ unsigned int gpg_oid2curve(unsigned char *oid, unsigned int len) {
if ( (len == sizeof(C_OID_BRAINPOOL512R1)) && (memcmp(oid, C_OID_BRAINPOOL512R1, len)==0) ) {
return CX_CURVE_BrainPoolP512R1;
}
*/
*/
if ((len == sizeof(C_OID_Ed25519)) && (memcmp(oid, C_OID_Ed25519, len) == 0)) {
return CX_CURVE_Ed25519;
}
Expand All @@ -129,14 +129,6 @@ unsigned int gpg_oid2curve(unsigned char *oid, unsigned int len) {
return CX_CURVE_Curve25519;
}

/*
if ( (len == sizeof(C_OID_SECP256K1)) && (memcmp(oid, C_OID_SECP256K1, len)==0) ) {
return CX_CURVE_256K1;
}
if ( (len == sizeof(C_OID_BRAINPOOL256T1)) && (memcmp(oid, C_OID_BRAINPOOL256T1, len)==0) ) {
return CX_CURVE_BrainPoolP256T1;
}
*/
return CX_CURVE_NONE;
}

Expand All @@ -146,11 +138,11 @@ unsigned char *gpg_curve2oid(unsigned int cv, unsigned int *len) {
*len = sizeof(C_OID_SECP256R1);
return (unsigned char *) PIC(C_OID_SECP256R1);

/*
case CX_CURVE_SECP256K1:
*len = sizeof(C_OID_SECP256K1);
return (unsigned char*)PIC(C_OID_SECP256K1);
*len = sizeof(C_OID_SECP256K1);
return (unsigned char *) PIC(C_OID_SECP256K1);

/*
case CX_CURVE_SECP384R1:
*len = sizeof(C_OID_SECP384R1);
return (unsigned char*)PIC(C_OID_SECP384R1);
Expand Down Expand Up @@ -188,6 +180,7 @@ unsigned char *gpg_curve2oid(unsigned int cv, unsigned int *len) {

unsigned int gpg_curve2domainlen(unsigned int cv) {
switch (cv) {
case CX_CURVE_SECP256K1:
case CX_CURVE_SECP256R1:
case CX_CURVE_Ed25519:
case CX_CURVE_Curve25519:
Expand Down

0 comments on commit 9f91786

Please sign in to comment.