From 00d47225ff769b2583dc62fe7eda999fb9c5174a Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Mon, 4 May 2020 21:08:29 +0200 Subject: [PATCH] move verify functions to crypto_verify module --- crypto_verify.js | 18 ++++++++++++++++++ index.js | 16 ++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 crypto_verify.js diff --git a/crypto_verify.js b/crypto_verify.js new file mode 100644 index 0000000..9eaa261 --- /dev/null +++ b/crypto_verify.js @@ -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); +} diff --git a/index.js b/index.js index 1e23bf6..bafb4c3 100644 --- a/index.js +++ b/index.js @@ -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) {