diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md index 1c09ba4..587671a 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,14 @@ Takes a `HandshakeState` and destroys all internal data (eg. securely zeros out data contained in Buffer-like objects and resets state). Use this to dispose of state objects after a split has occurred or upon error +### `{publicKey, secretKey} = noise.keygen([obj])` + +Generate a new keypair with a `secretKey` and `publicKey`. You can optionally pass in your own `obj` that contains pre-allocated buffers on the `obj.publicKey` and `obj.publicKey` properties. Otherwise they are created for you. + +### `{publicKey, secretKey} = noise.seedKeygen(seed)` + +Pass in a `seed` buffer of length `sodium.crypto_kx_SEEDBYTES` and get back an object with coresponding `publicKey` and `secretKey`. + ### Split If no more message patterns are left to process, a **Split** will occur, as diff --git a/dh.js b/dh.js index 5cd790c..6c55d6b 100644 --- a/dh.js +++ b/dh.js @@ -26,7 +26,7 @@ function generateKeypair (pk, sk) { function generateSeedKeypair (pk, sk, seed) { assert(pk.byteLength === PKLEN) assert(sk.byteLength === SKLEN) - assert(seed.byteLength === SKLEN) + assert(seed.byteLength === SEEDLEN) sodium.crypto_kx_seed_keypair(pk, sk, seed) } diff --git a/handshake-state.js b/handshake-state.js index 844c89f..385857b 100644 --- a/handshake-state.js +++ b/handshake-state.js @@ -482,18 +482,14 @@ function destroy (state) { state.messagePatterns = null } -function keygen (obj, sk) { +function keygen (obj) { if (!obj) { obj = {publicKey: sodium.sodium_malloc(PKLEN), secretKey: sodium.sodium_malloc(SKLEN)} return keygen(obj) } - if (obj.publicKey) { - dh.generateKeypair(obj.publicKey, obj.secretKey) - return obj - } - - if (obj.byteLength != null) dh.generateKeypair(null, obj) + dh.generateKeypair(obj.publicKey, obj.secretKey) + return obj } function seedKeygen (seed) {