Skip to content

Commit b164190

Browse files
committed
Internal: rename Curves to CurvesWithOID
Following the addition of the new format for Montgomery curves, which do not rely on OIDs.
1 parent ef953ce commit b164190

9 files changed

Lines changed: 36 additions & 36 deletions

File tree

src/crypto/crypto.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import KDFParams from '../type/kdf_params';
3333
import enums from '../enums';
3434
import util from '../util';
3535
import OID from '../type/oid';
36-
import { Curve } from './public_key/elliptic/curves';
36+
import { CurveWithOID } from './public_key/elliptic/oid_curves';
3737
import { UnsupportedError } from '../packet/packet';
3838
import ECDHXSymmetricKey from '../type/ecdh_x_symkey';
3939

@@ -219,14 +219,14 @@ export function parsePrivateKeyParams(algo, bytes, publicParams) {
219219
}
220220
case enums.publicKey.ecdsa:
221221
case enums.publicKey.ecdh: {
222-
const curve = new Curve(publicParams.oid);
222+
const curve = new CurveWithOID(publicParams.oid);
223223
let d = util.readMPI(bytes.subarray(read)); read += d.length + 2;
224224
d = util.leftPad(d, curve.payloadSize);
225225
return { read, privateParams: { d } };
226226
}
227227
case enums.publicKey.eddsa:
228228
case enums.publicKey.ed25519Legacy: {
229-
const curve = new Curve(publicParams.oid);
229+
const curve = new CurveWithOID(publicParams.oid);
230230
let seed = util.readMPI(bytes.subarray(read)); read += seed.length + 2;
231231
seed = util.leftPad(seed, curve.payloadSize);
232232
return { read, privateParams: { seed } };

src/crypto/public_key/elliptic/ecdh.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
import nacl from '@openpgp/tweetnacl/nacl-fast-light';
25-
import { Curve, jwkToRawPublic, rawPublicToJWK, privateToJWK, validateStandardParams } from './curves';
25+
import { CurveWithOID, jwkToRawPublic, rawPublicToJWK, privateToJWK, validateStandardParams } from './oid_curves';
2626
import * as aesKW from '../../aes_kw';
2727
import { getRandomBytes } from '../../random';
2828
import hash from '../../hash';
@@ -86,7 +86,7 @@ async function kdf(hashAlgo, X, length, param, stripLeading = false, stripTraili
8686
/**
8787
* Generate ECDHE ephemeral key and secret from public key
8888
*
89-
* @param {Curve} curve - Elliptic curve object
89+
* @param {CurveWithOID} curve - Elliptic curve object
9090
* @param {Uint8Array} Q - Recipient public key
9191
* @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
9292
* @async
@@ -129,7 +129,7 @@ async function genPublicEphemeralKey(curve, Q) {
129129
export async function encrypt(oid, kdfParams, data, Q, fingerprint) {
130130
const m = pkcs5.encode(data);
131131

132-
const curve = new Curve(oid);
132+
const curve = new CurveWithOID(oid);
133133
const { publicKey, sharedKey } = await genPublicEphemeralKey(curve, Q);
134134
const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
135135
const { keySize } = getCipher(kdfParams.cipher);
@@ -141,7 +141,7 @@ export async function encrypt(oid, kdfParams, data, Q, fingerprint) {
141141
/**
142142
* Generate ECDHE secret from private key and public part of ephemeral key
143143
*
144-
* @param {Curve} curve - Elliptic curve object
144+
* @param {CurveWithOID} curve - Elliptic curve object
145145
* @param {Uint8Array} V - Public part of ephemeral key
146146
* @param {Uint8Array} Q - Recipient public key
147147
* @param {Uint8Array} d - Recipient private key
@@ -189,7 +189,7 @@ async function genPrivateEphemeralKey(curve, V, Q, d) {
189189
* @async
190190
*/
191191
export async function decrypt(oid, kdfParams, V, C, Q, d, fingerprint) {
192-
const curve = new Curve(oid);
192+
const curve = new CurveWithOID(oid);
193193
const { sharedKey } = await genPrivateEphemeralKey(curve, V, Q, d);
194194
const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
195195
const { keySize } = getCipher(kdfParams.cipher);
@@ -209,7 +209,7 @@ export async function decrypt(oid, kdfParams, V, C, Q, d, fingerprint) {
209209
/**
210210
* Generate ECDHE secret from private key and public part of ephemeral key using webCrypto
211211
*
212-
* @param {Curve} curve - Elliptic curve object
212+
* @param {CurveWithOID} curve - Elliptic curve object
213213
* @param {Uint8Array} V - Public part of ephemeral key
214214
* @param {Uint8Array} Q - Recipient public key
215215
* @param {Uint8Array} d - Recipient private key
@@ -262,7 +262,7 @@ async function webPrivateEphemeralKey(curve, V, Q, d) {
262262
/**
263263
* Generate ECDHE ephemeral key and secret from public key using webCrypto
264264
*
265-
* @param {Curve} curve - Elliptic curve object
265+
* @param {CurveWithOID} curve - Elliptic curve object
266266
* @param {Uint8Array} Q - Recipient public key
267267
* @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
268268
* @async
@@ -310,7 +310,7 @@ async function webPublicEphemeralKey(curve, Q) {
310310
/**
311311
* Generate ECDHE secret from private key and public part of ephemeral key using indutny/elliptic
312312
*
313-
* @param {Curve} curve - Elliptic curve object
313+
* @param {CurveWithOID} curve - Elliptic curve object
314314
* @param {Uint8Array} V - Public part of ephemeral key
315315
* @param {Uint8Array} d - Recipient private key
316316
* @returns {Promise<{secretKey: Uint8Array, sharedKey: Uint8Array}>}
@@ -330,7 +330,7 @@ async function ellipticPrivateEphemeralKey(curve, V, d) {
330330
/**
331331
* Generate ECDHE ephemeral key and secret from public key using indutny/elliptic
332332
*
333-
* @param {Curve} curve - Elliptic curve object
333+
* @param {CurveWithOID} curve - Elliptic curve object
334334
* @param {Uint8Array} Q - Recipient public key
335335
* @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
336336
* @async
@@ -350,7 +350,7 @@ async function ellipticPublicEphemeralKey(curve, Q) {
350350
/**
351351
* Generate ECDHE secret from private key and public part of ephemeral key using nodeCrypto
352352
*
353-
* @param {Curve} curve - Elliptic curve object
353+
* @param {CurveWithOID} curve - Elliptic curve object
354354
* @param {Uint8Array} V - Public part of ephemeral key
355355
* @param {Uint8Array} d - Recipient private key
356356
* @returns {Promise<{secretKey: Uint8Array, sharedKey: Uint8Array}>}
@@ -367,7 +367,7 @@ async function nodePrivateEphemeralKey(curve, V, d) {
367367
/**
368368
* Generate ECDHE ephemeral key and secret from public key using nodeCrypto
369369
*
370-
* @param {Curve} curve - Elliptic curve object
370+
* @param {CurveWithOID} curve - Elliptic curve object
371371
* @param {Uint8Array} Q - Recipient public key
372372
* @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
373373
* @async

src/crypto/public_key/elliptic/ecdsa.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import enums from '../../../enums';
2525
import util from '../../../util';
2626
import { getRandomBytes } from '../../random';
2727
import hash from '../../hash';
28-
import { Curve, webCurves, privateToJWK, rawPublicToJWK, validateStandardParams } from './curves';
28+
import { CurveWithOID, webCurves, privateToJWK, rawPublicToJWK, validateStandardParams } from './oid_curves';
2929
import { getIndutnyCurve, keyFromPrivate, keyFromPublic } from './indutnyKey';
3030

3131
const webCrypto = util.getWebCrypto();
@@ -46,7 +46,7 @@ const nodeCrypto = util.getNodeCrypto();
4646
* @async
4747
*/
4848
export async function sign(oid, hashAlgo, message, publicKey, privateKey, hashed) {
49-
const curve = new Curve(oid);
49+
const curve = new CurveWithOID(oid);
5050
if (message && !util.isStream(message)) {
5151
const keyPair = { publicKey, privateKey };
5252
switch (curve.type) {
@@ -91,7 +91,7 @@ export async function sign(oid, hashAlgo, message, publicKey, privateKey, hashed
9191
* @async
9292
*/
9393
export async function verify(oid, hashAlgo, signature, message, publicKey, hashed) {
94-
const curve = new Curve(oid);
94+
const curve = new CurveWithOID(oid);
9595
if (message && !util.isStream(message)) {
9696
switch (curve.type) {
9797
case 'web':
@@ -125,7 +125,7 @@ export async function verify(oid, hashAlgo, signature, message, publicKey, hashe
125125
* @async
126126
*/
127127
export async function validateParams(oid, Q, d) {
128-
const curve = new Curve(oid);
128+
const curve = new CurveWithOID(oid);
129129
// Reject curves x25519 and ed25519
130130
if (curve.keyType !== enums.publicKey.ecdsa) {
131131
return false;

src/crypto/public_key/elliptic/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
* @private
2626
*/
2727

28-
import { Curve, generate, getPreferredHashAlgo } from './curves';
28+
import { CurveWithOID, generate, getPreferredHashAlgo } from './oid_curves';
2929
import * as ecdsa from './ecdsa';
3030
import * as eddsaLegacy from './eddsa_legacy';
3131
import * as eddsa from './eddsa';
3232
import * as ecdh from './ecdh';
3333
import * as ecdhX from './ecdh_x';
3434

3535
export {
36-
Curve, ecdh, ecdhX, ecdsa, eddsaLegacy, eddsa, generate, getPreferredHashAlgo
36+
CurveWithOID, ecdh, ecdhX, ecdsa, eddsaLegacy, eddsa, generate, getPreferredHashAlgo
3737
};

src/crypto/public_key/elliptic/curves.js renamed to src/crypto/public_key/elliptic/oid_curves.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const curves = {
131131
}
132132
};
133133

134-
class Curve {
134+
class CurveWithOID {
135135
constructor(oidOrName, params) {
136136
try {
137137
if (util.isArray(oidOrName) ||
@@ -208,7 +208,7 @@ class Curve {
208208
async function generate(curve) {
209209
const BigInteger = await util.getBigInteger();
210210

211-
curve = new Curve(curve);
211+
curve = new CurveWithOID(curve);
212212
const keyPair = await curve.genKeyPair();
213213
const Q = new BigInteger(keyPair.publicKey).toUint8Array();
214214
const secret = new BigInteger(keyPair.privateKey).toUint8Array('be', curve.payloadSize);
@@ -293,7 +293,7 @@ async function validateStandardParams(algo, oid, Q, d) {
293293
}
294294

295295
export {
296-
Curve, curves, webCurves, nodeCurves, generate, getPreferredHashAlgo, jwkToRawPublic, rawPublicToJWK, privateToJWK, validateStandardParams
296+
CurveWithOID, curves, webCurves, nodeCurves, generate, getPreferredHashAlgo, jwkToRawPublic, rawPublicToJWK, privateToJWK, validateStandardParams
297297
};
298298

299299
//////////////////////////

src/crypto/signature.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export async function verify(algo, hashAlgo, signature, publicParams, data, hash
9797
}
9898
case enums.publicKey.ecdsa: {
9999
const { oid, Q } = publicParams;
100-
const curveSize = new publicKey.elliptic.Curve(oid).payloadSize;
100+
const curveSize = new publicKey.elliptic.CurveWithOID(oid).payloadSize;
101101
// padding needed for webcrypto
102102
const r = util.leftPad(signature.r, curveSize);
103103
const s = util.leftPad(signature.s, curveSize);

test/crypto/ecdh.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = () => describe('ECDH key exchange @lightweight', function () {
2020
data = new Uint8Array(data);
2121
}
2222
return Promise.resolve().then(() => {
23-
const curve = new elliptic_curves.Curve(oid);
23+
const curve = new elliptic_curves.CurveWithOID(oid);
2424
return elliptic_curves.ecdh.decrypt(
2525
new OID(curve.oid),
2626
new KDFParams({ cipher, hash }),
@@ -138,7 +138,7 @@ module.exports = () => describe('ECDH key exchange @lightweight', function () {
138138
if (!openpgp.config.useIndutnyElliptic && !util.getNodeCrypto()) {
139139
this.skip();
140140
}
141-
const curve = new elliptic_curves.Curve('secp256k1');
141+
const curve = new elliptic_curves.CurveWithOID('secp256k1');
142142
const oid = new OID(curve.oid);
143143
const kdfParams = new KDFParams({ hash: curve.hash, cipher: curve.cipher });
144144
const data = util.stringToUint8Array('test');
@@ -148,7 +148,7 @@ module.exports = () => describe('ECDH key exchange @lightweight', function () {
148148
});
149149

150150
it('Different keys', async function () {
151-
const curve = new elliptic_curves.Curve('curve25519');
151+
const curve = new elliptic_curves.CurveWithOID('curve25519');
152152
const oid = new OID(curve.oid);
153153
const kdfParams = new KDFParams({ hash: curve.hash, cipher: curve.cipher });
154154
const data = util.stringToUint8Array('test');
@@ -159,7 +159,7 @@ module.exports = () => describe('ECDH key exchange @lightweight', function () {
159159
});
160160

161161
it('Invalid fingerprint', async function () {
162-
const curve = new elliptic_curves.Curve('curve25519');
162+
const curve = new elliptic_curves.CurveWithOID('curve25519');
163163
const oid = new OID(curve.oid);
164164
const kdfParams = new KDFParams({ hash: curve.hash, cipher: curve.cipher });
165165
const data = util.stringToUint8Array('test');
@@ -170,7 +170,7 @@ module.exports = () => describe('ECDH key exchange @lightweight', function () {
170170
});
171171

172172
it('Successful exchange x25519 (legacy)', async function () {
173-
const curve = new elliptic_curves.Curve('curve25519');
173+
const curve = new elliptic_curves.CurveWithOID('curve25519');
174174
const oid = new OID(curve.oid);
175175
const kdfParams = new KDFParams({ hash: curve.hash, cipher: curve.cipher });
176176
const data = util.stringToUint8Array('test');
@@ -190,7 +190,7 @@ module.exports = () => describe('ECDH key exchange @lightweight', function () {
190190

191191
['p256', 'p384', 'p521'].forEach(curveName => {
192192
it(`NIST ${curveName} - Successful exchange`, async function () {
193-
const curve = new elliptic_curves.Curve(curveName);
193+
const curve = new elliptic_curves.CurveWithOID(curveName);
194194
const oid = new OID(curve.oid);
195195
const kdfParams = new KDFParams({ hash: curve.hash, cipher: curve.cipher });
196196
const data = util.stringToUint8Array('test');
@@ -233,7 +233,7 @@ module.exports = () => describe('ECDH key exchange @lightweight', function () {
233233
this.skip();
234234
}
235235

236-
const curve = new elliptic_curves.Curve(curveName);
236+
const curve = new elliptic_curves.CurveWithOID(curveName);
237237
const oid = new OID(curve.oid);
238238
const kdfParams = new KDFParams({ hash: curve.hash, cipher: curve.cipher });
239239
const data = util.stringToUint8Array('test');

test/crypto/elliptic.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ module.exports = () => describe('Elliptic Curve Cryptography @lightweight', func
5959
describe('Basic Operations', function () {
6060
it('Creating curve from name or oid', function (done) {
6161
Object.keys(openpgp.enums.curve).forEach(function(name_or_oid) {
62-
expect(new elliptic_curves.Curve(name_or_oid)).to.exist;
62+
expect(new elliptic_curves.CurveWithOID(name_or_oid)).to.exist;
6363
});
6464
Object.values(openpgp.enums.curve).forEach(function(name_or_oid) {
65-
expect(new elliptic_curves.Curve(name_or_oid)).to.exist;
65+
expect(new elliptic_curves.CurveWithOID(name_or_oid)).to.exist;
6666
});
6767
done();
6868
});
@@ -73,7 +73,7 @@ module.exports = () => describe('Elliptic Curve Cryptography @lightweight', func
7373
const names = config.useIndutnyElliptic ? ['p256', 'p384', 'p521', 'secp256k1', 'curve25519', 'brainpoolP256r1', 'brainpoolP384r1', 'brainpoolP512r1'] :
7474
['p256', 'p384', 'p521', 'curve25519'];
7575
return Promise.all(names.map(function (name) {
76-
const curve = new elliptic_curves.Curve(name);
76+
const curve = new elliptic_curves.CurveWithOID(name);
7777
return curve.genKeyPair().then(keyPair => {
7878
expect(keyPair).to.exist;
7979
});
@@ -243,7 +243,7 @@ module.exports = () => describe('Elliptic Curve Cryptography @lightweight', func
243243
.to.eventually.be.true.notify(done);
244244
});
245245
it('Sign and verify message', function () {
246-
const curve = new elliptic_curves.Curve('p521');
246+
const curve = new elliptic_curves.CurveWithOID('p521');
247247
return curve.genKeyPair().then(async keyPair => {
248248
const keyPublic = new Uint8Array(keyPair.publicKey);
249249
const keyPrivate = new Uint8Array(keyPair.privateKey);

test/general/x25519.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr
218218
describe('Ed25519 Test Vectors from RFC8032', function () {
219219
// https://tools.ietf.org/html/rfc8032#section-7.1
220220
function testVector(vector) {
221-
const curve = new elliptic.Curve('ed25519');
221+
const curve = new elliptic.CurveWithOID('ed25519');
222222
const { publicKey } = nacl.sign.keyPair.fromSeed(util.hexToUint8Array(vector.SECRET_KEY));
223223
expect(publicKey).to.deep.equal(util.hexToUint8Array(vector.PUBLIC_KEY));
224224
const data = vector.MESSAGE;

0 commit comments

Comments
 (0)