Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keygen cleanup #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 3 additions & 7 deletions handshake-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down