From fade832619c988aea1c74614237930a912730969 Mon Sep 17 00:00:00 2001 From: Sanjana Rajan Date: Mon, 24 Jul 2017 18:38:26 +0200 Subject: [PATCH] remove material parameter for now --- src/crypto/public_key/elliptic/curves.js | 58 +++++++++++------------- src/crypto/public_key/elliptic/ecdh.js | 8 ++-- src/packet/secret_key.js | 4 +- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/crypto/public_key/elliptic/curves.js b/src/crypto/public_key/elliptic/curves.js index faabd656..7437ee11 100644 --- a/src/crypto/public_key/elliptic/curves.js +++ b/src/crypto/public_key/elliptic/curves.js @@ -33,30 +33,6 @@ import BigInteger from '../jsbn.js'; import enums from '../../../enums.js'; import util from '../../../util.js'; -function Curve(name, {oid, hash, cipher}) { - this.curve = new EC(name); - this.name = name; - this.oid = oid; - this.hash = hash; - this.cipher = cipher; -} - -Curve.prototype.keyFromPrivate = function (priv) { - return new KeyPair(this.curve, {priv: priv}); -}; - -Curve.prototype.keyFromPublic = function (pub) { - return new KeyPair(this.curve, {pub: pub}); -}; - -Curve.prototype.genKeyPair = function () { - var r = this.curve.genKeyPair(); - return new KeyPair(this.curve, { - pub: r.getPublic().encode(), - priv: r.getPrivate().toArray() - }); -}; - const curves = { p256: { oid: util.bin2str([0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07]), @@ -84,6 +60,31 @@ const curves = { } }; +function Curve(name, {oid, hash, cipher}) { + this.curve = new EC(name); + this.name = name; + this.oid = oid; + this.hash = hash; + this.cipher = cipher; +} + +Curve.prototype.keyFromPrivate = function (priv) { + return new KeyPair(this.curve, {priv: priv}); +}; + +Curve.prototype.keyFromPublic = function (pub) { + return new KeyPair(this.curve, {pub: pub}); +}; + +Curve.prototype.genKeyPair = function () { + var r = this.curve.genKeyPair(); + return new KeyPair(this.curve, { + pub: r.getPublic().encode(), + priv: r.getPrivate().toArray() + }); +}; + + function get(oid_or_name) { for (var name in curves) { if (curves[name].oid === oid_or_name || name === oid_or_name) { @@ -97,15 +98,10 @@ function get(oid_or_name) { throw new Error('Not valid curve'); } -function generate(curve, material) { +function generate(curve) { return new Promise(function (resolve) { curve = get(curve); - var keyPair; - if (typeof(material) !== "undefined") { - keyPair = curve.keyFromPrivate(material); - } else { - keyPair = curve.genKeyPair(); - } + var keyPair = curve.genKeyPair(); resolve({ oid: curve.oid, R: new BigInteger(keyPair.getPublic()), diff --git a/src/crypto/public_key/elliptic/ecdh.js b/src/crypto/public_key/elliptic/ecdh.js index fc28064d..76df6b79 100644 --- a/src/crypto/public_key/elliptic/ecdh.js +++ b/src/crypto/public_key/elliptic/ecdh.js @@ -20,7 +20,7 @@ /** * @requires crypto/hash * @requires crypto/cipher - * @requires crypto/rfc3394 + * @requires crypto/aes_kw * @requires crypto/public_key/elliptic/curves * @requires crypto/public_key/jsbn * @requires type/oid @@ -36,7 +36,7 @@ import BigInteger from '../jsbn.js'; import curves from './curves.js'; import cipher from '../../cipher'; import hash from '../../hash'; -import rfc3394 from '../../rfc3394.js'; +import aes_kw from '../../aes_kw.js'; import enums from '../../../enums.js'; import util from '../../../util.js'; import type_kdf_params from '../../../type/kdf_params.js'; @@ -92,7 +92,7 @@ function encrypt(oid, cipher_algo, hash_algo, m, R, fingerprint) { R = curve.keyFromPublic(R.toByteArray()); const S = v.derive(R); const Z = kdf(hash_algo, S, cipher[cipher_algo].keySize, param); - const C = rfc3394.wrap(Z, m); + const C = aes_kw.wrap(Z, m); return { V: new BigInteger(v.getPublic()), C: C @@ -120,7 +120,7 @@ function decrypt(oid, cipher_algo, hash_algo, V, C, r, fingerprint) { r = curve.keyFromPrivate(r.toByteArray()); const S = r.derive(V); const Z = kdf(hash_algo, S, cipher[cipher_algo].keySize, param); - return new BigInteger(rfc3394.unwrap(Z, C)); + return new BigInteger(aes_kw.unwrap(Z, C)); } module.exports = { diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js index ea1bd246..8e525e41 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -273,10 +273,10 @@ SecretKey.prototype.decrypt = function (passphrase) { return true; }; -SecretKey.prototype.generate = function (bits, curve, material) { +SecretKey.prototype.generate = function (bits, curve) { var self = this; - return crypto.generateMpi(self.algorithm, bits, curve, material).then(function(mpi) { + return crypto.generateMpi(self.algorithm, bits, curve).then(function(mpi) { self.mpi = mpi; self.isDecrypted = true; });