add: crypto_box_seed_keypair

This commit is contained in:
Christophe Diederichs 2020-06-16 16:02:42 +02:00
parent 7d7249ddc2
commit 84bf4229e4

View File

@ -1,8 +1,24 @@
const { crypto_hash_sha512 } = require('./crypto_hash')
const { crypto_scalarmult, crypto_scalarmult_base } = require('./crypto_scalarmult')
const { randombytes } = require('./randombytes')
const { crypto_generichash_batch } = require('./crypto_generichash')
const { crypto_secretbox_open_easy, crypto_secretbox_easy } = require('./crypto_secretbox')
const xsalsa20 = require('xsalsa20')
const { memzero } = require('./')
var crypto_box_PUBLICKEYBYTES = 32,
crypto_box_SECRETKEYBYTES = 32,
crypto_box_BEFORENMBYTES = 32,
crypto_box_NONCEBYTES = 24,
crypto_box_ZEROBYTES = 32,
crypto_box_BOXZEROBYTES = 16,
crypto_box_SEALBYTES = 48,
crypto_box_SEEDBYTES = 32,
crypto_box_BEFORENMBYTES = 32
module.exports = {
crypto_box_keypair,
crypto_box_seed_keypair,
crypto_box_seal,
crypto_box_seal_open,
crypto_box_PUBLICKEYBYTES,
@ -12,6 +28,7 @@ module.exports = {
crypto_box_ZEROBYTES,
crypto_box_BOXZEROBYTES,
crypto_box_SEALBYTES,
crypto_box_SEEDBYTES,
crypto_box_BEFORENMBYTES
}
@ -29,7 +46,7 @@ function crypto_box_seed_keypair(pk, sk, seed) {
const hash = Buffer.alloc(64)
crypto_hash_sha512(hash, seed, 32)
sk.set(hash, 0, 0, 32)
hash.copy(sk, 0, 0, 32)
memzero(hash)
return crypto_scalarmult_base(pk, sk)
@ -44,7 +61,7 @@ function crypto_box_seal(c, m, pk) {
crypto_box_keypair(epk, esk)
var n = new Uint8Array(crypto_box_NONCEBYTES)
sodium.crypto_generichash_batch(n, [ epk, pk ])
crypto_generichash_batch(n, [ epk, pk ])
var s = new Uint8Array(crypto_box_PUBLICKEYBYTES)
crypto_scalarmult(s, esk, pk)
@ -67,7 +84,7 @@ function crypto_box_seal_open(m, c, pk, sk) {
var epk = c.subarray(0, crypto_box_PUBLICKEYBYTES)
var n = new Uint8Array(crypto_box_NONCEBYTES)
sodium.crypto_generichash_batch(n, [ epk, pk ])
crypto_generichash_batch(n, [ epk, pk ])
var s = new Uint8Array(crypto_box_PUBLICKEYBYTES)
crypto_scalarmult(s, sk, epk)
@ -83,11 +100,6 @@ function check (buf, len) {
if (!buf || (len && buf.length < len)) throw new Error('Argument must be a buffer' + (len ? ' of length ' + len : ''))
}
var crypto_box_PUBLICKEYBYTES = 32,
crypto_box_SECRETKEYBYTES = 32,
crypto_box_BEFORENMBYTES = 32,
crypto_box_NONCEBYTES = 24,
crypto_box_ZEROBYTES = 32,
crypto_box_BOXZEROBYTES = 16,
crypto_box_SEALBYTES = 48,
crypto_box_BEFORENMBYTES = 32
function cleanup(arr) {
for (var i = 0; i < arr.length; i++) arr[i] = 0;
}