minor. ecdh.

This commit is contained in:
Christopher Jeffrey 2016-06-27 01:06:58 -07:00
parent 78d32ce3a2
commit 5973cad305
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 23 additions and 0 deletions

View File

@ -110,6 +110,8 @@ ChaCha20.prototype.encrypt = function encrypt(data) {
data[i] ^= this.bytes[this.pos++];
}
return data;
};
/**
@ -529,6 +531,8 @@ AEAD.prototype.encrypt = function encrypt(data) {
this.chacha20.encrypt(data);
this.poly1305.update(data);
this.cipherLen += data.length;
return data;
};
/**
@ -543,6 +547,8 @@ AEAD.prototype.decrypt = function decrypt(data) {
this.cipherLen += data.length;
this.poly1305.update(data);
this.chacha20.encrypt(data);
return data;
};
/**

View File

@ -86,6 +86,23 @@ ec.publicKeyCreate = function publicKeyCreate(priv, compressed) {
return new Buffer(priv);
};
/**
* Create an ecdh.
* @param {Buffer} pub
* @param {Buffer} priv
* @returns {Buffer}
*/
ec.ecdh = function ecdh(pub, priv) {
if (secp256k1)
return secp256k1.ecdh(pub, priv);
priv = ec.elliptic.keyPair({ priv: priv });
pub = ec.elliptic.keyPair({ pub: pub });
return priv.derive(pub.getPublic()).toArrayLike(Buffer, 'be', 32);
};
/**
* Generate some random bytes.
* @param {Number} size