sodium-javascript
Advanced tools
Comparing version 0.5.5 to 0.5.6
67
index.js
'use strict'; | ||
var xsalsa20 = require('xsalsa20') | ||
// Based on https://github.com/dchest/tweetnacl-js/blob/6dcbcaf5f5cbfd313f2dcfe763db35c828c8ff5b/nacl-fast.js. | ||
@@ -1739,2 +1741,53 @@ | ||
function crypto_box_keypair(pk, sk) { | ||
check(pk, crypto_box_PUBLICKEYBYTES) | ||
check(sk, crypto_box_SECRETKEYBYTES) | ||
randombytes(sk, 32) | ||
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) | ||
var epk = c.subarray(0, crypto_box_PUBLICKEYBYTES) | ||
var esk = new Uint8Array(crypto_box_SECRETKEYBYTES) | ||
crypto_box_keypair(epk, esk) | ||
var n = new Uint8Array(crypto_box_NONCEBYTES) | ||
sodium.crypto_generichash_batch(n, [ epk, pk ]) | ||
var s = new Uint8Array(crypto_box_PUBLICKEYBYTES) | ||
crypto_scalarmult(s, esk, pk) | ||
var k = new Uint8Array(crypto_box_BEFORENMBYTES) | ||
var zero = new Uint8Array(16) | ||
xsalsa20.core_hsalsa20(k, zero, s, xsalsa20.SIGMA) | ||
crypto_secretbox_easy(c.subarray(epk.length), m, n, k) | ||
cleanup(esk) | ||
} | ||
function crypto_box_seal_open(m, c, pk, sk) { | ||
check(c, crypto_box_SEALBYTES) | ||
check(m, c.length - crypto_box_SEALBYTES) | ||
check(pk, crypto_box_PUBLICKEYBYTES) | ||
check(sk, crypto_box_SECRETKEYBYTES) | ||
var epk = c.subarray(0, crypto_box_PUBLICKEYBYTES) | ||
var n = new Uint8Array(crypto_box_NONCEBYTES) | ||
sodium.crypto_generichash_batch(n, [ epk, pk ]) | ||
var s = new Uint8Array(crypto_box_PUBLICKEYBYTES) | ||
crypto_scalarmult(s, sk, epk) | ||
var k = new Uint8Array(crypto_box_BEFORENMBYTES) | ||
var zero = new Uint8Array(16) | ||
xsalsa20.core_hsalsa20(k, zero, s, xsalsa20.SIGMA) | ||
return crypto_secretbox_open_easy(m, c.subarray(epk.length), n, k) | ||
} | ||
var crypto_secretbox_KEYBYTES = 32, | ||
@@ -1752,2 +1805,4 @@ crypto_secretbox_NONCEBYTES = 24, | ||
crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, | ||
crypto_box_SEALBYTES = 48, | ||
crypto_box_BEFORENMBYTES = 32, | ||
crypto_sign_BYTES = 64, | ||
@@ -1793,2 +1848,14 @@ crypto_sign_PUBLICKEYBYTES = 32, | ||
sodium.crypto_box_PUBLICKEYBYTES = crypto_box_PUBLICKEYBYTES | ||
sodium.crypto_box_SECRETKEYBYTES = crypto_box_SECRETKEYBYTES | ||
sodium.crypto_box_SEALBYTES = crypto_box_SEALBYTES | ||
sodium.crypto_box_BEFORENMBYTES = crypto_box_BEFORENMBYTES | ||
sodium.crypto_box_keypair = crypto_box_keypair | ||
sodium.crypto_box_seal = crypto_box_seal | ||
sodium.crypto_box_seal_open = crypto_box_seal_open | ||
sodium.sodium_malloc = function (n) { | ||
return new Uint8Array(n) | ||
} | ||
function cleanup(arr) { | ||
@@ -1795,0 +1862,0 @@ for (var i = 0; i < arr.length; i++) arr[i] = 0; |
{ | ||
"name": "sodium-javascript", | ||
"version": "0.5.5", | ||
"version": "0.5.6", | ||
"description": "WIP - a pure javascript version of sodium-native", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55149
1765