move crypto_hash_sha256 to module to uncouple wasm dependencies
This commit is contained in:
parent
cb1fe07efe
commit
aa0305154f
@ -1,18 +1,11 @@
|
||||
const sha256 = require('sha256-wasm')
|
||||
const sha512 = require('sha512-wasm')
|
||||
const assert = require('nanoassert')
|
||||
|
||||
var crypto_hash_sha256_BYTES = 32
|
||||
if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.')
|
||||
|
||||
var crypto_hash_sha512_BYTES = 64
|
||||
var crypto_hash_BYTES = crypto_hash_sha512_BYTES
|
||||
|
||||
function crypto_hash_sha256 (out, m, n) {
|
||||
assert(out.byteLength === crypto_hash_sha256_BYTES, "out must be 'crypto_hash_sha256_BYTES' bytes long")
|
||||
|
||||
sha256().update(m.subarray(0, n)).digest(out)
|
||||
return 0
|
||||
}
|
||||
|
||||
function crypto_hash_sha512 (out, m, n) {
|
||||
assert(out.byteLength === crypto_hash_sha512_BYTES, "out must be 'crypto_hash_sha512_BYTES' bytes long")
|
||||
|
||||
@ -26,8 +19,6 @@ function crypto_hash (out, m, n) {
|
||||
|
||||
module.exports = {
|
||||
crypto_hash,
|
||||
crypto_hash_sha256,
|
||||
crypto_hash_sha512,
|
||||
crypto_hash_BYTES,
|
||||
crypto_hash_sha256_BYTES
|
||||
crypto_hash_BYTES
|
||||
}
|
||||
|
18
crypto_hash_256.js
Normal file
18
crypto_hash_256.js
Normal file
@ -0,0 +1,18 @@
|
||||
const sha256 = require('sha256-wasm')
|
||||
const assert = require('nanoassert')
|
||||
|
||||
if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.')
|
||||
|
||||
var crypto_hash_sha256_BYTES = 32
|
||||
|
||||
function crypto_hash_sha256 (out, m, n) {
|
||||
assert(out.byteLength === crypto_hash_sha256_BYTES, "out must be 'crypto_hash_sha256_BYTES' bytes long")
|
||||
|
||||
sha256().update(m.subarray(0, n)).digest(out)
|
||||
return 0
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
crypto_hash_sha256,
|
||||
crypto_hash_sha256_BYTES
|
||||
}
|
1
index.js
1
index.js
@ -23,6 +23,7 @@ sodium.sodium_malloc = function (n) {
|
||||
forward(require('./crypto_box'))
|
||||
forward(require('./crypto_generichash'))
|
||||
forward(require('./crypto_hash'))
|
||||
forward(require('./crypto_hash_sha256'))
|
||||
forward(require('./crypto_kdf'))
|
||||
forward(require('./crypto_kx'))
|
||||
forward(require('./crypto_aead'))
|
||||
|
Loading…
Reference in New Issue
Block a user