remove material parameter for now
This commit is contained in:
parent
0de9eecdc8
commit
fade832619
|
@ -33,30 +33,6 @@ import BigInteger from '../jsbn.js';
|
||||||
import enums from '../../../enums.js';
|
import enums from '../../../enums.js';
|
||||||
import util from '../../../util.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 = {
|
const curves = {
|
||||||
p256: {
|
p256: {
|
||||||
oid: util.bin2str([0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07]),
|
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) {
|
function get(oid_or_name) {
|
||||||
for (var name in curves) {
|
for (var name in curves) {
|
||||||
if (curves[name].oid === oid_or_name || name === oid_or_name) {
|
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');
|
throw new Error('Not valid curve');
|
||||||
}
|
}
|
||||||
|
|
||||||
function generate(curve, material) {
|
function generate(curve) {
|
||||||
return new Promise(function (resolve) {
|
return new Promise(function (resolve) {
|
||||||
curve = get(curve);
|
curve = get(curve);
|
||||||
var keyPair;
|
var keyPair = curve.genKeyPair();
|
||||||
if (typeof(material) !== "undefined") {
|
|
||||||
keyPair = curve.keyFromPrivate(material);
|
|
||||||
} else {
|
|
||||||
keyPair = curve.genKeyPair();
|
|
||||||
}
|
|
||||||
resolve({
|
resolve({
|
||||||
oid: curve.oid,
|
oid: curve.oid,
|
||||||
R: new BigInteger(keyPair.getPublic()),
|
R: new BigInteger(keyPair.getPublic()),
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
/**
|
/**
|
||||||
* @requires crypto/hash
|
* @requires crypto/hash
|
||||||
* @requires crypto/cipher
|
* @requires crypto/cipher
|
||||||
* @requires crypto/rfc3394
|
* @requires crypto/aes_kw
|
||||||
* @requires crypto/public_key/elliptic/curves
|
* @requires crypto/public_key/elliptic/curves
|
||||||
* @requires crypto/public_key/jsbn
|
* @requires crypto/public_key/jsbn
|
||||||
* @requires type/oid
|
* @requires type/oid
|
||||||
|
@ -36,7 +36,7 @@ import BigInteger from '../jsbn.js';
|
||||||
import curves from './curves.js';
|
import curves from './curves.js';
|
||||||
import cipher from '../../cipher';
|
import cipher from '../../cipher';
|
||||||
import hash from '../../hash';
|
import hash from '../../hash';
|
||||||
import rfc3394 from '../../rfc3394.js';
|
import aes_kw from '../../aes_kw.js';
|
||||||
import enums from '../../../enums.js';
|
import enums from '../../../enums.js';
|
||||||
import util from '../../../util.js';
|
import util from '../../../util.js';
|
||||||
import type_kdf_params from '../../../type/kdf_params.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());
|
R = curve.keyFromPublic(R.toByteArray());
|
||||||
const S = v.derive(R);
|
const S = v.derive(R);
|
||||||
const Z = kdf(hash_algo, S, cipher[cipher_algo].keySize, param);
|
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 {
|
return {
|
||||||
V: new BigInteger(v.getPublic()),
|
V: new BigInteger(v.getPublic()),
|
||||||
C: C
|
C: C
|
||||||
|
@ -120,7 +120,7 @@ function decrypt(oid, cipher_algo, hash_algo, V, C, r, fingerprint) {
|
||||||
r = curve.keyFromPrivate(r.toByteArray());
|
r = curve.keyFromPrivate(r.toByteArray());
|
||||||
const S = r.derive(V);
|
const S = r.derive(V);
|
||||||
const Z = kdf(hash_algo, S, cipher[cipher_algo].keySize, param);
|
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 = {
|
module.exports = {
|
||||||
|
|
|
@ -273,10 +273,10 @@ SecretKey.prototype.decrypt = function (passphrase) {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
SecretKey.prototype.generate = function (bits, curve, material) {
|
SecretKey.prototype.generate = function (bits, curve) {
|
||||||
var self = this;
|
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.mpi = mpi;
|
||||||
self.isDecrypted = true;
|
self.isDecrypted = true;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user