Skip to content

Commit

Permalink
ECDSA implementation (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
PlamenHristov authored May 21, 2023
1 parent 2993149 commit cdd9ed4
Show file tree
Hide file tree
Showing 8 changed files with 628 additions and 115 deletions.
2 changes: 1 addition & 1 deletion configs/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"strict": true,
"strict": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
Expand Down
236 changes: 171 additions & 65 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,177 @@
export enum EC_CURVE {
brainpoolP160r1 = "brainpoolP160r1",
brainpoolP192r1 = "brainpoolP192r1",
brainpoolP224r1 = "brainpoolP224r1",
brainpoolP256r1 = "brainpoolP256r1",
brainpoolP320r1 = "brainpoolP320r1",
brainpoolP384r1 = "brainpoolP384r1",
brainpoolP512r1 = "brainpoolP512r1",
prime192v1 = "prime192v1",
prime192v2 = "prime192v2",
prime192v3 = "prime192v3",
prime239v1 = "prime239v1",
prime239v2 = "prime239v2",
prime239v3 = "prime239v3",
prime256v1 = "prime256v1",
secp112r1 = "secp112r1",
secp112r2 = "secp112r2",
secp128r1 = "secp128r1",
secp128r2 = "secp128r2",
secp160k1 = "secp160k1",
secp160r1 = "secp160r1",
secp160r2 = "secp160r2",
secp192k1 = "secp192k1",
secp224k1 = "secp224k1",
secp224r1 = "secp224r1",
secp256k1 = "secp256k1",
secp384r1 = "secp384r1",
secp521r1 = "secp521r1",
}

export const EC_CURVE_TO_DER_MARKER: Record<EC_CURVE, string> = {
[EC_CURVE.brainpoolP160r1]: "06092B2403030208010101",
[EC_CURVE.brainpoolP192r1]: "06092B2403030208010103",
[EC_CURVE.brainpoolP224r1]: "06092B2403030208010105",
[EC_CURVE.brainpoolP256r1]: "06092B2403030208010107",
[EC_CURVE.brainpoolP320r1]: "06092B2403030208010109",
[EC_CURVE.brainpoolP384r1]: "06092B240303020801010B",
[EC_CURVE.brainpoolP512r1]: "06092B240303020801010D",
[EC_CURVE.prime192v1]: "06082A8648CE3D030101",
[EC_CURVE.prime192v2]: "06082A8648CE3D030102",
[EC_CURVE.prime192v3]: "06082A8648CE3D030103",
[EC_CURVE.prime239v1]: "06082A8648CE3D030104",
[EC_CURVE.prime239v2]: "06082A8648CE3D030105",
[EC_CURVE.prime239v3]: "06082A8648CE3D030106",
[EC_CURVE.prime256v1]: "06082A8648CE3D030107",
[EC_CURVE.secp112r1]: "06052B81040006",
[EC_CURVE.secp112r2]: "06052B81040007",
[EC_CURVE.secp128r1]: "06052B8104001C",
[EC_CURVE.secp128r2]: "06052B8104001D",
[EC_CURVE.secp160k1]: "06052B81040009",
[EC_CURVE.secp160r1]: "06052B8104001E",
[EC_CURVE.secp160r2]: "06052B81040021",
[EC_CURVE.secp192k1]: "06052B8104001F",
[EC_CURVE.secp224k1]: "06052B81040020",
[EC_CURVE.secp224r1]: "06052B81040021",
[EC_CURVE.secp256k1]: "06052B8104000A",
[EC_CURVE.secp384r1]: "06052B81040022",
[EC_CURVE.secp521r1]: "06052B81040023",
export const BYTE_LENGTH_IN_HEX = 2
export enum Key {
publicKey = "publicKey",
privateKey = "privateKey",
}

export enum ED_CURVE {
ed25519 = "ed25519",
ed488 = "ed488",
ed25519 = "ed25519",
ed488 = "ed488",
}

export const Curve = {... ED_CURVE, ...EC_CURVE}
export enum EC_CURVE {
SM2 = "SM2",
brainpoolP160r1 = "brainpoolP160r1",
brainpoolP160t1 = "brainpoolP160t1",
brainpoolP192r1 = "brainpoolP192r1",
brainpoolP192t1 = "brainpoolP192t1",
brainpoolP224r1 = "brainpoolP224r1",
brainpoolP224t1 = "brainpoolP224t1",
brainpoolP256r1 = "brainpoolP256r1",
brainpoolP256t1 = "brainpoolP256t1",
brainpoolP320r1 = "brainpoolP320r1",
brainpoolP320t1 = "brainpoolP320t1",
brainpoolP384r1 = "brainpoolP384r1",
brainpoolP384t1 = "brainpoolP384t1",
brainpoolP512r1 = "brainpoolP512r1",
brainpoolP512t1 = "brainpoolP512t1",
c2pnb163v1 = "c2pnb163v1",
c2pnb163v2 = "c2pnb163v2",
c2pnb163v3 = "c2pnb163v3",
c2pnb176v1 = "c2pnb176v1",
c2pnb208w1 = "c2pnb208w1",
c2pnb272w1 = "c2pnb272w1",
c2pnb304w1 = "c2pnb304w1",
c2pnb368w1 = "c2pnb368w1",
c2tnb191v1 = "c2tnb191v1",
c2tnb191v2 = "c2tnb191v2",
c2tnb191v3 = "c2tnb191v3",
c2tnb239v1 = "c2tnb239v1",
c2tnb239v2 = "c2tnb239v2",
c2tnb239v3 = "c2tnb239v3",
c2tnb359v1 = "c2tnb359v1",
c2tnb431r1 = "c2tnb431r1",
prime192v1 = "prime192v1",
prime192v2 = "prime192v2",
prime192v3 = "prime192v3",
prime239v1 = "prime239v1",
prime239v2 = "prime239v2",
prime239v3 = "prime239v3",
prime256v1 = "prime256v1",
secp112r1 = "secp112r1",
secp112r2 = "secp112r2",
secp128r1 = "secp128r1",
secp128r2 = "secp128r2",
secp160k1 = "secp160k1",
secp160r1 = "secp160r1",
secp160r2 = "secp160r2",
secp192k1 = "secp192k1",
secp224k1 = "secp224k1",
secp224r1 = "secp224r1",
secp256k1 = "secp256k1",
secp384r1 = "secp384r1",
secp521r1 = "secp521r1",
sect113r1 = "sect113r1",
sect113r2 = "sect113r2",
sect131r1 = "sect131r1",
sect131r2 = "sect131r2",
sect163k1 = "sect163k1",
sect163r1 = "sect163r1",
sect163r2 = "sect163r2",
sect193r1 = "sect193r1",
sect193r2 = "sect193r2",
sect233k1 = "sect233k1",
sect233r1 = "sect233r1",
sect239k1 = "sect239k1",
sect283k1 = "sect283k1",
sect283r1 = "sect283r1",
sect409k1 = "sect409k1",
sect409r1 = "sect409r1",
sect571k1 = "sect571k1",
sect571r1 = "sect571r1",
wap_wsg_idm_ecid_wtls1 = "wap-wsg-idm-ecid-wtls1",
wap_wsg_idm_ecid_wtls10 = "wap-wsg-idm-ecid-wtls10",
wap_wsg_idm_ecid_wtls11 = "wap-wsg-idm-ecid-wtls11",
wap_wsg_idm_ecid_wtls12 = "wap-wsg-idm-ecid-wtls12",
wap_wsg_idm_ecid_wtls3 = "wap-wsg-idm-ecid-wtls3",
wap_wsg_idm_ecid_wtls4 = "wap-wsg-idm-ecid-wtls4",
wap_wsg_idm_ecid_wtls5 = "wap-wsg-idm-ecid-wtls5",
wap_wsg_idm_ecid_wtls6 = "wap-wsg-idm-ecid-wtls6",
wap_wsg_idm_ecid_wtls7 = "wap-wsg-idm-ecid-wtls7",
wap_wsg_idm_ecid_wtls8 = "wap-wsg-idm-ecid-wtls8",
wap_wsg_idm_ecid_wtls9 = "wap-wsg-idm-ecid-wtls9",
}

export enum Key {
publicKey = "publicKey",
privateKey = "privateKey",
export const EC_CURVE_TO_OID: Record<EC_CURVE, string> = {
[EC_CURVE.SM2]: "06082a811ccf5501822d",
[EC_CURVE.brainpoolP160r1]: "06092b2403030208010101",
[EC_CURVE.brainpoolP160t1]: "06092b2403030208010102",
[EC_CURVE.brainpoolP192r1]: "06092b2403030208010103",
[EC_CURVE.brainpoolP192t1]: "06092b2403030208010104",
[EC_CURVE.brainpoolP224r1]: "06092b2403030208010105",
[EC_CURVE.brainpoolP224t1]: "06092b2403030208010106",
[EC_CURVE.brainpoolP256r1]: "06092b2403030208010107",
[EC_CURVE.brainpoolP256t1]: "06092b2403030208010108",
[EC_CURVE.brainpoolP320r1]: "06092b2403030208010109",
[EC_CURVE.brainpoolP320t1]: "06092b240303020801010a",
[EC_CURVE.brainpoolP384r1]: "06092b240303020801010b",
[EC_CURVE.brainpoolP384t1]: "06092b240303020801010c",
[EC_CURVE.brainpoolP512r1]: "06092b240303020801010d",
[EC_CURVE.brainpoolP512t1]: "06092b240303020801010e",
[EC_CURVE.c2pnb163v1]: "06082a8648ce3d030001",
[EC_CURVE.c2pnb163v2]: "06082a8648ce3d030002",
[EC_CURVE.c2pnb163v3]: "06082a8648ce3d030003",
[EC_CURVE.c2pnb176v1]: "06082a8648ce3d030004",
[EC_CURVE.c2pnb208w1]: "06082a8648ce3d03000a",
[EC_CURVE.c2pnb272w1]: "06082a8648ce3d030010",
[EC_CURVE.c2pnb304w1]: "06082a8648ce3d030011",
[EC_CURVE.c2pnb368w1]: "06082a8648ce3d030013",
[EC_CURVE.c2tnb191v1]: "06082a8648ce3d030005",
[EC_CURVE.c2tnb191v2]: "06082a8648ce3d030006",
[EC_CURVE.c2tnb191v3]: "06082a8648ce3d030007",
[EC_CURVE.c2tnb239v1]: "06082a8648ce3d03000b",
[EC_CURVE.c2tnb239v2]: "06082a8648ce3d03000c",
[EC_CURVE.c2tnb239v3]: "06082a8648ce3d03000d",
[EC_CURVE.c2tnb359v1]: "06082a8648ce3d030012",
[EC_CURVE.c2tnb431r1]: "06082a8648ce3d030014",
[EC_CURVE.prime192v1]: "06082a8648ce3d030101",
[EC_CURVE.prime192v2]: "06082a8648ce3d030102",
[EC_CURVE.prime192v3]: "06082a8648ce3d030103",
[EC_CURVE.prime239v1]: "06082a8648ce3d030104",
[EC_CURVE.prime239v2]: "06082a8648ce3d030105",
[EC_CURVE.prime239v3]: "06082a8648ce3d030106",
[EC_CURVE.prime256v1]: "06082a8648ce3d030107",
[EC_CURVE.secp112r1]: "06052b81040006",
[EC_CURVE.secp112r2]: "06052b81040007",
[EC_CURVE.secp128r1]: "06052b8104001c",
[EC_CURVE.secp128r2]: "06052b8104001d",
[EC_CURVE.secp160k1]: "06052b81040009",
[EC_CURVE.secp160r1]: "06052b81040008",
[EC_CURVE.secp160r2]: "06052b8104001e",
[EC_CURVE.secp192k1]: "06052b8104001f",
[EC_CURVE.secp224k1]: "06052b81040020",
[EC_CURVE.secp224r1]: "06052b81040021",
[EC_CURVE.secp256k1]: "06052b8104000a",
[EC_CURVE.secp384r1]: "06052b81040022",
[EC_CURVE.secp521r1]: "06052b81040023",
[EC_CURVE.sect113r1]: "06052b81040004",
[EC_CURVE.sect113r2]: "06052b81040005",
[EC_CURVE.sect131r1]: "06052b81040016",
[EC_CURVE.sect131r2]: "06052b81040017",
[EC_CURVE.sect163k1]: "06052b81040001",
[EC_CURVE.sect163r1]: "06052b81040002",
[EC_CURVE.sect163r2]: "06052b8104000f",
[EC_CURVE.sect193r1]: "06052b81040018",
[EC_CURVE.sect193r2]: "06052b81040019",
[EC_CURVE.sect233k1]: "06052b8104001a",
[EC_CURVE.sect233r1]: "06052b8104001b",
[EC_CURVE.sect239k1]: "06052b81040003",
[EC_CURVE.sect283k1]: "06052b81040010",
[EC_CURVE.sect283r1]: "06052b81040011",
[EC_CURVE.sect409k1]: "06052b81040024",
[EC_CURVE.sect409r1]: "06052b81040025",
[EC_CURVE.sect571k1]: "06052b81040026",
[EC_CURVE.sect571r1]: "06052b81040027",
[EC_CURVE.wap_wsg_idm_ecid_wtls1]: "0605672b010401",
[EC_CURVE.wap_wsg_idm_ecid_wtls10]: "0605672b01040a",
[EC_CURVE.wap_wsg_idm_ecid_wtls11]: "0605672b01040b",
[EC_CURVE.wap_wsg_idm_ecid_wtls12]: "0605672b01040c",
[EC_CURVE.wap_wsg_idm_ecid_wtls3]: "0605672b010403",
[EC_CURVE.wap_wsg_idm_ecid_wtls4]: "0605672b010404",
[EC_CURVE.wap_wsg_idm_ecid_wtls5]: "0605672b010405",
[EC_CURVE.wap_wsg_idm_ecid_wtls6]: "0605672b010406",
[EC_CURVE.wap_wsg_idm_ecid_wtls7]: "0605672b010407",
[EC_CURVE.wap_wsg_idm_ecid_wtls8]: "0605672b010408",
[EC_CURVE.wap_wsg_idm_ecid_wtls9]: "0605672b010409"
}

export const ED_CURVE_TO_DER_MARKER: Record<ED_CURVE, Record<Key, string>> = {
Expand All @@ -80,3 +184,5 @@ export const ED_CURVE_TO_DER_MARKER: Record<ED_CURVE, Record<Key, string>> = {
[Key.publicKey]: "3042300506032b6571033b00",
},
}

export const Curve = {...ED_CURVE, ...EC_CURVE}
Loading

0 comments on commit cdd9ed4

Please sign in to comment.