remove material parameter for now

This commit is contained in:
Sanjana Rajan 2017-07-24 18:38:26 +02:00
parent 0de9eecdc8
commit fade832619
3 changed files with 33 additions and 37 deletions

View File

@ -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()),

View File

@ -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 = {

View File

@ -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;
});