crypto_sign_SEEDBYTES = 32,\r
crypto_hash_BYTES = 64;\r
\r
- nacl.lowlevel = {\r
+ lowlevel = {\r
crypto_core_hsalsa20: crypto_core_hsalsa20,\r
crypto_stream_xor: crypto_stream_xor,\r
crypto_stream: crypto_stream,\r
for (var i = 0; i < arr.length; i++) arr[i] = 0;\r
}\r
\r
- nacl.randomBytes = function(n) {\r
+ randomBytes = function(n) {\r
var b = new Uint8Array(n);\r
randombytes(b, n);\r
return b;\r
};\r
\r
- nacl.secretbox = function(msg, nonce, key) {\r
+ secretbox = function(msg, nonce, key) {\r
checkArrayTypes(msg, nonce, key);\r
checkLengths(key, nonce);\r
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);\r
return c.subarray(crypto_secretbox_BOXZEROBYTES);\r
};\r
\r
- nacl.secretbox.open = function(box, nonce, key) {\r
+ secretbox.open = function(box, nonce, key) {\r
checkArrayTypes(box, nonce, key);\r
checkLengths(key, nonce);\r
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);\r
return m.subarray(crypto_secretbox_ZEROBYTES);\r
};\r
\r
- nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;\r
- nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;\r
- nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;\r
+ secretbox.keyLength = crypto_secretbox_KEYBYTES;\r
+ secretbox.nonceLength = crypto_secretbox_NONCEBYTES;\r
+ secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;\r
\r
- nacl.scalarMult = function(n, p) {\r
+ scalarMult = function(n, p) {\r
checkArrayTypes(n, p);\r
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');\r
if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');\r
return q;\r
};\r
\r
- nacl.scalarMult.base = function(n) {\r
+ scalarMult.base = function(n) {\r
checkArrayTypes(n);\r
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');\r
var q = new Uint8Array(crypto_scalarmult_BYTES);\r
return q;\r
};\r
\r
- nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;\r
- nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;\r
+ scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;\r
+ scalarMult.groupElementLength = crypto_scalarmult_BYTES;\r
\r
- nacl.box = function(msg, nonce, publicKey, secretKey) {\r
- var k = nacl.box.before(publicKey, secretKey);\r
- return nacl.secretbox(msg, nonce, k);\r
+ box = function(msg, nonce, publicKey, secretKey) {\r
+ var k = box.before(publicKey, secretKey);\r
+ return secretbox(msg, nonce, k);\r
};\r
\r
- nacl.box.before = function(publicKey, secretKey) {\r
+ box.before = function(publicKey, secretKey) {\r
checkArrayTypes(publicKey, secretKey);\r
checkBoxLengths(publicKey, secretKey);\r
var k = new Uint8Array(crypto_box_BEFORENMBYTES);\r
return k;\r
};\r
\r
- nacl.box.after = nacl.secretbox;\r
+ box.after = secretbox;\r
\r
- nacl.box.open = function(msg, nonce, publicKey, secretKey) {\r
- var k = nacl.box.before(publicKey, secretKey);\r
- return nacl.secretbox.open(msg, nonce, k);\r
+ box.open = function(msg, nonce, publicKey, secretKey) {\r
+ var k = box.before(publicKey, secretKey);\r
+ return secretbox.open(msg, nonce, k);\r
};\r
\r
- nacl.box.open.after = nacl.secretbox.open;\r
+ box.open.after = secretbox.open;\r
\r
- nacl.box.keyPair = function() {\r
+ box.keyPair = function() {\r
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);\r
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);\r
crypto_box_keypair(pk, sk);\r
return {publicKey: pk, secretKey: sk};\r
};\r
\r
- nacl.box.keyPair.fromSecretKey = function(secretKey) {\r
+ box.keyPair.fromSecretKey = function(secretKey) {\r
checkArrayTypes(secretKey);\r
if (secretKey.length !== crypto_box_SECRETKEYBYTES)\r
throw new Error('bad secret key size');\r
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};\r
};\r
\r
- nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;\r
- nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;\r
- nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;\r
- nacl.box.nonceLength = crypto_box_NONCEBYTES;\r
- nacl.box.overheadLength = nacl.secretbox.overheadLength;\r
+ box.publicKeyLength = crypto_box_PUBLICKEYBYTES;\r
+ box.secretKeyLength = crypto_box_SECRETKEYBYTES;\r
+ box.sharedKeyLength = crypto_box_BEFORENMBYTES;\r
+ box.nonceLength = crypto_box_NONCEBYTES;\r
+ box.overheadLength = secretbox.overheadLength;\r
\r
- nacl.sign = function(msg, secretKey) {\r
+ sign = function(msg, secretKey) {\r
checkArrayTypes(msg, secretKey);\r
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)\r
throw new Error('bad secret key size');\r
return signedMsg;\r
};\r
\r
- nacl.sign.open = function(signedMsg, publicKey) {\r
+ sign.open = function(signedMsg, publicKey) {\r
checkArrayTypes(signedMsg, publicKey);\r
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)\r
throw new Error('bad public key size');\r
return m;\r
};\r
\r
- nacl.sign.detached = function(msg, secretKey) {\r
- var signedMsg = nacl.sign(msg, secretKey);\r
+ sign.detached = function(msg, secretKey) {\r
+ var signedMsg = sign(msg, secretKey);\r
var sig = new Uint8Array(crypto_sign_BYTES);\r
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];\r
return sig;\r
};\r
\r
- nacl.sign.detached.verify = function(msg, sig, publicKey) {\r
+ sign.detached.verify = function(msg, sig, publicKey) {\r
checkArrayTypes(msg, sig, publicKey);\r
if (sig.length !== crypto_sign_BYTES)\r
throw new Error('bad signature size');\r
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);\r
};\r
\r
- nacl.sign.keyPair = function() {\r
+ sign.keyPair = function() {\r
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);\r
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);\r
crypto_sign_keypair(pk, sk);\r
return {publicKey: pk, secretKey: sk};\r
};\r
\r
- nacl.sign.keyPair.fromSecretKey = function(secretKey) {\r
+ sign.keyPair.fromSecretKey = function(secretKey) {\r
checkArrayTypes(secretKey);\r
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)\r
throw new Error('bad secret key size');\r
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};\r
};\r
\r
- nacl.sign.keyPair.fromSeed = function(seed) {\r
+ sign.keyPair.fromSeed = function(seed) {\r
checkArrayTypes(seed);\r
if (seed.length !== crypto_sign_SEEDBYTES)\r
throw new Error('bad seed size');\r
return {publicKey: pk, secretKey: sk};\r
};\r
\r
- nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;\r
- nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;\r
- nacl.sign.seedLength = crypto_sign_SEEDBYTES;\r
- nacl.sign.signatureLength = crypto_sign_BYTES;\r
+ sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;\r
+ sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;\r
+ sign.seedLength = crypto_sign_SEEDBYTES;\r
+ sign.signatureLength = crypto_sign_BYTES;\r
\r
- nacl.hash = function(msg) {\r
+ hash = function(msg) {\r
checkArrayTypes(msg);\r
var h = new Uint8Array(crypto_hash_BYTES);\r
crypto_hash(h, msg, msg.length);\r
return h;\r
};\r
\r
- nacl.hash.hashLength = crypto_hash_BYTES;\r
+ hash.hashLength = crypto_hash_BYTES;\r
\r
- nacl.verify = function(x, y) {\r
+ verify = function(x, y) {\r
checkArrayTypes(x, y);\r
// Zero length arguments are considered not equal.\r
if (x.length === 0 || y.length === 0) return false;\r
return (vn(x, 0, y, 0, x.length) === 0) ? true : false;\r
};\r
\r
- nacl.setPRNG = function(fn) {\r
+ setPRNG = function(fn) {\r
randombytes = fn;\r
};\r
\r
if (crypto && crypto.getRandomValues) {\r
// Browsers.\r
var QUOTA = 65536;\r
- nacl.setPRNG(function(x, n) {\r
+ setPRNG(function(x, n) {\r
var i, v = new Uint8Array(n);\r
for (i = 0; i < n; i += QUOTA) {\r
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));\r
// Node.js.\r
crypto = require('crypto');\r
if (crypto && crypto.randomBytes) {\r
- nacl.setPRNG(function(x, n) {\r
+ setPRNG(function(x, n) {\r
var i, v = crypto.randomBytes(n);\r
for (i = 0; i < n; i++) x[i] = v[i];\r
cleanup(v);\r
}\r
})();\r
\r
- export { box, keyPair, getPublicKey, hash, message, randomBytes, scalarMult }\r
+ export { box, hash, randomBytes, scalarMult, secretbox, sign, verify }\r