Socket
Socket
Sign inDemoInstall

private-box

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

private-box - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

26

index.js

@@ -15,10 +15,20 @@

const MAX = 7
function setMax (m) {
m = m || DEFAULT_MAX
if (m < 1 || m > 255)
throw new Error('max recipients must be between 0 and 255.')
return m
}
const DEFAULT_MAX = 7
exports.encrypt =
exports.multibox = function (msg, recipients) {
exports.multibox = function (msg, recipients, max) {
if(recipients.length > MAX)
throw new Error('max recipients is:'+MAX+' found:'+recipients.length)
max = setMax(max)
if(recipients.length > max)
throw new Error('max recipients is:'+max+' found:'+recipients.length)
var nonce = randombytes(24)

@@ -28,3 +38,3 @@ var key = randombytes(32)

var _key = concat([new Buffer([recipients.length & MAX]), key])
var _key = concat([new Buffer([recipients.length & max]), key])
return concat([

@@ -45,4 +55,6 @@ nonce,

exports.decrypt =
exports.multibox_open = function (ctxt, sk) { //, groups...
exports.multibox_open = function (ctxt, sk, max) { //, groups...
max = setMax(max)
var nonce = ctxt.slice(0, 24)

@@ -52,3 +64,3 @@ var onetime_pk = ctxt.slice(24, 24+32)

var _key, key, length, start = 24+32, size = 32+1+16
for(var i = 0; i <= MAX; i++) {
for(var i = 0; i <= max; i++) {
var s = start+size*i

@@ -55,0 +67,0 @@ if(s + size > (ctxt.length - 16)) continue

{
"name": "private-box",
"description": "encrypt a message to a secret number of recipients",
"version": "0.1.1",
"version": "0.2.0",
"homepage": "https://github.com/auditdrivencrypto/private-box",

@@ -6,0 +6,0 @@ "repository": {

@@ -13,2 +13,6 @@

function arrayOfSize (n) {
return new Array(n+1).join('0').split('')
}
tape('simple', function (t) {

@@ -46,18 +50,41 @@

tape('encrypt/decrypt to many keys', function (t) {
function encryptDecryptTo (n, t) {
var msg = crypto.randomBytes(1024)
var keys = [1,2,3,4,5,6,7].map(function () { return keypair() })
var keys = arrayOfSize(n).map(function () { return keypair() })
var ctxt = c.multibox(msg, keys.map(function (e) { return e.publicKey }))
var ctxt = c.multibox(msg, keys.map(function (e) { return e.publicKey }), n)
// a recipient key may open the message.
keys.forEach(function (keys) {
t.deepEqual(c.multibox_open(ctxt, keys.secretKey), msg)
t.deepEqual(c.multibox_open(ctxt, keys.secretKey, n), msg)
})
t.equal(c.multibox_open(ctxt, keypair().secretKey), undefined)
}
tape('with no custom max set, encrypt/decrypt to 7 keys', function (t) {
encryptDecryptTo(7, t)
t.end()
})
tape('can encrypt/decrypt up to 255 recipients after setting a custom max', function (t) {
encryptDecryptTo(255, t)
t.end()
})
tape('errors when max is more than 255 or less than 1', function (t) {
var msg = new Buffer('hello there!')
var ctxt = c.multibox(msg, [alice.publicKey, bob.publicKey])
var pk = alice.publicKey
var sk = alice.secretKey
t.throws(function () {
c.multibox(msg, [
pk,pk,pk,pk,
], -1)
})
t.throws(function () {
c.multibox.open(ctxt, sk, 256)
})
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