From f969d1f707ad6a9cc2e142d95f2cd94adbb1563d Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Tue, 16 Jun 2020 15:54:44 +0200 Subject: [PATCH] correction: crypto_kx is not actually an alias of crypto_box --- crypto_kx.js | 33 ++++++++++++++++++++++++++++++--- index.js | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crypto_kx.js b/crypto_kx.js index 04fb0bb..e77c6fb 100644 --- a/crypto_kx.js +++ b/crypto_kx.js @@ -1,9 +1,36 @@ -const { crypto_box_keypair, crypto_box_seed_keypair } = require('./crypto_box') +const { crypto_scalarmult_base } = require('./crypto_scalarmult') +const { crypto_generichash } = require('./crypto_generichash') +const { randombytes_buf } = require('./randombytes') + +var crypto_kx_SEEDBYTES = 32 +var crypto_kx_PUBLICKEYBYTES = 32 +var crypto_kx_SECRETKEYBYTES = 32 function crypto_kx_keypair (pk, sk) { - return crypto_box_keypair(pk, sk) + check(pk, crypto_kx_PUBLICKEYBYTES) + check(sk, crypto_kx_SECRETKEYBYTES) + + randombytes_buf(sk, crypto_kx_SECRETKEYBYTES) + return crypto_scalarmult_base(pk, sk) } function crypto_kx_seed_keypair (pk, sk, seed) { - return crypto_box_seed_keypair(pk, sk, seed) + check(pk, crypto_kx_PUBLICKEYBYTES) + check(sk, crypto_kx_SECRETKEYBYTES) + check(seed, crypto_kx_SEEDBYTES) + + crypto_generichash(sk, seed) + return crypto_scalarmult_base(pk, sk) +} + +function check (buf, len) { + if (!buf || (len && buf.length < len)) throw new Error('Argument must be a buffer' + (len ? ' of length ' + len : '')) +} + +module.exports = { + crypto_kx_keypair, + crypto_kx_seed_keypair, + crypto_kx_SEEDBYTES, + crypto_kx_SECRETKEYBYTES, + crypto_kx_PUBLICKEYBYTES } diff --git a/index.js b/index.js index 7c4e616..86a2184 100644 --- a/index.js +++ b/index.js @@ -29,6 +29,7 @@ forward(require('./crypto_box')) forward(require('./crypto_generichash')) forward(require('./crypto_hash')) forward(require('./crypto_kdf')) +forward(require('./crypto_kx')) forward(require('./crypto_onetimeauth')) forward(require('./crypto_scalarmult')) forward(require('./crypto_secretbox'))