add: crypto_box_seed_keypair; alias crypto_kx methods to crypto_box

This commit is contained in:
Christophe Diederichs 2020-06-16 14:18:32 +02:00
parent d57736bf8b
commit 8aae7efea2
2 changed files with 25 additions and 0 deletions

View File

@ -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)

9
crypto_kx.js Normal file
View File

@ -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)
}