minor. ecdh.
This commit is contained in:
parent
78d32ce3a2
commit
5973cad305
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user