Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

noise-curve-ed

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

noise-curve-ed - npm Package Compare versions

Comparing version 1.0.4 to 2.0.0

36

index.js

@@ -8,2 +8,3 @@ /* eslint-disable camelcase */

const PKLEN = sodium.crypto_scalarmult_ed25519_BYTES
const SCALARLEN = sodium.crypto_scalarmult_ed25519_BYTES
const SKLEN = sodium.crypto_sign_SECRETKEYBYTES

@@ -15,2 +16,3 @@ const ALG = 'Ed25519'

PKLEN,
SCALARLEN,
SKLEN,

@@ -43,19 +45,27 @@ ALG,

function dh (pk, lsk) {
assert(lsk.byteLength === SKLEN)
assert(pk.byteLength === PKLEN)
function dh (publicKey, { scalar, secretKey }) {
// tweaked keys expose scalar directly
if (!scalar) {
assert(secretKey.byteLength === SKLEN)
// libsodium stores seed not actual scalar
const sk = b4a.alloc(64)
sodium.crypto_hash_sha512(sk, secretKey.subarray(0, 32))
sk[0] &= 248
sk[31] &= 127
sk[31] |= 64
scalar = sk.subarray(0, 32)
}
assert(scalar.byteLength === SCALARLEN)
assert(publicKey.byteLength === PKLEN)
const output = b4a.alloc(DHLEN)
// libsodium stores seed not actual scalar
const sk = b4a.alloc(64)
sodium.crypto_hash_sha512(sk, lsk.subarray(0, 32))
sk[0] &= 248
sk[31] &= 127
sk[31] |= 64
sodium.crypto_scalarmult_ed25519(
// we clamp if necessary above
sodium.crypto_scalarmult_ed25519_noclamp(
output,
sk.subarray(0, 32),
pk
scalar,
publicKey
)

@@ -62,0 +72,0 @@

{
"name": "noise-curve-ed",
"version": "1.0.4",
"version": "2.0.0",
"description": "Ed25519 elliptic curve operations for [`noise-handshake`](https://github.com/chm-diederichs/noise-handshake)",

@@ -26,3 +26,4 @@ "main": "index.js",

"devDependencies": {
"noise-handshake": "^1.1.0",
"hypercore-crypto-tweak": "github:holepunchto/hypercore-crypto-tweak",
"noise-handshake": "^3.0.0",
"standard": "^16.0.3",

@@ -29,0 +30,0 @@ "tape": "^5.2.2"

@@ -19,2 +19,3 @@ # noise-curve-ed

`PKLEN` = 32
`SCALARLEN` = 32
`SKLEN` = 64

@@ -30,8 +31,8 @@ `ALG` = 'Ed25519'

publicKey,
secretKey
secretKey,
}
```
#### `dh(pk, lsk)`
#### `dh(publicKey, { secretKey, scalar })`
Perform DH between `pk` and `lsk` and return the result.
Perform DH between `publicKey` and `secretKey`/`scalar` and return the result.
const Noise = require('noise-handshake')
const tweak = require('hypercore-crypto-tweak')
const test = require('tape')
const curve = require('./')
const test = require('tape')

@@ -12,15 +13,35 @@ test('XX', t => {

while (!initiator.handshakeComplete) {
const message = initiator.send()
responder.recv(message)
const message = initiator.send()
responder.recv(message)
if (!responder.handshakeComplete) {
const reply = responder.send()
initiator.recv(reply)
}
}
const reply = responder.send()
initiator.recv(reply)
t.deepEqual(initiator.rx.key, responder.tx.key)
t.deepEqual(initiator.tx.key, responder.rx.key)
t.deepEqual(initiator.rx, responder.tx)
t.deepEqual(initiator.tx, responder.rx)
t.end()
})
test('XX tweaked', t => {
const ibase = curve.generateKeyPair()
const rbase = curve.generateKeyPair()
const ikp = tweak(ibase, 'initiator').keyPair
const rkp = tweak(rbase, 'responder').keyPair
const initiator = new Noise('XX', true, ikp, { curve })
const responder = new Noise('XX', false, rkp, { curve })
initiator.initialise(Buffer.alloc(0))
responder.initialise(Buffer.alloc(0))
const message = initiator.send()
responder.recv(message)
const reply = responder.send()
initiator.recv(reply)
t.deepEqual(initiator.rx, responder.tx)
t.deepEqual(initiator.tx, responder.rx)
t.end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc