Move helpers out
This commit is contained in:
parent
15e71abdc5
commit
2ca0db67b2
@ -1,11 +1,7 @@
|
|||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
const assert = require('nanoassert')
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
crypto_verify_16,
|
crypto_verify_16,
|
||||||
crypto_verify_32,
|
crypto_verify_32
|
||||||
sodium_memcmp,
|
|
||||||
sodium_is_zero
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function vn (x, xi, y, yi, n) {
|
function vn (x, xi, y, yi, n) {
|
||||||
@ -14,6 +10,11 @@ function vn (x, xi, y, yi, n) {
|
|||||||
return (1 & ((d - 1) >>> 8)) - 1
|
return (1 & ((d - 1) >>> 8)) - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make non enumerable as this is an internal function
|
||||||
|
Object.defineProperty(module.exports, 'vn', {
|
||||||
|
value: vn
|
||||||
|
})
|
||||||
|
|
||||||
function crypto_verify_16 (x, xi, y, yi) {
|
function crypto_verify_16 (x, xi, y, yi) {
|
||||||
return vn(x, xi, y, yi, 16)
|
return vn(x, xi, y, yi, 16)
|
||||||
}
|
}
|
||||||
@ -21,15 +22,3 @@ function crypto_verify_16 (x, xi, y, yi) {
|
|||||||
function crypto_verify_32 (x, xi, y, yi) {
|
function crypto_verify_32 (x, xi, y, yi) {
|
||||||
return vn(x, xi, y, yi, 32)
|
return vn(x, xi, y, yi, 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
function sodium_memcmp (a, b) {
|
|
||||||
assert(a.byteLength === b.byteLength, 'buffers must be the same size')
|
|
||||||
|
|
||||||
return vn(a, 0, b, 0, a.byteLength) === 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function sodium_is_zero (arr) {
|
|
||||||
var d = 0
|
|
||||||
for (let i = 0; i < arr.length; i++) d |= arr[i]
|
|
||||||
return d === 0
|
|
||||||
}
|
|
||||||
|
31
helpers.js
Normal file
31
helpers.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* eslint-disable camelcase */
|
||||||
|
const assert = require('nanoassert')
|
||||||
|
const { vn } = require('./verify')
|
||||||
|
|
||||||
|
function sodium_increment (n) {
|
||||||
|
const nlen = n.byteLength
|
||||||
|
var c = 1
|
||||||
|
for (var i = 0; i < nlen; i++) {
|
||||||
|
c += n[i]
|
||||||
|
n[i] = c
|
||||||
|
c >>= 8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sodium_memcmp (a, b) {
|
||||||
|
assert(a.byteLength === b.byteLength, 'buffers must be the same size')
|
||||||
|
|
||||||
|
return vn(a, 0, b, 0, a.byteLength) === 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function sodium_is_zero (arr) {
|
||||||
|
var d = 0
|
||||||
|
for (let i = 0; i < arr.length; i++) d |= arr[i]
|
||||||
|
return d === 0
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
sodium_increment,
|
||||||
|
sodium_memcmp,
|
||||||
|
sodium_is_zero
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user