From 759cec5b5a150b8923b2d70d1bff4e96dc17b1dd Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Thu, 18 Jun 2020 14:11:22 +0200 Subject: [PATCH] add endian check: all other modules require members of this set --- crypto_generichash.js | 2 ++ crypto_shorthash.js | 2 ++ crypto_stream.js | 2 ++ crypto_stream_chacha20.js | 2 ++ ed25519.js | 2 ++ poly1305.js | 2 ++ 6 files changed, 12 insertions(+) diff --git a/crypto_generichash.js b/crypto_generichash.js index 36b9111..2d7a3a7 100644 --- a/crypto_generichash.js +++ b/crypto_generichash.js @@ -1,5 +1,7 @@ var blake2b = require('blake2b') +if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.') + module.exports.crypto_generichash_PRIMITIVE = 'blake2b' module.exports.crypto_generichash_BYTES_MIN = blake2b.BYTES_MIN module.exports.crypto_generichash_BYTES_MAX = blake2b.BYTES_MAX diff --git a/crypto_shorthash.js b/crypto_shorthash.js index b1b8378..a617e4a 100644 --- a/crypto_shorthash.js +++ b/crypto_shorthash.js @@ -1,5 +1,7 @@ var siphash = require('siphash24') +if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.') + exports.crypto_shorthash_PRIMITIVE = 'siphash24' exports.crypto_shorthash_BYTES = siphash.BYTES exports.crypto_shorthash_KEYBYTES = siphash.KEYBYTES diff --git a/crypto_stream.js b/crypto_stream.js index 303e40d..a106a72 100644 --- a/crypto_stream.js +++ b/crypto_stream.js @@ -1,5 +1,7 @@ var xsalsa20 = require('xsalsa20') +if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.') + exports.crypto_stream_KEYBYTES = 32 exports.crypto_stream_NONCEBYTES = 24 exports.crypto_stream_PRIMITIVE = 'xsalsa20' diff --git a/crypto_stream_chacha20.js b/crypto_stream_chacha20.js index 2832d3a..bdcfef2 100644 --- a/crypto_stream_chacha20.js +++ b/crypto_stream_chacha20.js @@ -1,6 +1,8 @@ const assert = require('nanoassert') const Chacha20 = require('chacha20-universal') +if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.') + exports.crypto_stream_chacha20_KEYBYTES = 32 exports.crypto_stream_chacha20_NONCEBYTES = 8 exports.crypto_stream_chacha20_MESSAGEBYTES_MAX = Number.MAX_SAFE_INTEGER diff --git a/ed25519.js b/ed25519.js index 9553eb0..2e92b6f 100644 --- a/ed25519.js +++ b/ed25519.js @@ -1,3 +1,5 @@ +if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.') + var gf = function(init) { var i, r = new Float64Array(16); if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; diff --git a/poly1305.js b/poly1305.js index 34e5ef6..96af7f1 100644 --- a/poly1305.js +++ b/poly1305.js @@ -3,6 +3,8 @@ * https://github.com/floodyberry/poly1305-donna */ +if (new Uint16Array([1])[0] !== 1) throw new Error('Big endian architecture is not supported.') + var poly1305 = function(key) { this.buffer = new Uint8Array(16); this.r = new Uint16Array(10);