diff --git a/crypto_box.js b/crypto_box.js index 134c1b6..12a9e44 100644 --- a/crypto_box.js +++ b/crypto_box.js @@ -1,3 +1,6 @@ +const { crypto_hash_sha512 } = require('./crypto_hash') +const { memzero } = require('./') + module.exports = { crypto_box_keypair, crypto_box_seal, @@ -19,6 +22,19 @@ function crypto_box_keypair(pk, sk) { return crypto_scalarmult_base(pk, sk) } +function crypto_box_seed_keypair(pk, sk, seed) { + check(pk, crypto_box_PUBLICKEYBYTES) + check(sk, crypto_box_SECRETKEYBYTES) + check(sk, crypto_box_SEEDBYTES) + + const hash = Buffer.alloc(64) + crypto_hash_sha512(hash, seed, 32) + sk.set(hash, 0, 0, 32) + memzero(hash) + + return crypto_scalarmult_base(pk, sk) +} + function crypto_box_seal(c, m, pk) { check(c, crypto_box_SEALBYTES + m.length) check(pk, crypto_box_PUBLICKEYBYTES) diff --git a/crypto_kx.js b/crypto_kx.js new file mode 100644 index 0000000..04fb0bb --- /dev/null +++ b/crypto_kx.js @@ -0,0 +1,9 @@ +const { crypto_box_keypair, crypto_box_seed_keypair } = require('./crypto_box') + +function crypto_kx_keypair (pk, sk) { + return crypto_box_keypair(pk, sk) +} + +function crypto_kx_seed_keypair (pk, sk, seed) { + return crypto_box_seed_keypair(pk, sk, seed) +}