move verify functions to crypto_verify module

This commit is contained in:
Christophe Diederichs 2020-05-04 21:08:29 +02:00
parent 1e447c23d6
commit 00d47225ff
2 changed files with 24 additions and 10 deletions

18
crypto_verify.js Normal file
View File

@ -0,0 +1,18 @@
module.exports = {
crypto_verify_16,
crypto_verify_32
}
function vn(x, xi, y, yi, n) {
var i,d = 0;
for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
return (1 & ((d - 1) >>> 8)) - 1;
}
function crypto_verify_16(x, xi, y, yi) {
return vn(x,xi,y,yi,16);
}
function crypto_verify_32(x, xi, y, yi) {
return vn(x,xi,y,yi,32);
}

View File

@ -13,16 +13,6 @@ var sodium = module.exports
// also forwarded at the bottom but randombytes is non-enumerable
var randombytes = require('./randombytes').randombytes
function vn(x, xi, y, yi, n) {
var i,d = 0;
for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
return (1 & ((d - 1) >>> 8)) - 1;
}
function crypto_verify_16(x, xi, y, yi) {
return vn(x,xi,y,yi,16);
}
function crypto_stream_xor (c, cpos, m, mpos, clen, n, k) {
cs.crypto_stream_xor(c, m, n, k)
@ -136,11 +126,17 @@ function cleanup(arr) {
for (var i = 0; i < arr.length; i++) arr[i] = 0;
}
forward(require('./crypto_box'))
forward(require('./crypto_generichash'))
forward(require('./crypto_hash'))
forward(require('./crypto_kdf'))
forward(require('./crypto_onetimeauth'))
forward(require('./crypto_scalarmult'))
forward(require('./crypto_secretbox'))
forward(require('./crypto_shorthash'))
forward(require('./crypto_sign'))
forward(require('./crypto_stream'))
forward(require('./randombytes'))
function forward (submodule) {
Object.keys(submodule).forEach(function (prop) {