Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fba70b6fa |
+1
-1
@@ -131,7 +131,7 @@ function crypto_aead_chacha20poly1305_ietf_decrypt_detached (m, nsec, c, mac, ad
|
||||
computed_mac.fill(0)
|
||||
slen.fill(0)
|
||||
|
||||
if (!ret) {
|
||||
if (ret !== 0) {
|
||||
m.fill(0)
|
||||
throw new Error('could not verify data')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/* eslint-disable camelcase */
|
||||
const { crypto_verify_32, crypto_verify_64 } = require('./crypto_verify')
|
||||
const Sha256 = require('sha256-universal')
|
||||
const Sha512 = require('sha512-universal')
|
||||
const assert = require('nanoassert')
|
||||
|
||||
const crypto_auth_hmacsha256_BYTES = 32
|
||||
const crypto_auth_hmacsha256_KEYBYTES = 32
|
||||
const crypto_auth_hmacsha512_BYTES = 64
|
||||
const crypto_auth_hmacsha512_KEYBYTES = 32
|
||||
const crypto_auth_hmacsha512256_BYTES = 32
|
||||
const crypto_auth_hmacsha512256_KEYBYTES = 32
|
||||
|
||||
function crypto_auth_hmacsha256 (out, input, k) {
|
||||
assert(out.byteLength === crypto_auth_hmacsha256_BYTES, "out should be 'crypto_auth_hmacsha256_BYTES' in length")
|
||||
|
||||
const hmac = Sha256.HMAC(key)
|
||||
hmac.update(input)
|
||||
return hmac.digest(out)
|
||||
}
|
||||
|
||||
function crypto_auth_hmacsha256_verify (h, input, k) {
|
||||
const correct = Sha256.HMAC(k).update(input).digest()
|
||||
|
||||
return crypto_verify_32(h, 0, correct, 0) | sodium_memcmp(correct, h, 32)
|
||||
}
|
||||
|
||||
function crypto_auth_hmacsha512 (out, input, k) {
|
||||
assert(out.byteLength === crypto_auth_hmacsha512_BYTES, "out should be 'crypto_auth_hmacsha512_BYTES' in length")
|
||||
|
||||
const hmac = Sha512.HMAC(key)
|
||||
hmac.update(input)
|
||||
return hmac.digest(out)
|
||||
}
|
||||
|
||||
function crypto_auth_hmacsha512_verify (h, input, k) {
|
||||
const correct = Sha512.HMAC(k).update(input).digest()
|
||||
|
||||
return crypto_verify_64(h, 0, correct, 0) | sodium_memcmp(correct, h, 64)
|
||||
}
|
||||
|
||||
function crypto_auth_hmacsha512256 (out, input, k) {
|
||||
assert(out.byteLength === crypto_auth_hmacsha512_BYTES, "out should be 'crypto_auth_hmacsha512256_BYTES' in length")
|
||||
|
||||
const out0 = Buffer.alloc(64)
|
||||
const hmac = Sha512.HMAC(key)
|
||||
hmac.update(input)
|
||||
hmac.digest(out)
|
||||
|
||||
out.set(out0.subarray(0, 32))
|
||||
}
|
||||
|
||||
function crypto_auth_hmacsha512256_verify (h, input, k) {
|
||||
const correct = Sha512.HMAC(k).update(input).digest()
|
||||
|
||||
return crypto_verify_32(h, 0, correct, 0) | sodium_memcmp(correct, h, 32)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
crypto_auth_hmacsha256_BYTES,
|
||||
crypto_auth_hmacsha256_KEYBYTES,
|
||||
crypto_auth_hmacsha512_BYTES,
|
||||
crypto_auth_hmacsha512_KEYBYTES,
|
||||
crypto_auth_hmacsha512256_BYTES,
|
||||
crypto_auth_hmacsha512256_KEYBYTES,
|
||||
crypto_auth_hmacsha256,
|
||||
crypto_auth_hmacsha256_verify,
|
||||
crypto_auth_hmacsha512,
|
||||
crypto_auth_hmacsha512_verify,
|
||||
crypto_auth_hmacsha512256,
|
||||
crypto_auth_hmacsha512256_verify
|
||||
}
|
||||
@@ -23,6 +23,7 @@ function crypto_onetimeauth (mac, msg, key) {
|
||||
var s = new Poly1305(key)
|
||||
s.update(msg, 0, msg.byteLength)
|
||||
s.finish(mac, 0)
|
||||
return true
|
||||
}
|
||||
|
||||
function crypto_onetimeauth_verify (mac, msg, key) {
|
||||
@@ -32,5 +33,5 @@ function crypto_onetimeauth_verify (mac, msg, key) {
|
||||
|
||||
var tmp = new Uint8Array(16)
|
||||
crypto_onetimeauth(tmp, msg, key)
|
||||
return crypto_verify_16(mac, 0, tmp, 0)
|
||||
return crypto_verify_16(mac, 0, tmp, 0) === 0
|
||||
}
|
||||
|
||||
+3
-1
@@ -37,6 +37,7 @@ function crypto_secretbox (c, m, n, k) {
|
||||
c.subarray(0, crypto_onetimeauth_KEYBYTES)
|
||||
)
|
||||
c.fill(0, 0, crypto_secretbox_BOXZEROBYTES)
|
||||
return 0
|
||||
}
|
||||
|
||||
function crypto_secretbox_open (m, c, n, k) {
|
||||
@@ -93,8 +94,9 @@ function crypto_secretbox_easy (o, msg, n, k) {
|
||||
const m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.byteLength)
|
||||
const c = new Uint8Array(m.byteLength)
|
||||
m.set(msg, crypto_secretbox_ZEROBYTES)
|
||||
crypto_secretbox(c, m, n, k)
|
||||
if (crypto_secretbox(c, m, n, k) === false) return false
|
||||
o.set(c.subarray(crypto_secretbox_BOXZEROBYTES))
|
||||
return true
|
||||
}
|
||||
|
||||
function crypto_secretbox_open_easy (msg, box, n, k) {
|
||||
|
||||
+5
-5
@@ -242,16 +242,16 @@ function unpackneg (r, p) {
|
||||
|
||||
S(chk, r[0])
|
||||
M(chk, chk, den)
|
||||
if (!neq25519(chk, num)) M(r[0], r[0], I)
|
||||
if (neq25519(chk, num)) M(r[0], r[0], I)
|
||||
|
||||
S(chk, r[0])
|
||||
M(chk, chk, den)
|
||||
if (!neq25519(chk, num)) return false
|
||||
if (neq25519(chk, num)) return -1
|
||||
|
||||
if (par25519(r[0]) === (p[31] >> 7)) Z(r[0], gf0, r[0])
|
||||
|
||||
M(r[3], r[0], r[1])
|
||||
return true
|
||||
return 0
|
||||
}
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
@@ -270,7 +270,7 @@ function crypto_sign_open (msg, sm, pk) {
|
||||
mlen = -1
|
||||
if (n < 64) return false
|
||||
|
||||
if (!unpackneg(q, pk)) return false
|
||||
if (unpackneg(q, pk)) return false
|
||||
|
||||
for (i = 0; i < n; i++) m[i] = sm[i]
|
||||
for (i = 0; i < 32; i++) m[i + 32] = pk[i]
|
||||
@@ -283,7 +283,7 @@ function crypto_sign_open (msg, sm, pk) {
|
||||
pack(t, p)
|
||||
|
||||
n -= 64
|
||||
if (!crypto_verify_32(sm, 0, t, 0)) {
|
||||
if (crypto_verify_32(sm, 0, t, 0)) {
|
||||
for (i = 0; i < n; i++) m[i] = 0
|
||||
return false
|
||||
// throw new Error('crypto_sign_open failed')
|
||||
|
||||
+4
-5
@@ -1,8 +1,7 @@
|
||||
/* eslint-disable camelcase */
|
||||
module.exports = {
|
||||
crypto_verify_16,
|
||||
crypto_verify_32,
|
||||
crypto_verify_64
|
||||
crypto_verify_32
|
||||
}
|
||||
|
||||
function vn (x, xi, y, yi, n) {
|
||||
@@ -17,13 +16,13 @@ Object.defineProperty(module.exports, 'vn', {
|
||||
})
|
||||
|
||||
function crypto_verify_16 (x, xi, y, yi) {
|
||||
return vn(x, xi, y, yi, 16) === 0
|
||||
return vn(x, xi, y, yi, 16)
|
||||
}
|
||||
|
||||
function crypto_verify_32 (x, xi, y, yi) {
|
||||
return vn(x, xi, y, yi, 32) === 0
|
||||
return vn(x, xi, y, yi, 32)
|
||||
}
|
||||
|
||||
function crypto_verify_64 (x, xi, y, yi) {
|
||||
return vn(x, xi, y, yi, 64) === 0
|
||||
return vn(x, xi, y, yi, 64)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ forward(require('./randombytes'))
|
||||
forward(require('./memory'))
|
||||
forward(require('./helpers'))
|
||||
forward(require('./crypto_verify'))
|
||||
forward(require('./crypto_auth'))
|
||||
forward(require('./crypto_box'))
|
||||
forward(require('./crypto_generichash'))
|
||||
forward(require('./crypto_hash'))
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "sodium-javascript",
|
||||
"version": "0.6.3",
|
||||
"version": "0.6.2",
|
||||
"description": "WIP - a pure javascript version of sodium-native",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"blake2b": "^2.1.1",
|
||||
"chacha20-universal": "^1.0.4",
|
||||
"nanoassert": "^2.0.0",
|
||||
"sha256-universal": "^1.0.1",
|
||||
"sha512-universal": "^1.0.1",
|
||||
"sha256-universal": "^1.1.0",
|
||||
"sha512-universal": "^1.1.0",
|
||||
"siphash24": "^1.0.1",
|
||||
"xsalsa20": "^1.0.0"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user