Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
Add BrainpoolP256r1, 384r1 and 512r1
Browse files Browse the repository at this point in the history
Needed for OpenPGP
  • Loading branch information
larabr committed Oct 12, 2023
1 parent 1c81291 commit 1dda7a5
Show file tree
Hide file tree
Showing 18 changed files with 69,994 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# noble-curves

> This fork adds support for legacy browsers without BigInt (e.g. Safari 13 or less), and only includes hash algorithms needed by openpgpjs: Curve25519, Curve448, NIST curves and Secp256k1.<br>
> This fork adds support for legacy browsers without BigInt (e.g. Safari 13 or less), and only includes hash algorithms needed by openpgpjs: Curve25519, Curve448, NIST curves and Secp256k1. It also adds some Brainpool curves.<br>
We recommend you use the upstream repo. The rest of the README refers to the upstream library.

<hr>
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
"sideEffects": false,
"main": "index.js",
"exports": {
"./abstract/utils": {
"import": "./esm/abstract/utils.js"
},
"./_shortw_utils": {
"import": "./esm/_shortw_utils.js"
},
"./ed25519": {
"import": "./esm/ed25519.js"
},
Expand All @@ -77,6 +71,15 @@
},
"./secp256k1": {
"import": "./esm/secp256k1.js"
},
"./brainpoolP256r1": {
"import": "./esm/brainpoolP256r1.js"
},
"./brainpoolP384r1": {
"import": "./esm/brainpoolP384r1.js"
},
"./brainpoolP512r1": {
"import": "./esm/brainpoolP512r1.js"
}
},
"keywords": [
Expand Down
24 changes: 24 additions & 0 deletions src/brainpoolP256r1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createCurve } from './_shortw_utils.js';
import { sha256 } from '@openpgp/noble-hashes/sha256';
import { Field } from './abstract/modular.js';
import { BigInteger } from '@openpgp/noble-hashes/biginteger';

// brainpoolP256r1: https://datatracker.ietf.org/doc/html/rfc5639#section-3.4

const Fp = Field(BigInteger.new('0xa9fb57dba1eea9bc3e660a909d838d726e3bf623d52620282013481d1f6e5377'));
const CURVE_A = Fp.create(BigInteger.new('0x7d5a0975fc2c3057eef67530417affe7fb8055c126dc5c6ce94a4b44f330b5d9'));
const CURVE_B = BigInteger.new('0x26dc5c6ce94a4b44f330b5d9bbd77cbf958416295cf7e1ce6bccdc18ff8c07b6');

// prettier-ignore
export const brainpoolP256r1 = createCurve({
a: CURVE_A, // Equation params: a, b
b: CURVE_B,
Fp,
// Curve order (q), total count of valid points in the field
n: BigInteger.new('0xa9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7'),
// Base (generator) point (x, y)
Gx: BigInteger.new('0x8bd2aeb9cb7e57cb2c4b482ffc81b7afb9de27e1e3bd23c23a4453bd9ace3262'),
Gy: BigInteger.new('0x547ef835c3dac4fd97f8461a14611dc9c27745132ded8e545c1d54c72f046997'),
h: BigInteger.new(1),
lowS: false,
} as const, sha256);
24 changes: 24 additions & 0 deletions src/brainpoolP384r1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createCurve } from './_shortw_utils.js';
import { sha384 } from '@openpgp/noble-hashes/sha512';
import { Field } from './abstract/modular.js';
import { BigInteger } from '@openpgp/noble-hashes/biginteger';

// brainpoolP384 r1: https://datatracker.ietf.org/doc/html/rfc5639#section-3.6

const Fp = Field(BigInteger.new('0x8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b412b1da197fb71123acd3a729901d1a71874700133107ec53'));
const CURVE_A = Fp.create(BigInteger.new('0x7bc382c63d8c150c3c72080ace05afa0c2bea28e4fb22787139165efba91f90f8aa5814a503ad4eb04a8c7dd22ce2826'));
const CURVE_B = BigInteger.new('0x04a8c7dd22ce28268b39b55416f0447c2fb77de107dcd2a62e880ea53eeb62d57cb4390295dbc9943ab78696fa504c11');

// prettier-ignore
export const brainpoolP384r1 = createCurve({
a: CURVE_A, // Equation params: a, b
b: CURVE_B,
Fp,
// Curve order (q), total count of valid points in the field
n: BigInteger.new('0x8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565'),
// Base (generator) point (x, y)
Gx: BigInteger.new('0x1d1c64f068cf45ffa2a63a81b7c13f6b8847a3e77ef14fe3db7fcafe0cbd10e8e826e03436d646aaef87b2e247d4af1e'),
Gy: BigInteger.new('0x8abe1d7520f9c2a45cb1eb8e95cfd55262b70b29feec5864e19c054ff99129280e4646217791811142820341263c5315'),
h: BigInteger.new(1),
lowS: false,
} as const, sha384);
24 changes: 24 additions & 0 deletions src/brainpoolP512r1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createCurve } from './_shortw_utils.js';
import { sha512 } from '@openpgp/noble-hashes/sha512';
import { Field } from './abstract/modular.js';
import { BigInteger } from '@openpgp/noble-hashes/biginteger';

// brainpoolP512r1: https://datatracker.ietf.org/doc/html/rfc5639#section-3.7

const Fp = Field(BigInteger.new('0xaadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca703308717d4d9b009bc66842aecda12ae6a380e62881ff2f2d82c68528aa6056583a48f3'));
const CURVE_A = Fp.create(BigInteger.new('0x7830a3318b603b89e2327145ac234cc594cbdd8d3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94ca'));
const CURVE_B = BigInteger.new('0x3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94cadc083e67984050b75ebae5dd2809bd638016f723');

// prettier-ignore
export const brainpoolP512r1 = createCurve({
a: CURVE_A, // Equation params: a, b
b: CURVE_B,
Fp,
// Curve order (q), total count of valid points in the field
n: BigInteger.new('0xaadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca70330870553e5c414ca92619418661197fac10471db1d381085ddaddb58796829ca90069'),
// Base (generator) point (x, y)
Gx: BigInteger.new('0x81aee4bdd82ed9645a21322e9c4c6a9385ed9f70b5d916c1b43b62eef4d0098eff3b1f78e2d0d48d50d1687b93b97d5f7c6d5047406a5e688b352209bcb9f822'),
Gy: BigInteger.new('0x7dde385d566332ecc0eabfa9cf7822fdf209f70024a57b1aa000c55b881f8111b2dcde494a5f485e5bca4bd88a2763aed1ca2b2fa8f0540678cd1e0f3ad80892'),
h: BigInteger.new(1),
lowS: false,
} as const, sha512);
8 changes: 8 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { secp521r1 } from '../esm/p521.js';
import { secp256k1 } from '../esm/secp256k1.js';
import { ed25519, ed25519ctx, ed25519ph, x25519 } from '../esm/ed25519.js';
import { ed448, ed448ph } from '../esm/ed448.js';
import { brainpoolP256r1 } from '../esm/brainpoolP256r1.js';
import { brainpoolP384r1 } from '../esm/brainpoolP384r1.js';
import { brainpoolP512r1 } from '../esm/brainpoolP512r1.js';
// import { pallas, vesta } from '../esm/pasta.js';
// import { bn254 } from '../esm/bn254.js';
// import { jubjub } from '../esm/jubjub.js';
Expand Down Expand Up @@ -50,6 +53,10 @@ const FIELDS = {
// jubjub: { Fp: [jubjub.CURVE.Fp] },
ed25519: { Fp: [ed25519.CURVE.Fp] },
ed448: { Fp: [ed448.CURVE.Fp] },
brainpoolP256r1: { Fp: [ brainpoolP256r1.CURVE.Fp ]},
brainpoolP384r1: { Fp: [ brainpoolP384r1.CURVE.Fp ]},
brainpoolP512r1: { Fp: [ brainpoolP512r1.CURVE.Fp ]}

// bn254: { Fp: [bn254.CURVE.Fp] },
// pallas: { Fp: [pallas.CURVE.Fp] },
// vesta: { Fp: [vesta.CURVE.Fp] },
Expand Down Expand Up @@ -336,6 +343,7 @@ const CURVES = {
secp256k1,
ed25519, ed25519ctx, ed25519ph,
ed448, ed448ph,
brainpoolP256r1, brainpoolP384r1, brainpoolP512r1
// pallas, vesta,
// bn254,
// jubjub,
Expand Down
Loading

0 comments on commit 1dda7a5

Please sign in to comment.