@xchainjs/xchain-thorchain 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.esm.js +897 -860
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +897 -860
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -5540,13 +5540,13 @@ function requireMinimal () {
|
|
|
5540
5540
|
|
|
5541
5541
|
var writer = Writer$1;
|
|
5542
5542
|
|
|
5543
|
-
var util$
|
|
5543
|
+
var util$5 = requireMinimal();
|
|
5544
5544
|
|
|
5545
5545
|
var BufferWriter$1; // cyclic
|
|
5546
5546
|
|
|
5547
|
-
var LongBits$1 = util$
|
|
5548
|
-
base64 = util$
|
|
5549
|
-
utf8$1 = util$
|
|
5547
|
+
var LongBits$1 = util$5.LongBits,
|
|
5548
|
+
base64 = util$5.base64,
|
|
5549
|
+
utf8$1 = util$5.utf8;
|
|
5550
5550
|
|
|
5551
5551
|
/**
|
|
5552
5552
|
* Constructs a new writer operation instance.
|
|
@@ -5661,7 +5661,7 @@ function Writer$1() {
|
|
|
5661
5661
|
}
|
|
5662
5662
|
|
|
5663
5663
|
var create$1 = function create() {
|
|
5664
|
-
return util$
|
|
5664
|
+
return util$5.Buffer
|
|
5665
5665
|
? function create_buffer_setup() {
|
|
5666
5666
|
return (Writer$1.create = function create_buffer() {
|
|
5667
5667
|
return new BufferWriter$1();
|
|
@@ -5686,13 +5686,13 @@ Writer$1.create = create$1();
|
|
|
5686
5686
|
* @returns {Uint8Array} Buffer
|
|
5687
5687
|
*/
|
|
5688
5688
|
Writer$1.alloc = function alloc(size) {
|
|
5689
|
-
return new util$
|
|
5689
|
+
return new util$5.Array(size);
|
|
5690
5690
|
};
|
|
5691
5691
|
|
|
5692
5692
|
// Use Uint8Array buffer pool in the browser, just like node does with buffers
|
|
5693
5693
|
/* istanbul ignore else */
|
|
5694
|
-
if (util$
|
|
5695
|
-
Writer$1.alloc = util$
|
|
5694
|
+
if (util$5.Array !== Array)
|
|
5695
|
+
Writer$1.alloc = util$5.pool(Writer$1.alloc, util$5.Array.prototype.subarray);
|
|
5696
5696
|
|
|
5697
5697
|
/**
|
|
5698
5698
|
* Pushes a new operation to the queue.
|
|
@@ -5882,7 +5882,7 @@ Writer$1.prototype.sfixed64 = Writer$1.prototype.fixed64;
|
|
|
5882
5882
|
* @returns {Writer} `this`
|
|
5883
5883
|
*/
|
|
5884
5884
|
Writer$1.prototype.float = function write_float(value) {
|
|
5885
|
-
return this._push(util$
|
|
5885
|
+
return this._push(util$5.float.writeFloatLE, 4, value);
|
|
5886
5886
|
};
|
|
5887
5887
|
|
|
5888
5888
|
/**
|
|
@@ -5892,10 +5892,10 @@ Writer$1.prototype.float = function write_float(value) {
|
|
|
5892
5892
|
* @returns {Writer} `this`
|
|
5893
5893
|
*/
|
|
5894
5894
|
Writer$1.prototype.double = function write_double(value) {
|
|
5895
|
-
return this._push(util$
|
|
5895
|
+
return this._push(util$5.float.writeDoubleLE, 8, value);
|
|
5896
5896
|
};
|
|
5897
5897
|
|
|
5898
|
-
var writeBytes = util$
|
|
5898
|
+
var writeBytes = util$5.Array.prototype.set
|
|
5899
5899
|
? function writeBytes_set(val, buf, pos) {
|
|
5900
5900
|
buf.set(val, pos); // also works for plain array values
|
|
5901
5901
|
}
|
|
@@ -5914,7 +5914,7 @@ Writer$1.prototype.bytes = function write_bytes(value) {
|
|
|
5914
5914
|
var len = value.length >>> 0;
|
|
5915
5915
|
if (!len)
|
|
5916
5916
|
return this._push(writeByte, 1, 0);
|
|
5917
|
-
if (util$
|
|
5917
|
+
if (util$5.isString(value)) {
|
|
5918
5918
|
var buf = Writer$1.alloc(len = base64.length(value));
|
|
5919
5919
|
base64.decode(value, buf, 0);
|
|
5920
5920
|
value = buf;
|
|
@@ -6009,7 +6009,7 @@ var writer_buffer = BufferWriter;
|
|
|
6009
6009
|
var Writer = writer;
|
|
6010
6010
|
(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
|
|
6011
6011
|
|
|
6012
|
-
var util$
|
|
6012
|
+
var util$4 = requireMinimal();
|
|
6013
6013
|
|
|
6014
6014
|
/**
|
|
6015
6015
|
* Constructs a new buffer writer instance.
|
|
@@ -6028,9 +6028,9 @@ BufferWriter._configure = function () {
|
|
|
6028
6028
|
* @param {number} size Buffer size
|
|
6029
6029
|
* @returns {Buffer} Buffer
|
|
6030
6030
|
*/
|
|
6031
|
-
BufferWriter.alloc = util$
|
|
6031
|
+
BufferWriter.alloc = util$4._Buffer_allocUnsafe;
|
|
6032
6032
|
|
|
6033
|
-
BufferWriter.writeBytesBuffer = util$
|
|
6033
|
+
BufferWriter.writeBytesBuffer = util$4.Buffer && util$4.Buffer.prototype instanceof Uint8Array && util$4.Buffer.prototype.set.name === "set"
|
|
6034
6034
|
? function writeBytesBuffer_set(val, buf, pos) {
|
|
6035
6035
|
buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
|
|
6036
6036
|
// also works for plain array values
|
|
@@ -6049,8 +6049,8 @@ BufferWriter._configure = function () {
|
|
|
6049
6049
|
* @override
|
|
6050
6050
|
*/
|
|
6051
6051
|
BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
6052
|
-
if (util$
|
|
6053
|
-
value = util$
|
|
6052
|
+
if (util$4.isString(value))
|
|
6053
|
+
value = util$4._Buffer_from(value, "base64");
|
|
6054
6054
|
var len = value.length >>> 0;
|
|
6055
6055
|
this.uint32(len);
|
|
6056
6056
|
if (len)
|
|
@@ -6060,7 +6060,7 @@ BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
|
6060
6060
|
|
|
6061
6061
|
function writeStringBuffer(val, buf, pos) {
|
|
6062
6062
|
if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
|
|
6063
|
-
util$
|
|
6063
|
+
util$4.utf8.write(val, buf, pos);
|
|
6064
6064
|
else if (buf.utf8Write)
|
|
6065
6065
|
buf.utf8Write(val, pos);
|
|
6066
6066
|
else
|
|
@@ -6071,7 +6071,7 @@ function writeStringBuffer(val, buf, pos) {
|
|
|
6071
6071
|
* @override
|
|
6072
6072
|
*/
|
|
6073
6073
|
BufferWriter.prototype.string = function write_string_buffer(value) {
|
|
6074
|
-
var len = util$
|
|
6074
|
+
var len = util$4.Buffer.byteLength(value);
|
|
6075
6075
|
this.uint32(len);
|
|
6076
6076
|
if (len)
|
|
6077
6077
|
this._push(writeStringBuffer, len, value);
|
|
@@ -6090,12 +6090,12 @@ BufferWriter._configure();
|
|
|
6090
6090
|
|
|
6091
6091
|
var reader = Reader$1;
|
|
6092
6092
|
|
|
6093
|
-
var util$
|
|
6093
|
+
var util$3 = requireMinimal();
|
|
6094
6094
|
|
|
6095
6095
|
var BufferReader$1; // cyclic
|
|
6096
6096
|
|
|
6097
|
-
var LongBits = util$
|
|
6098
|
-
utf8 = util$
|
|
6097
|
+
var LongBits = util$3.LongBits,
|
|
6098
|
+
utf8 = util$3.utf8;
|
|
6099
6099
|
|
|
6100
6100
|
/* istanbul ignore next */
|
|
6101
6101
|
function indexOutOfRange(reader, writeLength) {
|
|
@@ -6143,10 +6143,10 @@ var create_array = typeof Uint8Array !== "undefined"
|
|
|
6143
6143
|
};
|
|
6144
6144
|
|
|
6145
6145
|
var create = function create() {
|
|
6146
|
-
return util$
|
|
6146
|
+
return util$3.Buffer
|
|
6147
6147
|
? function create_buffer_setup(buffer) {
|
|
6148
6148
|
return (Reader$1.create = function create_buffer(buffer) {
|
|
6149
|
-
return util$
|
|
6149
|
+
return util$3.Buffer.isBuffer(buffer)
|
|
6150
6150
|
? new BufferReader$1(buffer)
|
|
6151
6151
|
/* istanbul ignore next */
|
|
6152
6152
|
: create_array(buffer);
|
|
@@ -6165,7 +6165,7 @@ var create = function create() {
|
|
|
6165
6165
|
*/
|
|
6166
6166
|
Reader$1.create = create();
|
|
6167
6167
|
|
|
6168
|
-
Reader$1.prototype._slice = util$
|
|
6168
|
+
Reader$1.prototype._slice = util$3.Array.prototype.subarray || /* istanbul ignore next */ util$3.Array.prototype.slice;
|
|
6169
6169
|
|
|
6170
6170
|
/**
|
|
6171
6171
|
* Reads a varint as an unsigned 32 bit value.
|
|
@@ -6364,7 +6364,7 @@ Reader$1.prototype.float = function read_float() {
|
|
|
6364
6364
|
if (this.pos + 4 > this.len)
|
|
6365
6365
|
throw indexOutOfRange(this, 4);
|
|
6366
6366
|
|
|
6367
|
-
var value = util$
|
|
6367
|
+
var value = util$3.float.readFloatLE(this.buf, this.pos);
|
|
6368
6368
|
this.pos += 4;
|
|
6369
6369
|
return value;
|
|
6370
6370
|
};
|
|
@@ -6380,7 +6380,7 @@ Reader$1.prototype.double = function read_double() {
|
|
|
6380
6380
|
if (this.pos + 8 > this.len)
|
|
6381
6381
|
throw indexOutOfRange(this, 4);
|
|
6382
6382
|
|
|
6383
|
-
var value = util$
|
|
6383
|
+
var value = util$3.float.readDoubleLE(this.buf, this.pos);
|
|
6384
6384
|
this.pos += 8;
|
|
6385
6385
|
return value;
|
|
6386
6386
|
};
|
|
@@ -6473,8 +6473,8 @@ Reader$1._configure = function(BufferReader_) {
|
|
|
6473
6473
|
Reader$1.create = create();
|
|
6474
6474
|
BufferReader$1._configure();
|
|
6475
6475
|
|
|
6476
|
-
var fn = util$
|
|
6477
|
-
util$
|
|
6476
|
+
var fn = util$3.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
|
|
6477
|
+
util$3.merge(Reader$1.prototype, {
|
|
6478
6478
|
|
|
6479
6479
|
int64: function read_int64() {
|
|
6480
6480
|
return readLongVarint.call(this)[fn](false);
|
|
@@ -6505,7 +6505,7 @@ var reader_buffer = BufferReader;
|
|
|
6505
6505
|
var Reader = reader;
|
|
6506
6506
|
(BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
|
|
6507
6507
|
|
|
6508
|
-
var util$
|
|
6508
|
+
var util$2 = requireMinimal();
|
|
6509
6509
|
|
|
6510
6510
|
/**
|
|
6511
6511
|
* Constructs a new buffer reader instance.
|
|
@@ -6526,8 +6526,8 @@ function BufferReader(buffer) {
|
|
|
6526
6526
|
|
|
6527
6527
|
BufferReader._configure = function () {
|
|
6528
6528
|
/* istanbul ignore else */
|
|
6529
|
-
if (util$
|
|
6530
|
-
BufferReader.prototype._slice = util$
|
|
6529
|
+
if (util$2.Buffer)
|
|
6530
|
+
BufferReader.prototype._slice = util$2.Buffer.prototype.slice;
|
|
6531
6531
|
};
|
|
6532
6532
|
|
|
6533
6533
|
|
|
@@ -6554,10 +6554,10 @@ var rpc = {};
|
|
|
6554
6554
|
|
|
6555
6555
|
var service$1 = Service;
|
|
6556
6556
|
|
|
6557
|
-
var util$
|
|
6557
|
+
var util$1 = requireMinimal();
|
|
6558
6558
|
|
|
6559
6559
|
// Extends EventEmitter
|
|
6560
|
-
(Service.prototype = Object.create(util$
|
|
6560
|
+
(Service.prototype = Object.create(util$1.EventEmitter.prototype)).constructor = Service;
|
|
6561
6561
|
|
|
6562
6562
|
/**
|
|
6563
6563
|
* A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
|
|
@@ -6597,7 +6597,7 @@ function Service(rpcImpl, requestDelimited, responseDelimited) {
|
|
|
6597
6597
|
if (typeof rpcImpl !== "function")
|
|
6598
6598
|
throw TypeError("rpcImpl must be a function");
|
|
6599
6599
|
|
|
6600
|
-
util$
|
|
6600
|
+
util$1.EventEmitter.call(this);
|
|
6601
6601
|
|
|
6602
6602
|
/**
|
|
6603
6603
|
* RPC implementation. Becomes `null` once the service is ended.
|
|
@@ -6636,7 +6636,7 @@ Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor,
|
|
|
6636
6636
|
|
|
6637
6637
|
var self = this;
|
|
6638
6638
|
if (!callback)
|
|
6639
|
-
return util$
|
|
6639
|
+
return util$1.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
|
|
6640
6640
|
|
|
6641
6641
|
if (!self.rpcImpl) {
|
|
6642
6642
|
setTimeout(function() { callback(Error("already ended")); }, 0);
|
|
@@ -115209,20 +115209,25 @@ function requireBlowfish () {
|
|
|
115209
115209
|
|
|
115210
115210
|
cryptoJs.exports;
|
|
115211
115211
|
|
|
115212
|
-
|
|
115213
|
-
(function (root, factory, undef) {
|
|
115214
|
-
{
|
|
115215
|
-
// CommonJS
|
|
115216
|
-
module.exports = factory(requireCore$1(), requireX64Core(), requireLibTypedarrays(), requireEncUtf16(), requireEncBase64(), requireEncBase64url(), requireMd5(), requireSha1(), requireSha256(), requireSha224(), requireSha512(), requireSha384(), requireSha3(), requireRipemd160(), requireHmac(), requirePbkdf2(), requireEvpkdf(), requireCipherCore(), requireModeCfb(), requireModeCtr(), requireModeCtrGladman(), requireModeOfb(), requireModeEcb(), requirePadAnsix923(), requirePadIso10126(), requirePadIso97971(), requirePadZeropadding(), requirePadNopadding(), requireFormatHex(), requireAes(), requireTripledes(), requireRc4(), requireRabbit(), requireRabbitLegacy(), requireBlowfish());
|
|
115217
|
-
}
|
|
115218
|
-
}(commonjsGlobal$1, function (CryptoJS) {
|
|
115212
|
+
var hasRequiredCryptoJs;
|
|
115219
115213
|
|
|
115220
|
-
|
|
115214
|
+
function requireCryptoJs () {
|
|
115215
|
+
if (hasRequiredCryptoJs) return cryptoJs.exports;
|
|
115216
|
+
hasRequiredCryptoJs = 1;
|
|
115217
|
+
(function (module, exports) {
|
|
115218
|
+
(function (root, factory, undef) {
|
|
115219
|
+
{
|
|
115220
|
+
// CommonJS
|
|
115221
|
+
module.exports = factory(requireCore$1(), requireX64Core(), requireLibTypedarrays(), requireEncUtf16(), requireEncBase64(), requireEncBase64url(), requireMd5(), requireSha1(), requireSha256(), requireSha224(), requireSha512(), requireSha384(), requireSha3(), requireRipemd160(), requireHmac(), requirePbkdf2(), requireEvpkdf(), requireCipherCore(), requireModeCfb(), requireModeCtr(), requireModeCtrGladman(), requireModeOfb(), requireModeEcb(), requirePadAnsix923(), requirePadIso10126(), requirePadIso97971(), requirePadZeropadding(), requirePadNopadding(), requireFormatHex(), requireAes(), requireTripledes(), requireRc4(), requireRabbit(), requireRabbitLegacy(), requireBlowfish());
|
|
115222
|
+
}
|
|
115223
|
+
}(commonjsGlobal$1, function (CryptoJS) {
|
|
115221
115224
|
|
|
115222
|
-
|
|
115223
|
-
} (cryptoJs, cryptoJs.exports));
|
|
115225
|
+
return CryptoJS;
|
|
115224
115226
|
|
|
115225
|
-
|
|
115227
|
+
}));
|
|
115228
|
+
} (cryptoJs, cryptoJs.exports));
|
|
115229
|
+
return cryptoJs.exports;
|
|
115230
|
+
}
|
|
115226
115231
|
|
|
115227
115232
|
var utility = {};
|
|
115228
115233
|
|
|
@@ -117727,826 +117732,858 @@ function requireUtility () {
|
|
|
117727
117732
|
return utility;
|
|
117728
117733
|
}
|
|
117729
117734
|
|
|
117730
|
-
|
|
117731
|
-
|
|
117732
|
-
// For convenience, let people hash a string, not just a Uint8Array
|
|
117733
|
-
function normalizeInput (input) {
|
|
117734
|
-
let ret;
|
|
117735
|
-
if (input instanceof Uint8Array) {
|
|
117736
|
-
ret = input;
|
|
117737
|
-
} else if (typeof input === 'string') {
|
|
117738
|
-
const encoder = new TextEncoder();
|
|
117739
|
-
ret = encoder.encode(input);
|
|
117740
|
-
} else {
|
|
117741
|
-
throw new Error(ERROR_MSG_INPUT)
|
|
117742
|
-
}
|
|
117743
|
-
return ret
|
|
117744
|
-
}
|
|
117745
|
-
|
|
117746
|
-
// Converts a Uint8Array to a hexadecimal string
|
|
117747
|
-
// For example, toHex([255, 0, 255]) returns "ff00ff"
|
|
117748
|
-
function toHex (bytes) {
|
|
117749
|
-
return Array.prototype.map
|
|
117750
|
-
.call(bytes, function (n) {
|
|
117751
|
-
return (n < 16 ? '0' : '') + n.toString(16)
|
|
117752
|
-
})
|
|
117753
|
-
.join('')
|
|
117754
|
-
}
|
|
117755
|
-
|
|
117756
|
-
// Converts any value in [0...2^32-1] to an 8-character hex string
|
|
117757
|
-
function uint32ToHex (val) {
|
|
117758
|
-
return (0x100000000 + val).toString(16).substring(1)
|
|
117759
|
-
}
|
|
117760
|
-
|
|
117761
|
-
// For debugging: prints out hash state in the same format as the RFC
|
|
117762
|
-
// sample computation exactly, so that you can diff
|
|
117763
|
-
function debugPrint (label, arr, size) {
|
|
117764
|
-
let msg = '\n' + label + ' = ';
|
|
117765
|
-
for (let i = 0; i < arr.length; i += 2) {
|
|
117766
|
-
if (size === 32) {
|
|
117767
|
-
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117768
|
-
msg += ' ';
|
|
117769
|
-
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117770
|
-
} else if (size === 64) {
|
|
117771
|
-
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117772
|
-
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117773
|
-
} else throw new Error('Invalid size ' + size)
|
|
117774
|
-
if (i % 6 === 4) {
|
|
117775
|
-
msg += '\n' + new Array(label.length + 4).join(' ');
|
|
117776
|
-
} else if (i < arr.length - 2) {
|
|
117777
|
-
msg += ' ';
|
|
117778
|
-
}
|
|
117779
|
-
}
|
|
117780
|
-
console.log(msg);
|
|
117781
|
-
}
|
|
117782
|
-
|
|
117783
|
-
// For performance testing: generates N bytes of input, hashes M times
|
|
117784
|
-
// Measures and prints MB/second hash performance each time
|
|
117785
|
-
function testSpeed (hashFn, N, M) {
|
|
117786
|
-
let startMs = new Date().getTime();
|
|
117787
|
-
|
|
117788
|
-
const input = new Uint8Array(N);
|
|
117789
|
-
for (let i = 0; i < N; i++) {
|
|
117790
|
-
input[i] = i % 256;
|
|
117791
|
-
}
|
|
117792
|
-
const genMs = new Date().getTime();
|
|
117793
|
-
console.log('Generated random input in ' + (genMs - startMs) + 'ms');
|
|
117794
|
-
startMs = genMs;
|
|
117795
|
-
|
|
117796
|
-
for (let i = 0; i < M; i++) {
|
|
117797
|
-
const hashHex = hashFn(input);
|
|
117798
|
-
const hashMs = new Date().getTime();
|
|
117799
|
-
const ms = hashMs - startMs;
|
|
117800
|
-
startMs = hashMs;
|
|
117801
|
-
console.log('Hashed in ' + ms + 'ms: ' + hashHex.substring(0, 20) + '...');
|
|
117802
|
-
console.log(
|
|
117803
|
-
Math.round((N / (1 << 20) / (ms / 1000)) * 100) / 100 + ' MB PER SECOND'
|
|
117804
|
-
);
|
|
117805
|
-
}
|
|
117806
|
-
}
|
|
117807
|
-
|
|
117808
|
-
var util$2 = {
|
|
117809
|
-
normalizeInput: normalizeInput,
|
|
117810
|
-
toHex: toHex,
|
|
117811
|
-
debugPrint: debugPrint,
|
|
117812
|
-
testSpeed: testSpeed
|
|
117813
|
-
};
|
|
117735
|
+
var util;
|
|
117736
|
+
var hasRequiredUtil;
|
|
117814
117737
|
|
|
117815
|
-
|
|
117816
|
-
|
|
117817
|
-
|
|
117818
|
-
|
|
117819
|
-
const util$1 = util$2;
|
|
117820
|
-
|
|
117821
|
-
// 64-bit unsigned addition
|
|
117822
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
117823
|
-
// v should be a Uint32Array
|
|
117824
|
-
function ADD64AA (v, a, b) {
|
|
117825
|
-
const o0 = v[a] + v[b];
|
|
117826
|
-
let o1 = v[a + 1] + v[b + 1];
|
|
117827
|
-
if (o0 >= 0x100000000) {
|
|
117828
|
-
o1++;
|
|
117829
|
-
}
|
|
117830
|
-
v[a] = o0;
|
|
117831
|
-
v[a + 1] = o1;
|
|
117832
|
-
}
|
|
117833
|
-
|
|
117834
|
-
// 64-bit unsigned addition
|
|
117835
|
-
// Sets v[a,a+1] += b
|
|
117836
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
117837
|
-
function ADD64AC (v, a, b0, b1) {
|
|
117838
|
-
let o0 = v[a] + b0;
|
|
117839
|
-
if (b0 < 0) {
|
|
117840
|
-
o0 += 0x100000000;
|
|
117841
|
-
}
|
|
117842
|
-
let o1 = v[a + 1] + b1;
|
|
117843
|
-
if (o0 >= 0x100000000) {
|
|
117844
|
-
o1++;
|
|
117845
|
-
}
|
|
117846
|
-
v[a] = o0;
|
|
117847
|
-
v[a + 1] = o1;
|
|
117848
|
-
}
|
|
117849
|
-
|
|
117850
|
-
// Little-endian byte access
|
|
117851
|
-
function B2B_GET32 (arr, i) {
|
|
117852
|
-
return arr[i] ^ (arr[i + 1] << 8) ^ (arr[i + 2] << 16) ^ (arr[i + 3] << 24)
|
|
117853
|
-
}
|
|
117854
|
-
|
|
117855
|
-
// G Mixing function
|
|
117856
|
-
// The ROTRs are inlined for speed
|
|
117857
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
117858
|
-
const x0 = m$1[ix];
|
|
117859
|
-
const x1 = m$1[ix + 1];
|
|
117860
|
-
const y0 = m$1[iy];
|
|
117861
|
-
const y1 = m$1[iy + 1];
|
|
117862
|
-
|
|
117863
|
-
ADD64AA(v$1, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
117864
|
-
ADD64AC(v$1, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
117865
|
-
|
|
117866
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
117867
|
-
let xor0 = v$1[d] ^ v$1[a];
|
|
117868
|
-
let xor1 = v$1[d + 1] ^ v$1[a + 1];
|
|
117869
|
-
v$1[d] = xor1;
|
|
117870
|
-
v$1[d + 1] = xor0;
|
|
117871
|
-
|
|
117872
|
-
ADD64AA(v$1, c, d);
|
|
117873
|
-
|
|
117874
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
117875
|
-
xor0 = v$1[b] ^ v$1[c];
|
|
117876
|
-
xor1 = v$1[b + 1] ^ v$1[c + 1];
|
|
117877
|
-
v$1[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
117878
|
-
v$1[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
117879
|
-
|
|
117880
|
-
ADD64AA(v$1, a, b);
|
|
117881
|
-
ADD64AC(v$1, a, y0, y1);
|
|
117882
|
-
|
|
117883
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
117884
|
-
xor0 = v$1[d] ^ v$1[a];
|
|
117885
|
-
xor1 = v$1[d + 1] ^ v$1[a + 1];
|
|
117886
|
-
v$1[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
117887
|
-
v$1[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
117888
|
-
|
|
117889
|
-
ADD64AA(v$1, c, d);
|
|
117890
|
-
|
|
117891
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
117892
|
-
xor0 = v$1[b] ^ v$1[c];
|
|
117893
|
-
xor1 = v$1[b + 1] ^ v$1[c + 1];
|
|
117894
|
-
v$1[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
117895
|
-
v$1[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
117896
|
-
}
|
|
117897
|
-
|
|
117898
|
-
// Initialization Vector
|
|
117899
|
-
const BLAKE2B_IV32 = new Uint32Array([
|
|
117900
|
-
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372,
|
|
117901
|
-
0x5f1d36f1, 0xa54ff53a, 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c,
|
|
117902
|
-
0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19
|
|
117903
|
-
]);
|
|
117738
|
+
function requireUtil () {
|
|
117739
|
+
if (hasRequiredUtil) return util;
|
|
117740
|
+
hasRequiredUtil = 1;
|
|
117741
|
+
const ERROR_MSG_INPUT = 'Input must be an string, Buffer or Uint8Array';
|
|
117904
117742
|
|
|
117905
|
-
|
|
117906
|
-
|
|
117907
|
-
|
|
117908
|
-
|
|
117909
|
-
|
|
117910
|
-
|
|
117911
|
-
|
|
117912
|
-
|
|
117913
|
-
|
|
117914
|
-
|
|
117915
|
-
|
|
117743
|
+
// For convenience, let people hash a string, not just a Uint8Array
|
|
117744
|
+
function normalizeInput (input) {
|
|
117745
|
+
let ret;
|
|
117746
|
+
if (input instanceof Uint8Array) {
|
|
117747
|
+
ret = input;
|
|
117748
|
+
} else if (typeof input === 'string') {
|
|
117749
|
+
const encoder = new TextEncoder();
|
|
117750
|
+
ret = encoder.encode(input);
|
|
117751
|
+
} else {
|
|
117752
|
+
throw new Error(ERROR_MSG_INPUT)
|
|
117753
|
+
}
|
|
117754
|
+
return ret
|
|
117755
|
+
}
|
|
117756
|
+
|
|
117757
|
+
// Converts a Uint8Array to a hexadecimal string
|
|
117758
|
+
// For example, toHex([255, 0, 255]) returns "ff00ff"
|
|
117759
|
+
function toHex (bytes) {
|
|
117760
|
+
return Array.prototype.map
|
|
117761
|
+
.call(bytes, function (n) {
|
|
117762
|
+
return (n < 16 ? '0' : '') + n.toString(16)
|
|
117763
|
+
})
|
|
117764
|
+
.join('')
|
|
117765
|
+
}
|
|
117766
|
+
|
|
117767
|
+
// Converts any value in [0...2^32-1] to an 8-character hex string
|
|
117768
|
+
function uint32ToHex (val) {
|
|
117769
|
+
return (0x100000000 + val).toString(16).substring(1)
|
|
117770
|
+
}
|
|
117771
|
+
|
|
117772
|
+
// For debugging: prints out hash state in the same format as the RFC
|
|
117773
|
+
// sample computation exactly, so that you can diff
|
|
117774
|
+
function debugPrint (label, arr, size) {
|
|
117775
|
+
let msg = '\n' + label + ' = ';
|
|
117776
|
+
for (let i = 0; i < arr.length; i += 2) {
|
|
117777
|
+
if (size === 32) {
|
|
117778
|
+
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117779
|
+
msg += ' ';
|
|
117780
|
+
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117781
|
+
} else if (size === 64) {
|
|
117782
|
+
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
117783
|
+
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
117784
|
+
} else throw new Error('Invalid size ' + size)
|
|
117785
|
+
if (i % 6 === 4) {
|
|
117786
|
+
msg += '\n' + new Array(label.length + 4).join(' ');
|
|
117787
|
+
} else if (i < arr.length - 2) {
|
|
117788
|
+
msg += ' ';
|
|
117789
|
+
}
|
|
117790
|
+
}
|
|
117791
|
+
console.log(msg);
|
|
117792
|
+
}
|
|
117916
117793
|
|
|
117917
|
-
//
|
|
117918
|
-
//
|
|
117919
|
-
|
|
117920
|
-
|
|
117921
|
-
SIGMA8.map(function (x) {
|
|
117922
|
-
return x * 2
|
|
117923
|
-
})
|
|
117924
|
-
);
|
|
117794
|
+
// For performance testing: generates N bytes of input, hashes M times
|
|
117795
|
+
// Measures and prints MB/second hash performance each time
|
|
117796
|
+
function testSpeed (hashFn, N, M) {
|
|
117797
|
+
let startMs = new Date().getTime();
|
|
117925
117798
|
|
|
117926
|
-
|
|
117927
|
-
|
|
117928
|
-
|
|
117929
|
-
|
|
117930
|
-
|
|
117931
|
-
|
|
117932
|
-
|
|
117933
|
-
|
|
117934
|
-
|
|
117935
|
-
|
|
117936
|
-
|
|
117937
|
-
|
|
117938
|
-
|
|
117939
|
-
|
|
117940
|
-
|
|
117941
|
-
|
|
117942
|
-
|
|
117943
|
-
|
|
117944
|
-
|
|
117945
|
-
if (last) {
|
|
117946
|
-
v$1[28] = ~v$1[28];
|
|
117947
|
-
v$1[29] = ~v$1[29];
|
|
117948
|
-
}
|
|
117949
|
-
|
|
117950
|
-
// get little-endian words
|
|
117951
|
-
for (i = 0; i < 32; i++) {
|
|
117952
|
-
m$1[i] = B2B_GET32(ctx.b, 4 * i);
|
|
117953
|
-
}
|
|
117954
|
-
|
|
117955
|
-
// twelve rounds of mixing
|
|
117956
|
-
// uncomment the DebugPrint calls to log the computation
|
|
117957
|
-
// and match the RFC sample documentation
|
|
117958
|
-
// util.debugPrint(' m[16]', m, 64)
|
|
117959
|
-
for (i = 0; i < 12; i++) {
|
|
117960
|
-
// util.debugPrint(' (i=' + (i < 10 ? ' ' : '') + i + ') v[16]', v, 64)
|
|
117961
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
117962
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
117963
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
117964
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
117965
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
117966
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
117967
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
117968
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
117969
|
-
}
|
|
117970
|
-
// util.debugPrint(' (i=12) v[16]', v, 64)
|
|
117971
|
-
|
|
117972
|
-
for (i = 0; i < 16; i++) {
|
|
117973
|
-
ctx.h[i] = ctx.h[i] ^ v$1[i] ^ v$1[i + 16];
|
|
117974
|
-
}
|
|
117975
|
-
// util.debugPrint('h[8]', ctx.h, 64)
|
|
117976
|
-
}
|
|
117977
|
-
|
|
117978
|
-
// reusable parameterBlock
|
|
117979
|
-
const parameterBlock = new Uint8Array([
|
|
117980
|
-
0,
|
|
117981
|
-
0,
|
|
117982
|
-
0,
|
|
117983
|
-
0, // 0: outlen, keylen, fanout, depth
|
|
117984
|
-
0,
|
|
117985
|
-
0,
|
|
117986
|
-
0,
|
|
117987
|
-
0, // 4: leaf length, sequential mode
|
|
117988
|
-
0,
|
|
117989
|
-
0,
|
|
117990
|
-
0,
|
|
117991
|
-
0, // 8: node offset
|
|
117992
|
-
0,
|
|
117993
|
-
0,
|
|
117994
|
-
0,
|
|
117995
|
-
0, // 12: node offset
|
|
117996
|
-
0,
|
|
117997
|
-
0,
|
|
117998
|
-
0,
|
|
117999
|
-
0, // 16: node depth, inner length, rfu
|
|
118000
|
-
0,
|
|
118001
|
-
0,
|
|
118002
|
-
0,
|
|
118003
|
-
0, // 20: rfu
|
|
118004
|
-
0,
|
|
118005
|
-
0,
|
|
118006
|
-
0,
|
|
118007
|
-
0, // 24: rfu
|
|
118008
|
-
0,
|
|
118009
|
-
0,
|
|
118010
|
-
0,
|
|
118011
|
-
0, // 28: rfu
|
|
118012
|
-
0,
|
|
118013
|
-
0,
|
|
118014
|
-
0,
|
|
118015
|
-
0, // 32: salt
|
|
118016
|
-
0,
|
|
118017
|
-
0,
|
|
118018
|
-
0,
|
|
118019
|
-
0, // 36: salt
|
|
118020
|
-
0,
|
|
118021
|
-
0,
|
|
118022
|
-
0,
|
|
118023
|
-
0, // 40: salt
|
|
118024
|
-
0,
|
|
118025
|
-
0,
|
|
118026
|
-
0,
|
|
118027
|
-
0, // 44: salt
|
|
118028
|
-
0,
|
|
118029
|
-
0,
|
|
118030
|
-
0,
|
|
118031
|
-
0, // 48: personal
|
|
118032
|
-
0,
|
|
118033
|
-
0,
|
|
118034
|
-
0,
|
|
118035
|
-
0, // 52: personal
|
|
118036
|
-
0,
|
|
118037
|
-
0,
|
|
118038
|
-
0,
|
|
118039
|
-
0, // 56: personal
|
|
118040
|
-
0,
|
|
118041
|
-
0,
|
|
118042
|
-
0,
|
|
118043
|
-
0 // 60: personal
|
|
118044
|
-
]);
|
|
117799
|
+
const input = new Uint8Array(N);
|
|
117800
|
+
for (let i = 0; i < N; i++) {
|
|
117801
|
+
input[i] = i % 256;
|
|
117802
|
+
}
|
|
117803
|
+
const genMs = new Date().getTime();
|
|
117804
|
+
console.log('Generated random input in ' + (genMs - startMs) + 'ms');
|
|
117805
|
+
startMs = genMs;
|
|
117806
|
+
|
|
117807
|
+
for (let i = 0; i < M; i++) {
|
|
117808
|
+
const hashHex = hashFn(input);
|
|
117809
|
+
const hashMs = new Date().getTime();
|
|
117810
|
+
const ms = hashMs - startMs;
|
|
117811
|
+
startMs = hashMs;
|
|
117812
|
+
console.log('Hashed in ' + ms + 'ms: ' + hashHex.substring(0, 20) + '...');
|
|
117813
|
+
console.log(
|
|
117814
|
+
Math.round((N / (1 << 20) / (ms / 1000)) * 100) / 100 + ' MB PER SECOND'
|
|
117815
|
+
);
|
|
117816
|
+
}
|
|
117817
|
+
}
|
|
118045
117818
|
|
|
118046
|
-
|
|
118047
|
-
|
|
118048
|
-
|
|
118049
|
-
|
|
118050
|
-
|
|
118051
|
-
|
|
118052
|
-
|
|
118053
|
-
|
|
118054
|
-
}
|
|
118055
|
-
if (key && key.length > 64) {
|
|
118056
|
-
throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64')
|
|
118057
|
-
}
|
|
118058
|
-
if (salt && salt.length !== 16) {
|
|
118059
|
-
throw new Error('Illegal salt, expected Uint8Array with length is 16')
|
|
118060
|
-
}
|
|
118061
|
-
if (personal && personal.length !== 16) {
|
|
118062
|
-
throw new Error('Illegal personal, expected Uint8Array with length is 16')
|
|
118063
|
-
}
|
|
118064
|
-
|
|
118065
|
-
// state, 'param block'
|
|
118066
|
-
const ctx = {
|
|
118067
|
-
b: new Uint8Array(128),
|
|
118068
|
-
h: new Uint32Array(16),
|
|
118069
|
-
t: 0, // input count
|
|
118070
|
-
c: 0, // pointer within buffer
|
|
118071
|
-
outlen: outlen // output length in bytes
|
|
118072
|
-
};
|
|
118073
|
-
|
|
118074
|
-
// initialize parameterBlock before usage
|
|
118075
|
-
parameterBlock.fill(0);
|
|
118076
|
-
parameterBlock[0] = outlen;
|
|
118077
|
-
if (key) parameterBlock[1] = key.length;
|
|
118078
|
-
parameterBlock[2] = 1; // fanout
|
|
118079
|
-
parameterBlock[3] = 1; // depth
|
|
118080
|
-
if (salt) parameterBlock.set(salt, 32);
|
|
118081
|
-
if (personal) parameterBlock.set(personal, 48);
|
|
118082
|
-
|
|
118083
|
-
// initialize hash state
|
|
118084
|
-
for (let i = 0; i < 16; i++) {
|
|
118085
|
-
ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);
|
|
118086
|
-
}
|
|
118087
|
-
|
|
118088
|
-
// key the hash, if applicable
|
|
118089
|
-
if (key) {
|
|
118090
|
-
blake2bUpdate(ctx, key);
|
|
118091
|
-
// at the end
|
|
118092
|
-
ctx.c = 128;
|
|
118093
|
-
}
|
|
118094
|
-
|
|
118095
|
-
return ctx
|
|
118096
|
-
}
|
|
118097
|
-
|
|
118098
|
-
// Updates a BLAKE2b streaming hash
|
|
118099
|
-
// Requires hash context and Uint8Array (byte array)
|
|
118100
|
-
function blake2bUpdate (ctx, input) {
|
|
118101
|
-
for (let i = 0; i < input.length; i++) {
|
|
118102
|
-
if (ctx.c === 128) {
|
|
118103
|
-
// buffer full ?
|
|
118104
|
-
ctx.t += ctx.c; // add counters
|
|
118105
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
118106
|
-
ctx.c = 0; // counter to zero
|
|
118107
|
-
}
|
|
118108
|
-
ctx.b[ctx.c++] = input[i];
|
|
118109
|
-
}
|
|
118110
|
-
}
|
|
118111
|
-
|
|
118112
|
-
// Completes a BLAKE2b streaming hash
|
|
118113
|
-
// Returns a Uint8Array containing the message digest
|
|
118114
|
-
function blake2bFinal (ctx) {
|
|
118115
|
-
ctx.t += ctx.c; // mark last block offset
|
|
118116
|
-
|
|
118117
|
-
while (ctx.c < 128) {
|
|
118118
|
-
// fill up with zeros
|
|
118119
|
-
ctx.b[ctx.c++] = 0;
|
|
118120
|
-
}
|
|
118121
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
118122
|
-
|
|
118123
|
-
// little endian convert and store
|
|
118124
|
-
const out = new Uint8Array(ctx.outlen);
|
|
118125
|
-
for (let i = 0; i < ctx.outlen; i++) {
|
|
118126
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
118127
|
-
}
|
|
118128
|
-
return out
|
|
118129
|
-
}
|
|
118130
|
-
|
|
118131
|
-
// Computes the BLAKE2B hash of a string or byte array, and returns a Uint8Array
|
|
118132
|
-
//
|
|
118133
|
-
// Returns a n-byte Uint8Array
|
|
118134
|
-
//
|
|
118135
|
-
// Parameters:
|
|
118136
|
-
// - input - the input bytes, as a string, Buffer or Uint8Array
|
|
118137
|
-
// - key - optional key Uint8Array, up to 64 bytes
|
|
118138
|
-
// - outlen - optional output length in bytes, default 64
|
|
118139
|
-
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118140
|
-
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118141
|
-
function blake2b (input, key, outlen, salt, personal) {
|
|
118142
|
-
// preprocess inputs
|
|
118143
|
-
outlen = outlen || 64;
|
|
118144
|
-
input = util$1.normalizeInput(input);
|
|
118145
|
-
if (salt) {
|
|
118146
|
-
salt = util$1.normalizeInput(salt);
|
|
118147
|
-
}
|
|
118148
|
-
if (personal) {
|
|
118149
|
-
personal = util$1.normalizeInput(personal);
|
|
118150
|
-
}
|
|
118151
|
-
|
|
118152
|
-
// do the math
|
|
118153
|
-
const ctx = blake2bInit(outlen, key, salt, personal);
|
|
118154
|
-
blake2bUpdate(ctx, input);
|
|
118155
|
-
return blake2bFinal(ctx)
|
|
118156
|
-
}
|
|
118157
|
-
|
|
118158
|
-
// Computes the BLAKE2B hash of a string or byte array
|
|
118159
|
-
//
|
|
118160
|
-
// Returns an n-byte hash in hex, all lowercase
|
|
118161
|
-
//
|
|
118162
|
-
// Parameters:
|
|
118163
|
-
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118164
|
-
// - key - optional key Uint8Array, up to 64 bytes
|
|
118165
|
-
// - outlen - optional output length in bytes, default 64
|
|
118166
|
-
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118167
|
-
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118168
|
-
function blake2bHex (input, key, outlen, salt, personal) {
|
|
118169
|
-
const output = blake2b(input, key, outlen, salt, personal);
|
|
118170
|
-
return util$1.toHex(output)
|
|
118171
|
-
}
|
|
118172
|
-
|
|
118173
|
-
var blake2b_1 = {
|
|
118174
|
-
blake2b: blake2b,
|
|
118175
|
-
blake2bHex: blake2bHex,
|
|
118176
|
-
blake2bInit: blake2bInit,
|
|
118177
|
-
blake2bUpdate: blake2bUpdate,
|
|
118178
|
-
blake2bFinal: blake2bFinal
|
|
118179
|
-
};
|
|
117819
|
+
util = {
|
|
117820
|
+
normalizeInput: normalizeInput,
|
|
117821
|
+
toHex: toHex,
|
|
117822
|
+
debugPrint: debugPrint,
|
|
117823
|
+
testSpeed: testSpeed
|
|
117824
|
+
};
|
|
117825
|
+
return util;
|
|
117826
|
+
}
|
|
118180
117827
|
|
|
118181
|
-
|
|
118182
|
-
|
|
118183
|
-
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118184
|
-
|
|
118185
|
-
const util = util$2;
|
|
118186
|
-
|
|
118187
|
-
// Little-endian byte access.
|
|
118188
|
-
// Expects a Uint8Array and an index
|
|
118189
|
-
// Returns the little-endian uint32 at v[i..i+3]
|
|
118190
|
-
function B2S_GET32 (v, i) {
|
|
118191
|
-
return v[i] ^ (v[i + 1] << 8) ^ (v[i + 2] << 16) ^ (v[i + 3] << 24)
|
|
118192
|
-
}
|
|
118193
|
-
|
|
118194
|
-
// Mixing function G.
|
|
118195
|
-
function B2S_G (a, b, c, d, x, y) {
|
|
118196
|
-
v[a] = v[a] + v[b] + x;
|
|
118197
|
-
v[d] = ROTR32(v[d] ^ v[a], 16);
|
|
118198
|
-
v[c] = v[c] + v[d];
|
|
118199
|
-
v[b] = ROTR32(v[b] ^ v[c], 12);
|
|
118200
|
-
v[a] = v[a] + v[b] + y;
|
|
118201
|
-
v[d] = ROTR32(v[d] ^ v[a], 8);
|
|
118202
|
-
v[c] = v[c] + v[d];
|
|
118203
|
-
v[b] = ROTR32(v[b] ^ v[c], 7);
|
|
118204
|
-
}
|
|
118205
|
-
|
|
118206
|
-
// 32-bit right rotation
|
|
118207
|
-
// x should be a uint32
|
|
118208
|
-
// y must be between 1 and 31, inclusive
|
|
118209
|
-
function ROTR32 (x, y) {
|
|
118210
|
-
return (x >>> y) ^ (x << (32 - y))
|
|
118211
|
-
}
|
|
118212
|
-
|
|
118213
|
-
// Initialization Vector.
|
|
118214
|
-
const BLAKE2S_IV = new Uint32Array([
|
|
118215
|
-
0x6a09e667,
|
|
118216
|
-
0xbb67ae85,
|
|
118217
|
-
0x3c6ef372,
|
|
118218
|
-
0xa54ff53a,
|
|
118219
|
-
0x510e527f,
|
|
118220
|
-
0x9b05688c,
|
|
118221
|
-
0x1f83d9ab,
|
|
118222
|
-
0x5be0cd19
|
|
118223
|
-
]);
|
|
117828
|
+
var blake2b_1;
|
|
117829
|
+
var hasRequiredBlake2b;
|
|
118224
117830
|
|
|
118225
|
-
|
|
118226
|
-
|
|
118227
|
-
|
|
118228
|
-
|
|
118229
|
-
|
|
118230
|
-
|
|
118231
|
-
5,
|
|
118232
|
-
6,
|
|
118233
|
-
7,
|
|
118234
|
-
8,
|
|
118235
|
-
9,
|
|
118236
|
-
10,
|
|
118237
|
-
11,
|
|
118238
|
-
12,
|
|
118239
|
-
13,
|
|
118240
|
-
14,
|
|
118241
|
-
15,
|
|
118242
|
-
14,
|
|
118243
|
-
10,
|
|
118244
|
-
4,
|
|
118245
|
-
8,
|
|
118246
|
-
9,
|
|
118247
|
-
15,
|
|
118248
|
-
13,
|
|
118249
|
-
6,
|
|
118250
|
-
1,
|
|
118251
|
-
12,
|
|
118252
|
-
0,
|
|
118253
|
-
2,
|
|
118254
|
-
11,
|
|
118255
|
-
7,
|
|
118256
|
-
5,
|
|
118257
|
-
3,
|
|
118258
|
-
11,
|
|
118259
|
-
8,
|
|
118260
|
-
12,
|
|
118261
|
-
0,
|
|
118262
|
-
5,
|
|
118263
|
-
2,
|
|
118264
|
-
15,
|
|
118265
|
-
13,
|
|
118266
|
-
10,
|
|
118267
|
-
14,
|
|
118268
|
-
3,
|
|
118269
|
-
6,
|
|
118270
|
-
7,
|
|
118271
|
-
1,
|
|
118272
|
-
9,
|
|
118273
|
-
4,
|
|
118274
|
-
7,
|
|
118275
|
-
9,
|
|
118276
|
-
3,
|
|
118277
|
-
1,
|
|
118278
|
-
13,
|
|
118279
|
-
12,
|
|
118280
|
-
11,
|
|
118281
|
-
14,
|
|
118282
|
-
2,
|
|
118283
|
-
6,
|
|
118284
|
-
5,
|
|
118285
|
-
10,
|
|
118286
|
-
4,
|
|
118287
|
-
0,
|
|
118288
|
-
15,
|
|
118289
|
-
8,
|
|
118290
|
-
9,
|
|
118291
|
-
0,
|
|
118292
|
-
5,
|
|
118293
|
-
7,
|
|
118294
|
-
2,
|
|
118295
|
-
4,
|
|
118296
|
-
10,
|
|
118297
|
-
15,
|
|
118298
|
-
14,
|
|
118299
|
-
1,
|
|
118300
|
-
11,
|
|
118301
|
-
12,
|
|
118302
|
-
6,
|
|
118303
|
-
8,
|
|
118304
|
-
3,
|
|
118305
|
-
13,
|
|
118306
|
-
2,
|
|
118307
|
-
12,
|
|
118308
|
-
6,
|
|
118309
|
-
10,
|
|
118310
|
-
0,
|
|
118311
|
-
11,
|
|
118312
|
-
8,
|
|
118313
|
-
3,
|
|
118314
|
-
4,
|
|
118315
|
-
13,
|
|
118316
|
-
7,
|
|
118317
|
-
5,
|
|
118318
|
-
15,
|
|
118319
|
-
14,
|
|
118320
|
-
1,
|
|
118321
|
-
9,
|
|
118322
|
-
12,
|
|
118323
|
-
5,
|
|
118324
|
-
1,
|
|
118325
|
-
15,
|
|
118326
|
-
14,
|
|
118327
|
-
13,
|
|
118328
|
-
4,
|
|
118329
|
-
10,
|
|
118330
|
-
0,
|
|
118331
|
-
7,
|
|
118332
|
-
6,
|
|
118333
|
-
3,
|
|
118334
|
-
9,
|
|
118335
|
-
2,
|
|
118336
|
-
8,
|
|
118337
|
-
11,
|
|
118338
|
-
13,
|
|
118339
|
-
11,
|
|
118340
|
-
7,
|
|
118341
|
-
14,
|
|
118342
|
-
12,
|
|
118343
|
-
1,
|
|
118344
|
-
3,
|
|
118345
|
-
9,
|
|
118346
|
-
5,
|
|
118347
|
-
0,
|
|
118348
|
-
15,
|
|
118349
|
-
4,
|
|
118350
|
-
8,
|
|
118351
|
-
6,
|
|
118352
|
-
2,
|
|
118353
|
-
10,
|
|
118354
|
-
6,
|
|
118355
|
-
15,
|
|
118356
|
-
14,
|
|
118357
|
-
9,
|
|
118358
|
-
11,
|
|
118359
|
-
3,
|
|
118360
|
-
0,
|
|
118361
|
-
8,
|
|
118362
|
-
12,
|
|
118363
|
-
2,
|
|
118364
|
-
13,
|
|
118365
|
-
7,
|
|
118366
|
-
1,
|
|
118367
|
-
4,
|
|
118368
|
-
10,
|
|
118369
|
-
5,
|
|
118370
|
-
10,
|
|
118371
|
-
2,
|
|
118372
|
-
8,
|
|
118373
|
-
4,
|
|
118374
|
-
7,
|
|
118375
|
-
6,
|
|
118376
|
-
1,
|
|
118377
|
-
5,
|
|
118378
|
-
15,
|
|
118379
|
-
11,
|
|
118380
|
-
9,
|
|
118381
|
-
14,
|
|
118382
|
-
3,
|
|
118383
|
-
12,
|
|
118384
|
-
13,
|
|
118385
|
-
0
|
|
118386
|
-
]);
|
|
117831
|
+
function requireBlake2b () {
|
|
117832
|
+
if (hasRequiredBlake2b) return blake2b_1;
|
|
117833
|
+
hasRequiredBlake2b = 1;
|
|
117834
|
+
// Blake2B in pure Javascript
|
|
117835
|
+
// Adapted from the reference implementation in RFC7693
|
|
117836
|
+
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118387
117837
|
|
|
118388
|
-
|
|
118389
|
-
const v = new Uint32Array(16);
|
|
118390
|
-
const m = new Uint32Array(16);
|
|
118391
|
-
function blake2sCompress (ctx, last) {
|
|
118392
|
-
let i = 0;
|
|
118393
|
-
for (i = 0; i < 8; i++) {
|
|
118394
|
-
// init work variables
|
|
118395
|
-
v[i] = ctx.h[i];
|
|
118396
|
-
v[i + 8] = BLAKE2S_IV[i];
|
|
118397
|
-
}
|
|
118398
|
-
|
|
118399
|
-
v[12] ^= ctx.t; // low 32 bits of offset
|
|
118400
|
-
v[13] ^= ctx.t / 0x100000000; // high 32 bits
|
|
118401
|
-
if (last) {
|
|
118402
|
-
// last block flag set ?
|
|
118403
|
-
v[14] = ~v[14];
|
|
118404
|
-
}
|
|
118405
|
-
|
|
118406
|
-
for (i = 0; i < 16; i++) {
|
|
118407
|
-
// get little-endian words
|
|
118408
|
-
m[i] = B2S_GET32(ctx.b, 4 * i);
|
|
118409
|
-
}
|
|
118410
|
-
|
|
118411
|
-
// ten rounds of mixing
|
|
118412
|
-
// uncomment the DebugPrint calls to log the computation
|
|
118413
|
-
// and match the RFC sample documentation
|
|
118414
|
-
// util.debugPrint(' m[16]', m, 32)
|
|
118415
|
-
for (i = 0; i < 10; i++) {
|
|
118416
|
-
// util.debugPrint(' (i=' + i + ') v[16]', v, 32)
|
|
118417
|
-
B2S_G(0, 4, 8, 12, m[SIGMA[i * 16 + 0]], m[SIGMA[i * 16 + 1]]);
|
|
118418
|
-
B2S_G(1, 5, 9, 13, m[SIGMA[i * 16 + 2]], m[SIGMA[i * 16 + 3]]);
|
|
118419
|
-
B2S_G(2, 6, 10, 14, m[SIGMA[i * 16 + 4]], m[SIGMA[i * 16 + 5]]);
|
|
118420
|
-
B2S_G(3, 7, 11, 15, m[SIGMA[i * 16 + 6]], m[SIGMA[i * 16 + 7]]);
|
|
118421
|
-
B2S_G(0, 5, 10, 15, m[SIGMA[i * 16 + 8]], m[SIGMA[i * 16 + 9]]);
|
|
118422
|
-
B2S_G(1, 6, 11, 12, m[SIGMA[i * 16 + 10]], m[SIGMA[i * 16 + 11]]);
|
|
118423
|
-
B2S_G(2, 7, 8, 13, m[SIGMA[i * 16 + 12]], m[SIGMA[i * 16 + 13]]);
|
|
118424
|
-
B2S_G(3, 4, 9, 14, m[SIGMA[i * 16 + 14]], m[SIGMA[i * 16 + 15]]);
|
|
118425
|
-
}
|
|
118426
|
-
// util.debugPrint(' (i=10) v[16]', v, 32)
|
|
118427
|
-
|
|
118428
|
-
for (i = 0; i < 8; i++) {
|
|
118429
|
-
ctx.h[i] ^= v[i] ^ v[i + 8];
|
|
118430
|
-
}
|
|
118431
|
-
// util.debugPrint('h[8]', ctx.h, 32)
|
|
118432
|
-
}
|
|
118433
|
-
|
|
118434
|
-
// Creates a BLAKE2s hashing context
|
|
118435
|
-
// Requires an output length between 1 and 32 bytes
|
|
118436
|
-
// Takes an optional Uint8Array key
|
|
118437
|
-
function blake2sInit (outlen, key) {
|
|
118438
|
-
if (!(outlen > 0 && outlen <= 32)) {
|
|
118439
|
-
throw new Error('Incorrect output length, should be in [1, 32]')
|
|
118440
|
-
}
|
|
118441
|
-
const keylen = key ? key.length : 0;
|
|
118442
|
-
if (key && !(keylen > 0 && keylen <= 32)) {
|
|
118443
|
-
throw new Error('Incorrect key length, should be in [1, 32]')
|
|
118444
|
-
}
|
|
118445
|
-
|
|
118446
|
-
const ctx = {
|
|
118447
|
-
h: new Uint32Array(BLAKE2S_IV), // hash state
|
|
118448
|
-
b: new Uint8Array(64), // input block
|
|
118449
|
-
c: 0, // pointer within block
|
|
118450
|
-
t: 0, // input count
|
|
118451
|
-
outlen: outlen // output length in bytes
|
|
118452
|
-
};
|
|
118453
|
-
ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen;
|
|
118454
|
-
|
|
118455
|
-
if (keylen > 0) {
|
|
118456
|
-
blake2sUpdate(ctx, key);
|
|
118457
|
-
ctx.c = 64; // at the end
|
|
118458
|
-
}
|
|
118459
|
-
|
|
118460
|
-
return ctx
|
|
118461
|
-
}
|
|
118462
|
-
|
|
118463
|
-
// Updates a BLAKE2s streaming hash
|
|
118464
|
-
// Requires hash context and Uint8Array (byte array)
|
|
118465
|
-
function blake2sUpdate (ctx, input) {
|
|
118466
|
-
for (let i = 0; i < input.length; i++) {
|
|
118467
|
-
if (ctx.c === 64) {
|
|
118468
|
-
// buffer full ?
|
|
118469
|
-
ctx.t += ctx.c; // add counters
|
|
118470
|
-
blake2sCompress(ctx, false); // compress (not last)
|
|
118471
|
-
ctx.c = 0; // counter to zero
|
|
118472
|
-
}
|
|
118473
|
-
ctx.b[ctx.c++] = input[i];
|
|
118474
|
-
}
|
|
118475
|
-
}
|
|
118476
|
-
|
|
118477
|
-
// Completes a BLAKE2s streaming hash
|
|
118478
|
-
// Returns a Uint8Array containing the message digest
|
|
118479
|
-
function blake2sFinal (ctx) {
|
|
118480
|
-
ctx.t += ctx.c; // mark last block offset
|
|
118481
|
-
while (ctx.c < 64) {
|
|
118482
|
-
// fill up with zeros
|
|
118483
|
-
ctx.b[ctx.c++] = 0;
|
|
118484
|
-
}
|
|
118485
|
-
blake2sCompress(ctx, true); // final block flag = 1
|
|
118486
|
-
|
|
118487
|
-
// little endian convert and store
|
|
118488
|
-
const out = new Uint8Array(ctx.outlen);
|
|
118489
|
-
for (let i = 0; i < ctx.outlen; i++) {
|
|
118490
|
-
out[i] = (ctx.h[i >> 2] >> (8 * (i & 3))) & 0xff;
|
|
118491
|
-
}
|
|
118492
|
-
return out
|
|
118493
|
-
}
|
|
118494
|
-
|
|
118495
|
-
// Computes the BLAKE2S hash of a string or byte array, and returns a Uint8Array
|
|
118496
|
-
//
|
|
118497
|
-
// Returns a n-byte Uint8Array
|
|
118498
|
-
//
|
|
118499
|
-
// Parameters:
|
|
118500
|
-
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118501
|
-
// - key - optional key Uint8Array, up to 32 bytes
|
|
118502
|
-
// - outlen - optional output length in bytes, default 64
|
|
118503
|
-
function blake2s (input, key, outlen) {
|
|
118504
|
-
// preprocess inputs
|
|
118505
|
-
outlen = outlen || 32;
|
|
118506
|
-
input = util.normalizeInput(input);
|
|
118507
|
-
|
|
118508
|
-
// do the math
|
|
118509
|
-
const ctx = blake2sInit(outlen, key);
|
|
118510
|
-
blake2sUpdate(ctx, input);
|
|
118511
|
-
return blake2sFinal(ctx)
|
|
118512
|
-
}
|
|
118513
|
-
|
|
118514
|
-
// Computes the BLAKE2S hash of a string or byte array
|
|
118515
|
-
//
|
|
118516
|
-
// Returns an n-byte hash in hex, all lowercase
|
|
118517
|
-
//
|
|
118518
|
-
// Parameters:
|
|
118519
|
-
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118520
|
-
// - key - optional key Uint8Array, up to 32 bytes
|
|
118521
|
-
// - outlen - optional output length in bytes, default 64
|
|
118522
|
-
function blake2sHex (input, key, outlen) {
|
|
118523
|
-
const output = blake2s(input, key, outlen);
|
|
118524
|
-
return util.toHex(output)
|
|
118525
|
-
}
|
|
118526
|
-
|
|
118527
|
-
var blake2s_1 = {
|
|
118528
|
-
blake2s: blake2s,
|
|
118529
|
-
blake2sHex: blake2sHex,
|
|
118530
|
-
blake2sInit: blake2sInit,
|
|
118531
|
-
blake2sUpdate: blake2sUpdate,
|
|
118532
|
-
blake2sFinal: blake2sFinal
|
|
118533
|
-
};
|
|
117838
|
+
const util = requireUtil();
|
|
118534
117839
|
|
|
118535
|
-
|
|
118536
|
-
|
|
118537
|
-
|
|
118538
|
-
|
|
118539
|
-
|
|
118540
|
-
|
|
118541
|
-
|
|
118542
|
-
|
|
118543
|
-
|
|
118544
|
-
|
|
118545
|
-
|
|
118546
|
-
|
|
118547
|
-
|
|
118548
|
-
|
|
118549
|
-
|
|
117840
|
+
// 64-bit unsigned addition
|
|
117841
|
+
// Sets v[a,a+1] += v[b,b+1]
|
|
117842
|
+
// v should be a Uint32Array
|
|
117843
|
+
function ADD64AA (v, a, b) {
|
|
117844
|
+
const o0 = v[a] + v[b];
|
|
117845
|
+
let o1 = v[a + 1] + v[b + 1];
|
|
117846
|
+
if (o0 >= 0x100000000) {
|
|
117847
|
+
o1++;
|
|
117848
|
+
}
|
|
117849
|
+
v[a] = o0;
|
|
117850
|
+
v[a + 1] = o1;
|
|
117851
|
+
}
|
|
117852
|
+
|
|
117853
|
+
// 64-bit unsigned addition
|
|
117854
|
+
// Sets v[a,a+1] += b
|
|
117855
|
+
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
117856
|
+
function ADD64AC (v, a, b0, b1) {
|
|
117857
|
+
let o0 = v[a] + b0;
|
|
117858
|
+
if (b0 < 0) {
|
|
117859
|
+
o0 += 0x100000000;
|
|
117860
|
+
}
|
|
117861
|
+
let o1 = v[a + 1] + b1;
|
|
117862
|
+
if (o0 >= 0x100000000) {
|
|
117863
|
+
o1++;
|
|
117864
|
+
}
|
|
117865
|
+
v[a] = o0;
|
|
117866
|
+
v[a + 1] = o1;
|
|
117867
|
+
}
|
|
117868
|
+
|
|
117869
|
+
// Little-endian byte access
|
|
117870
|
+
function B2B_GET32 (arr, i) {
|
|
117871
|
+
return arr[i] ^ (arr[i + 1] << 8) ^ (arr[i + 2] << 16) ^ (arr[i + 3] << 24)
|
|
117872
|
+
}
|
|
117873
|
+
|
|
117874
|
+
// G Mixing function
|
|
117875
|
+
// The ROTRs are inlined for speed
|
|
117876
|
+
function B2B_G (a, b, c, d, ix, iy) {
|
|
117877
|
+
const x0 = m[ix];
|
|
117878
|
+
const x1 = m[ix + 1];
|
|
117879
|
+
const y0 = m[iy];
|
|
117880
|
+
const y1 = m[iy + 1];
|
|
117881
|
+
|
|
117882
|
+
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
117883
|
+
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
117884
|
+
|
|
117885
|
+
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
117886
|
+
let xor0 = v[d] ^ v[a];
|
|
117887
|
+
let xor1 = v[d + 1] ^ v[a + 1];
|
|
117888
|
+
v[d] = xor1;
|
|
117889
|
+
v[d + 1] = xor0;
|
|
117890
|
+
|
|
117891
|
+
ADD64AA(v, c, d);
|
|
117892
|
+
|
|
117893
|
+
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
117894
|
+
xor0 = v[b] ^ v[c];
|
|
117895
|
+
xor1 = v[b + 1] ^ v[c + 1];
|
|
117896
|
+
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
117897
|
+
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
117898
|
+
|
|
117899
|
+
ADD64AA(v, a, b);
|
|
117900
|
+
ADD64AC(v, a, y0, y1);
|
|
117901
|
+
|
|
117902
|
+
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
117903
|
+
xor0 = v[d] ^ v[a];
|
|
117904
|
+
xor1 = v[d + 1] ^ v[a + 1];
|
|
117905
|
+
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
117906
|
+
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
117907
|
+
|
|
117908
|
+
ADD64AA(v, c, d);
|
|
117909
|
+
|
|
117910
|
+
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
117911
|
+
xor0 = v[b] ^ v[c];
|
|
117912
|
+
xor1 = v[b + 1] ^ v[c + 1];
|
|
117913
|
+
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
117914
|
+
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
117915
|
+
}
|
|
117916
|
+
|
|
117917
|
+
// Initialization Vector
|
|
117918
|
+
const BLAKE2B_IV32 = new Uint32Array([
|
|
117919
|
+
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372,
|
|
117920
|
+
0x5f1d36f1, 0xa54ff53a, 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c,
|
|
117921
|
+
0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19
|
|
117922
|
+
]);
|
|
117923
|
+
|
|
117924
|
+
const SIGMA8 = [
|
|
117925
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13,
|
|
117926
|
+
6, 1, 12, 0, 2, 11, 7, 5, 3, 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1,
|
|
117927
|
+
9, 4, 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8, 9, 0, 5, 7, 2, 4,
|
|
117928
|
+
10, 15, 14, 1, 11, 12, 6, 8, 3, 13, 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5,
|
|
117929
|
+
15, 14, 1, 9, 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11, 13, 11, 7,
|
|
117930
|
+
14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10, 6, 15, 14, 9, 11, 3, 0, 8, 12, 2,
|
|
117931
|
+
13, 7, 1, 4, 10, 5, 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0, 0,
|
|
117932
|
+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13, 6,
|
|
117933
|
+
1, 12, 0, 2, 11, 7, 5, 3
|
|
117934
|
+
];
|
|
117935
|
+
|
|
117936
|
+
// These are offsets into a uint64 buffer.
|
|
117937
|
+
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
117938
|
+
// because this is Javascript and we don't have uint64s
|
|
117939
|
+
const SIGMA82 = new Uint8Array(
|
|
117940
|
+
SIGMA8.map(function (x) {
|
|
117941
|
+
return x * 2
|
|
117942
|
+
})
|
|
117943
|
+
);
|
|
117944
|
+
|
|
117945
|
+
// Compression function. 'last' flag indicates last block.
|
|
117946
|
+
// Note we're representing 16 uint64s as 32 uint32s
|
|
117947
|
+
const v = new Uint32Array(32);
|
|
117948
|
+
const m = new Uint32Array(32);
|
|
117949
|
+
function blake2bCompress (ctx, last) {
|
|
117950
|
+
let i = 0;
|
|
117951
|
+
|
|
117952
|
+
// init work variables
|
|
117953
|
+
for (i = 0; i < 16; i++) {
|
|
117954
|
+
v[i] = ctx.h[i];
|
|
117955
|
+
v[i + 16] = BLAKE2B_IV32[i];
|
|
117956
|
+
}
|
|
117957
|
+
|
|
117958
|
+
// low 64 bits of offset
|
|
117959
|
+
v[24] = v[24] ^ ctx.t;
|
|
117960
|
+
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
117961
|
+
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
117962
|
+
|
|
117963
|
+
// last block flag set ?
|
|
117964
|
+
if (last) {
|
|
117965
|
+
v[28] = ~v[28];
|
|
117966
|
+
v[29] = ~v[29];
|
|
117967
|
+
}
|
|
117968
|
+
|
|
117969
|
+
// get little-endian words
|
|
117970
|
+
for (i = 0; i < 32; i++) {
|
|
117971
|
+
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
117972
|
+
}
|
|
117973
|
+
|
|
117974
|
+
// twelve rounds of mixing
|
|
117975
|
+
// uncomment the DebugPrint calls to log the computation
|
|
117976
|
+
// and match the RFC sample documentation
|
|
117977
|
+
// util.debugPrint(' m[16]', m, 64)
|
|
117978
|
+
for (i = 0; i < 12; i++) {
|
|
117979
|
+
// util.debugPrint(' (i=' + (i < 10 ? ' ' : '') + i + ') v[16]', v, 64)
|
|
117980
|
+
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
117981
|
+
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
117982
|
+
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
117983
|
+
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
117984
|
+
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
117985
|
+
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
117986
|
+
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
117987
|
+
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
117988
|
+
}
|
|
117989
|
+
// util.debugPrint(' (i=12) v[16]', v, 64)
|
|
117990
|
+
|
|
117991
|
+
for (i = 0; i < 16; i++) {
|
|
117992
|
+
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
117993
|
+
}
|
|
117994
|
+
// util.debugPrint('h[8]', ctx.h, 64)
|
|
117995
|
+
}
|
|
117996
|
+
|
|
117997
|
+
// reusable parameterBlock
|
|
117998
|
+
const parameterBlock = new Uint8Array([
|
|
117999
|
+
0,
|
|
118000
|
+
0,
|
|
118001
|
+
0,
|
|
118002
|
+
0, // 0: outlen, keylen, fanout, depth
|
|
118003
|
+
0,
|
|
118004
|
+
0,
|
|
118005
|
+
0,
|
|
118006
|
+
0, // 4: leaf length, sequential mode
|
|
118007
|
+
0,
|
|
118008
|
+
0,
|
|
118009
|
+
0,
|
|
118010
|
+
0, // 8: node offset
|
|
118011
|
+
0,
|
|
118012
|
+
0,
|
|
118013
|
+
0,
|
|
118014
|
+
0, // 12: node offset
|
|
118015
|
+
0,
|
|
118016
|
+
0,
|
|
118017
|
+
0,
|
|
118018
|
+
0, // 16: node depth, inner length, rfu
|
|
118019
|
+
0,
|
|
118020
|
+
0,
|
|
118021
|
+
0,
|
|
118022
|
+
0, // 20: rfu
|
|
118023
|
+
0,
|
|
118024
|
+
0,
|
|
118025
|
+
0,
|
|
118026
|
+
0, // 24: rfu
|
|
118027
|
+
0,
|
|
118028
|
+
0,
|
|
118029
|
+
0,
|
|
118030
|
+
0, // 28: rfu
|
|
118031
|
+
0,
|
|
118032
|
+
0,
|
|
118033
|
+
0,
|
|
118034
|
+
0, // 32: salt
|
|
118035
|
+
0,
|
|
118036
|
+
0,
|
|
118037
|
+
0,
|
|
118038
|
+
0, // 36: salt
|
|
118039
|
+
0,
|
|
118040
|
+
0,
|
|
118041
|
+
0,
|
|
118042
|
+
0, // 40: salt
|
|
118043
|
+
0,
|
|
118044
|
+
0,
|
|
118045
|
+
0,
|
|
118046
|
+
0, // 44: salt
|
|
118047
|
+
0,
|
|
118048
|
+
0,
|
|
118049
|
+
0,
|
|
118050
|
+
0, // 48: personal
|
|
118051
|
+
0,
|
|
118052
|
+
0,
|
|
118053
|
+
0,
|
|
118054
|
+
0, // 52: personal
|
|
118055
|
+
0,
|
|
118056
|
+
0,
|
|
118057
|
+
0,
|
|
118058
|
+
0, // 56: personal
|
|
118059
|
+
0,
|
|
118060
|
+
0,
|
|
118061
|
+
0,
|
|
118062
|
+
0 // 60: personal
|
|
118063
|
+
]);
|
|
118064
|
+
|
|
118065
|
+
// Creates a BLAKE2b hashing context
|
|
118066
|
+
// Requires an output length between 1 and 64 bytes
|
|
118067
|
+
// Takes an optional Uint8Array key
|
|
118068
|
+
// Takes an optinal Uint8Array salt
|
|
118069
|
+
// Takes an optinal Uint8Array personal
|
|
118070
|
+
function blake2bInit (outlen, key, salt, personal) {
|
|
118071
|
+
if (outlen === 0 || outlen > 64) {
|
|
118072
|
+
throw new Error('Illegal output length, expected 0 < length <= 64')
|
|
118073
|
+
}
|
|
118074
|
+
if (key && key.length > 64) {
|
|
118075
|
+
throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64')
|
|
118076
|
+
}
|
|
118077
|
+
if (salt && salt.length !== 16) {
|
|
118078
|
+
throw new Error('Illegal salt, expected Uint8Array with length is 16')
|
|
118079
|
+
}
|
|
118080
|
+
if (personal && personal.length !== 16) {
|
|
118081
|
+
throw new Error('Illegal personal, expected Uint8Array with length is 16')
|
|
118082
|
+
}
|
|
118083
|
+
|
|
118084
|
+
// state, 'param block'
|
|
118085
|
+
const ctx = {
|
|
118086
|
+
b: new Uint8Array(128),
|
|
118087
|
+
h: new Uint32Array(16),
|
|
118088
|
+
t: 0, // input count
|
|
118089
|
+
c: 0, // pointer within buffer
|
|
118090
|
+
outlen: outlen // output length in bytes
|
|
118091
|
+
};
|
|
118092
|
+
|
|
118093
|
+
// initialize parameterBlock before usage
|
|
118094
|
+
parameterBlock.fill(0);
|
|
118095
|
+
parameterBlock[0] = outlen;
|
|
118096
|
+
if (key) parameterBlock[1] = key.length;
|
|
118097
|
+
parameterBlock[2] = 1; // fanout
|
|
118098
|
+
parameterBlock[3] = 1; // depth
|
|
118099
|
+
if (salt) parameterBlock.set(salt, 32);
|
|
118100
|
+
if (personal) parameterBlock.set(personal, 48);
|
|
118101
|
+
|
|
118102
|
+
// initialize hash state
|
|
118103
|
+
for (let i = 0; i < 16; i++) {
|
|
118104
|
+
ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);
|
|
118105
|
+
}
|
|
118106
|
+
|
|
118107
|
+
// key the hash, if applicable
|
|
118108
|
+
if (key) {
|
|
118109
|
+
blake2bUpdate(ctx, key);
|
|
118110
|
+
// at the end
|
|
118111
|
+
ctx.c = 128;
|
|
118112
|
+
}
|
|
118113
|
+
|
|
118114
|
+
return ctx
|
|
118115
|
+
}
|
|
118116
|
+
|
|
118117
|
+
// Updates a BLAKE2b streaming hash
|
|
118118
|
+
// Requires hash context and Uint8Array (byte array)
|
|
118119
|
+
function blake2bUpdate (ctx, input) {
|
|
118120
|
+
for (let i = 0; i < input.length; i++) {
|
|
118121
|
+
if (ctx.c === 128) {
|
|
118122
|
+
// buffer full ?
|
|
118123
|
+
ctx.t += ctx.c; // add counters
|
|
118124
|
+
blake2bCompress(ctx, false); // compress (not last)
|
|
118125
|
+
ctx.c = 0; // counter to zero
|
|
118126
|
+
}
|
|
118127
|
+
ctx.b[ctx.c++] = input[i];
|
|
118128
|
+
}
|
|
118129
|
+
}
|
|
118130
|
+
|
|
118131
|
+
// Completes a BLAKE2b streaming hash
|
|
118132
|
+
// Returns a Uint8Array containing the message digest
|
|
118133
|
+
function blake2bFinal (ctx) {
|
|
118134
|
+
ctx.t += ctx.c; // mark last block offset
|
|
118135
|
+
|
|
118136
|
+
while (ctx.c < 128) {
|
|
118137
|
+
// fill up with zeros
|
|
118138
|
+
ctx.b[ctx.c++] = 0;
|
|
118139
|
+
}
|
|
118140
|
+
blake2bCompress(ctx, true); // final block flag = 1
|
|
118141
|
+
|
|
118142
|
+
// little endian convert and store
|
|
118143
|
+
const out = new Uint8Array(ctx.outlen);
|
|
118144
|
+
for (let i = 0; i < ctx.outlen; i++) {
|
|
118145
|
+
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
118146
|
+
}
|
|
118147
|
+
return out
|
|
118148
|
+
}
|
|
118149
|
+
|
|
118150
|
+
// Computes the BLAKE2B hash of a string or byte array, and returns a Uint8Array
|
|
118151
|
+
//
|
|
118152
|
+
// Returns a n-byte Uint8Array
|
|
118153
|
+
//
|
|
118154
|
+
// Parameters:
|
|
118155
|
+
// - input - the input bytes, as a string, Buffer or Uint8Array
|
|
118156
|
+
// - key - optional key Uint8Array, up to 64 bytes
|
|
118157
|
+
// - outlen - optional output length in bytes, default 64
|
|
118158
|
+
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118159
|
+
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118160
|
+
function blake2b (input, key, outlen, salt, personal) {
|
|
118161
|
+
// preprocess inputs
|
|
118162
|
+
outlen = outlen || 64;
|
|
118163
|
+
input = util.normalizeInput(input);
|
|
118164
|
+
if (salt) {
|
|
118165
|
+
salt = util.normalizeInput(salt);
|
|
118166
|
+
}
|
|
118167
|
+
if (personal) {
|
|
118168
|
+
personal = util.normalizeInput(personal);
|
|
118169
|
+
}
|
|
118170
|
+
|
|
118171
|
+
// do the math
|
|
118172
|
+
const ctx = blake2bInit(outlen, key, salt, personal);
|
|
118173
|
+
blake2bUpdate(ctx, input);
|
|
118174
|
+
return blake2bFinal(ctx)
|
|
118175
|
+
}
|
|
118176
|
+
|
|
118177
|
+
// Computes the BLAKE2B hash of a string or byte array
|
|
118178
|
+
//
|
|
118179
|
+
// Returns an n-byte hash in hex, all lowercase
|
|
118180
|
+
//
|
|
118181
|
+
// Parameters:
|
|
118182
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118183
|
+
// - key - optional key Uint8Array, up to 64 bytes
|
|
118184
|
+
// - outlen - optional output length in bytes, default 64
|
|
118185
|
+
// - salt - optional salt bytes, string, Buffer or Uint8Array
|
|
118186
|
+
// - personal - optional personal bytes, string, Buffer or Uint8Array
|
|
118187
|
+
function blake2bHex (input, key, outlen, salt, personal) {
|
|
118188
|
+
const output = blake2b(input, key, outlen, salt, personal);
|
|
118189
|
+
return util.toHex(output)
|
|
118190
|
+
}
|
|
118191
|
+
|
|
118192
|
+
blake2b_1 = {
|
|
118193
|
+
blake2b: blake2b,
|
|
118194
|
+
blake2bHex: blake2bHex,
|
|
118195
|
+
blake2bInit: blake2bInit,
|
|
118196
|
+
blake2bUpdate: blake2bUpdate,
|
|
118197
|
+
blake2bFinal: blake2bFinal
|
|
118198
|
+
};
|
|
118199
|
+
return blake2b_1;
|
|
118200
|
+
}
|
|
118201
|
+
|
|
118202
|
+
var blake2s_1;
|
|
118203
|
+
var hasRequiredBlake2s;
|
|
118204
|
+
|
|
118205
|
+
function requireBlake2s () {
|
|
118206
|
+
if (hasRequiredBlake2s) return blake2s_1;
|
|
118207
|
+
hasRequiredBlake2s = 1;
|
|
118208
|
+
// BLAKE2s hash function in pure Javascript
|
|
118209
|
+
// Adapted from the reference implementation in RFC7693
|
|
118210
|
+
// Ported to Javascript by DC - https://github.com/dcposch
|
|
118211
|
+
|
|
118212
|
+
const util = requireUtil();
|
|
118213
|
+
|
|
118214
|
+
// Little-endian byte access.
|
|
118215
|
+
// Expects a Uint8Array and an index
|
|
118216
|
+
// Returns the little-endian uint32 at v[i..i+3]
|
|
118217
|
+
function B2S_GET32 (v, i) {
|
|
118218
|
+
return v[i] ^ (v[i + 1] << 8) ^ (v[i + 2] << 16) ^ (v[i + 3] << 24)
|
|
118219
|
+
}
|
|
118220
|
+
|
|
118221
|
+
// Mixing function G.
|
|
118222
|
+
function B2S_G (a, b, c, d, x, y) {
|
|
118223
|
+
v[a] = v[a] + v[b] + x;
|
|
118224
|
+
v[d] = ROTR32(v[d] ^ v[a], 16);
|
|
118225
|
+
v[c] = v[c] + v[d];
|
|
118226
|
+
v[b] = ROTR32(v[b] ^ v[c], 12);
|
|
118227
|
+
v[a] = v[a] + v[b] + y;
|
|
118228
|
+
v[d] = ROTR32(v[d] ^ v[a], 8);
|
|
118229
|
+
v[c] = v[c] + v[d];
|
|
118230
|
+
v[b] = ROTR32(v[b] ^ v[c], 7);
|
|
118231
|
+
}
|
|
118232
|
+
|
|
118233
|
+
// 32-bit right rotation
|
|
118234
|
+
// x should be a uint32
|
|
118235
|
+
// y must be between 1 and 31, inclusive
|
|
118236
|
+
function ROTR32 (x, y) {
|
|
118237
|
+
return (x >>> y) ^ (x << (32 - y))
|
|
118238
|
+
}
|
|
118239
|
+
|
|
118240
|
+
// Initialization Vector.
|
|
118241
|
+
const BLAKE2S_IV = new Uint32Array([
|
|
118242
|
+
0x6a09e667,
|
|
118243
|
+
0xbb67ae85,
|
|
118244
|
+
0x3c6ef372,
|
|
118245
|
+
0xa54ff53a,
|
|
118246
|
+
0x510e527f,
|
|
118247
|
+
0x9b05688c,
|
|
118248
|
+
0x1f83d9ab,
|
|
118249
|
+
0x5be0cd19
|
|
118250
|
+
]);
|
|
118251
|
+
|
|
118252
|
+
const SIGMA = new Uint8Array([
|
|
118253
|
+
0,
|
|
118254
|
+
1,
|
|
118255
|
+
2,
|
|
118256
|
+
3,
|
|
118257
|
+
4,
|
|
118258
|
+
5,
|
|
118259
|
+
6,
|
|
118260
|
+
7,
|
|
118261
|
+
8,
|
|
118262
|
+
9,
|
|
118263
|
+
10,
|
|
118264
|
+
11,
|
|
118265
|
+
12,
|
|
118266
|
+
13,
|
|
118267
|
+
14,
|
|
118268
|
+
15,
|
|
118269
|
+
14,
|
|
118270
|
+
10,
|
|
118271
|
+
4,
|
|
118272
|
+
8,
|
|
118273
|
+
9,
|
|
118274
|
+
15,
|
|
118275
|
+
13,
|
|
118276
|
+
6,
|
|
118277
|
+
1,
|
|
118278
|
+
12,
|
|
118279
|
+
0,
|
|
118280
|
+
2,
|
|
118281
|
+
11,
|
|
118282
|
+
7,
|
|
118283
|
+
5,
|
|
118284
|
+
3,
|
|
118285
|
+
11,
|
|
118286
|
+
8,
|
|
118287
|
+
12,
|
|
118288
|
+
0,
|
|
118289
|
+
5,
|
|
118290
|
+
2,
|
|
118291
|
+
15,
|
|
118292
|
+
13,
|
|
118293
|
+
10,
|
|
118294
|
+
14,
|
|
118295
|
+
3,
|
|
118296
|
+
6,
|
|
118297
|
+
7,
|
|
118298
|
+
1,
|
|
118299
|
+
9,
|
|
118300
|
+
4,
|
|
118301
|
+
7,
|
|
118302
|
+
9,
|
|
118303
|
+
3,
|
|
118304
|
+
1,
|
|
118305
|
+
13,
|
|
118306
|
+
12,
|
|
118307
|
+
11,
|
|
118308
|
+
14,
|
|
118309
|
+
2,
|
|
118310
|
+
6,
|
|
118311
|
+
5,
|
|
118312
|
+
10,
|
|
118313
|
+
4,
|
|
118314
|
+
0,
|
|
118315
|
+
15,
|
|
118316
|
+
8,
|
|
118317
|
+
9,
|
|
118318
|
+
0,
|
|
118319
|
+
5,
|
|
118320
|
+
7,
|
|
118321
|
+
2,
|
|
118322
|
+
4,
|
|
118323
|
+
10,
|
|
118324
|
+
15,
|
|
118325
|
+
14,
|
|
118326
|
+
1,
|
|
118327
|
+
11,
|
|
118328
|
+
12,
|
|
118329
|
+
6,
|
|
118330
|
+
8,
|
|
118331
|
+
3,
|
|
118332
|
+
13,
|
|
118333
|
+
2,
|
|
118334
|
+
12,
|
|
118335
|
+
6,
|
|
118336
|
+
10,
|
|
118337
|
+
0,
|
|
118338
|
+
11,
|
|
118339
|
+
8,
|
|
118340
|
+
3,
|
|
118341
|
+
4,
|
|
118342
|
+
13,
|
|
118343
|
+
7,
|
|
118344
|
+
5,
|
|
118345
|
+
15,
|
|
118346
|
+
14,
|
|
118347
|
+
1,
|
|
118348
|
+
9,
|
|
118349
|
+
12,
|
|
118350
|
+
5,
|
|
118351
|
+
1,
|
|
118352
|
+
15,
|
|
118353
|
+
14,
|
|
118354
|
+
13,
|
|
118355
|
+
4,
|
|
118356
|
+
10,
|
|
118357
|
+
0,
|
|
118358
|
+
7,
|
|
118359
|
+
6,
|
|
118360
|
+
3,
|
|
118361
|
+
9,
|
|
118362
|
+
2,
|
|
118363
|
+
8,
|
|
118364
|
+
11,
|
|
118365
|
+
13,
|
|
118366
|
+
11,
|
|
118367
|
+
7,
|
|
118368
|
+
14,
|
|
118369
|
+
12,
|
|
118370
|
+
1,
|
|
118371
|
+
3,
|
|
118372
|
+
9,
|
|
118373
|
+
5,
|
|
118374
|
+
0,
|
|
118375
|
+
15,
|
|
118376
|
+
4,
|
|
118377
|
+
8,
|
|
118378
|
+
6,
|
|
118379
|
+
2,
|
|
118380
|
+
10,
|
|
118381
|
+
6,
|
|
118382
|
+
15,
|
|
118383
|
+
14,
|
|
118384
|
+
9,
|
|
118385
|
+
11,
|
|
118386
|
+
3,
|
|
118387
|
+
0,
|
|
118388
|
+
8,
|
|
118389
|
+
12,
|
|
118390
|
+
2,
|
|
118391
|
+
13,
|
|
118392
|
+
7,
|
|
118393
|
+
1,
|
|
118394
|
+
4,
|
|
118395
|
+
10,
|
|
118396
|
+
5,
|
|
118397
|
+
10,
|
|
118398
|
+
2,
|
|
118399
|
+
8,
|
|
118400
|
+
4,
|
|
118401
|
+
7,
|
|
118402
|
+
6,
|
|
118403
|
+
1,
|
|
118404
|
+
5,
|
|
118405
|
+
15,
|
|
118406
|
+
11,
|
|
118407
|
+
9,
|
|
118408
|
+
14,
|
|
118409
|
+
3,
|
|
118410
|
+
12,
|
|
118411
|
+
13,
|
|
118412
|
+
0
|
|
118413
|
+
]);
|
|
118414
|
+
|
|
118415
|
+
// Compression function. "last" flag indicates last block
|
|
118416
|
+
const v = new Uint32Array(16);
|
|
118417
|
+
const m = new Uint32Array(16);
|
|
118418
|
+
function blake2sCompress (ctx, last) {
|
|
118419
|
+
let i = 0;
|
|
118420
|
+
for (i = 0; i < 8; i++) {
|
|
118421
|
+
// init work variables
|
|
118422
|
+
v[i] = ctx.h[i];
|
|
118423
|
+
v[i + 8] = BLAKE2S_IV[i];
|
|
118424
|
+
}
|
|
118425
|
+
|
|
118426
|
+
v[12] ^= ctx.t; // low 32 bits of offset
|
|
118427
|
+
v[13] ^= ctx.t / 0x100000000; // high 32 bits
|
|
118428
|
+
if (last) {
|
|
118429
|
+
// last block flag set ?
|
|
118430
|
+
v[14] = ~v[14];
|
|
118431
|
+
}
|
|
118432
|
+
|
|
118433
|
+
for (i = 0; i < 16; i++) {
|
|
118434
|
+
// get little-endian words
|
|
118435
|
+
m[i] = B2S_GET32(ctx.b, 4 * i);
|
|
118436
|
+
}
|
|
118437
|
+
|
|
118438
|
+
// ten rounds of mixing
|
|
118439
|
+
// uncomment the DebugPrint calls to log the computation
|
|
118440
|
+
// and match the RFC sample documentation
|
|
118441
|
+
// util.debugPrint(' m[16]', m, 32)
|
|
118442
|
+
for (i = 0; i < 10; i++) {
|
|
118443
|
+
// util.debugPrint(' (i=' + i + ') v[16]', v, 32)
|
|
118444
|
+
B2S_G(0, 4, 8, 12, m[SIGMA[i * 16 + 0]], m[SIGMA[i * 16 + 1]]);
|
|
118445
|
+
B2S_G(1, 5, 9, 13, m[SIGMA[i * 16 + 2]], m[SIGMA[i * 16 + 3]]);
|
|
118446
|
+
B2S_G(2, 6, 10, 14, m[SIGMA[i * 16 + 4]], m[SIGMA[i * 16 + 5]]);
|
|
118447
|
+
B2S_G(3, 7, 11, 15, m[SIGMA[i * 16 + 6]], m[SIGMA[i * 16 + 7]]);
|
|
118448
|
+
B2S_G(0, 5, 10, 15, m[SIGMA[i * 16 + 8]], m[SIGMA[i * 16 + 9]]);
|
|
118449
|
+
B2S_G(1, 6, 11, 12, m[SIGMA[i * 16 + 10]], m[SIGMA[i * 16 + 11]]);
|
|
118450
|
+
B2S_G(2, 7, 8, 13, m[SIGMA[i * 16 + 12]], m[SIGMA[i * 16 + 13]]);
|
|
118451
|
+
B2S_G(3, 4, 9, 14, m[SIGMA[i * 16 + 14]], m[SIGMA[i * 16 + 15]]);
|
|
118452
|
+
}
|
|
118453
|
+
// util.debugPrint(' (i=10) v[16]', v, 32)
|
|
118454
|
+
|
|
118455
|
+
for (i = 0; i < 8; i++) {
|
|
118456
|
+
ctx.h[i] ^= v[i] ^ v[i + 8];
|
|
118457
|
+
}
|
|
118458
|
+
// util.debugPrint('h[8]', ctx.h, 32)
|
|
118459
|
+
}
|
|
118460
|
+
|
|
118461
|
+
// Creates a BLAKE2s hashing context
|
|
118462
|
+
// Requires an output length between 1 and 32 bytes
|
|
118463
|
+
// Takes an optional Uint8Array key
|
|
118464
|
+
function blake2sInit (outlen, key) {
|
|
118465
|
+
if (!(outlen > 0 && outlen <= 32)) {
|
|
118466
|
+
throw new Error('Incorrect output length, should be in [1, 32]')
|
|
118467
|
+
}
|
|
118468
|
+
const keylen = key ? key.length : 0;
|
|
118469
|
+
if (key && !(keylen > 0 && keylen <= 32)) {
|
|
118470
|
+
throw new Error('Incorrect key length, should be in [1, 32]')
|
|
118471
|
+
}
|
|
118472
|
+
|
|
118473
|
+
const ctx = {
|
|
118474
|
+
h: new Uint32Array(BLAKE2S_IV), // hash state
|
|
118475
|
+
b: new Uint8Array(64), // input block
|
|
118476
|
+
c: 0, // pointer within block
|
|
118477
|
+
t: 0, // input count
|
|
118478
|
+
outlen: outlen // output length in bytes
|
|
118479
|
+
};
|
|
118480
|
+
ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen;
|
|
118481
|
+
|
|
118482
|
+
if (keylen > 0) {
|
|
118483
|
+
blake2sUpdate(ctx, key);
|
|
118484
|
+
ctx.c = 64; // at the end
|
|
118485
|
+
}
|
|
118486
|
+
|
|
118487
|
+
return ctx
|
|
118488
|
+
}
|
|
118489
|
+
|
|
118490
|
+
// Updates a BLAKE2s streaming hash
|
|
118491
|
+
// Requires hash context and Uint8Array (byte array)
|
|
118492
|
+
function blake2sUpdate (ctx, input) {
|
|
118493
|
+
for (let i = 0; i < input.length; i++) {
|
|
118494
|
+
if (ctx.c === 64) {
|
|
118495
|
+
// buffer full ?
|
|
118496
|
+
ctx.t += ctx.c; // add counters
|
|
118497
|
+
blake2sCompress(ctx, false); // compress (not last)
|
|
118498
|
+
ctx.c = 0; // counter to zero
|
|
118499
|
+
}
|
|
118500
|
+
ctx.b[ctx.c++] = input[i];
|
|
118501
|
+
}
|
|
118502
|
+
}
|
|
118503
|
+
|
|
118504
|
+
// Completes a BLAKE2s streaming hash
|
|
118505
|
+
// Returns a Uint8Array containing the message digest
|
|
118506
|
+
function blake2sFinal (ctx) {
|
|
118507
|
+
ctx.t += ctx.c; // mark last block offset
|
|
118508
|
+
while (ctx.c < 64) {
|
|
118509
|
+
// fill up with zeros
|
|
118510
|
+
ctx.b[ctx.c++] = 0;
|
|
118511
|
+
}
|
|
118512
|
+
blake2sCompress(ctx, true); // final block flag = 1
|
|
118513
|
+
|
|
118514
|
+
// little endian convert and store
|
|
118515
|
+
const out = new Uint8Array(ctx.outlen);
|
|
118516
|
+
for (let i = 0; i < ctx.outlen; i++) {
|
|
118517
|
+
out[i] = (ctx.h[i >> 2] >> (8 * (i & 3))) & 0xff;
|
|
118518
|
+
}
|
|
118519
|
+
return out
|
|
118520
|
+
}
|
|
118521
|
+
|
|
118522
|
+
// Computes the BLAKE2S hash of a string or byte array, and returns a Uint8Array
|
|
118523
|
+
//
|
|
118524
|
+
// Returns a n-byte Uint8Array
|
|
118525
|
+
//
|
|
118526
|
+
// Parameters:
|
|
118527
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118528
|
+
// - key - optional key Uint8Array, up to 32 bytes
|
|
118529
|
+
// - outlen - optional output length in bytes, default 64
|
|
118530
|
+
function blake2s (input, key, outlen) {
|
|
118531
|
+
// preprocess inputs
|
|
118532
|
+
outlen = outlen || 32;
|
|
118533
|
+
input = util.normalizeInput(input);
|
|
118534
|
+
|
|
118535
|
+
// do the math
|
|
118536
|
+
const ctx = blake2sInit(outlen, key);
|
|
118537
|
+
blake2sUpdate(ctx, input);
|
|
118538
|
+
return blake2sFinal(ctx)
|
|
118539
|
+
}
|
|
118540
|
+
|
|
118541
|
+
// Computes the BLAKE2S hash of a string or byte array
|
|
118542
|
+
//
|
|
118543
|
+
// Returns an n-byte hash in hex, all lowercase
|
|
118544
|
+
//
|
|
118545
|
+
// Parameters:
|
|
118546
|
+
// - input - the input bytes, as a string, Buffer, or Uint8Array
|
|
118547
|
+
// - key - optional key Uint8Array, up to 32 bytes
|
|
118548
|
+
// - outlen - optional output length in bytes, default 64
|
|
118549
|
+
function blake2sHex (input, key, outlen) {
|
|
118550
|
+
const output = blake2s(input, key, outlen);
|
|
118551
|
+
return util.toHex(output)
|
|
118552
|
+
}
|
|
118553
|
+
|
|
118554
|
+
blake2s_1 = {
|
|
118555
|
+
blake2s: blake2s,
|
|
118556
|
+
blake2sHex: blake2sHex,
|
|
118557
|
+
blake2sInit: blake2sInit,
|
|
118558
|
+
blake2sUpdate: blake2sUpdate,
|
|
118559
|
+
blake2sFinal: blake2sFinal
|
|
118560
|
+
};
|
|
118561
|
+
return blake2s_1;
|
|
118562
|
+
}
|
|
118563
|
+
|
|
118564
|
+
var blakejs;
|
|
118565
|
+
var hasRequiredBlakejs;
|
|
118566
|
+
|
|
118567
|
+
function requireBlakejs () {
|
|
118568
|
+
if (hasRequiredBlakejs) return blakejs;
|
|
118569
|
+
hasRequiredBlakejs = 1;
|
|
118570
|
+
const b2b = requireBlake2b();
|
|
118571
|
+
const b2s = requireBlake2s();
|
|
118572
|
+
|
|
118573
|
+
blakejs = {
|
|
118574
|
+
blake2b: b2b.blake2b,
|
|
118575
|
+
blake2bHex: b2b.blake2bHex,
|
|
118576
|
+
blake2bInit: b2b.blake2bInit,
|
|
118577
|
+
blake2bUpdate: b2b.blake2bUpdate,
|
|
118578
|
+
blake2bFinal: b2b.blake2bFinal,
|
|
118579
|
+
blake2s: b2s.blake2s,
|
|
118580
|
+
blake2sHex: b2s.blake2sHex,
|
|
118581
|
+
blake2sInit: b2s.blake2sInit,
|
|
118582
|
+
blake2sUpdate: b2s.blake2sUpdate,
|
|
118583
|
+
blake2sFinal: b2s.blake2sFinal
|
|
118584
|
+
};
|
|
118585
|
+
return blakejs;
|
|
118586
|
+
}
|
|
118550
118587
|
|
|
118551
118588
|
var hasRequiredHash;
|
|
118552
118589
|
|
|
@@ -118555,12 +118592,12 @@ function requireHash () {
|
|
|
118555
118592
|
hasRequiredHash = 1;
|
|
118556
118593
|
Object.defineProperty(hash, "__esModule", { value: true });
|
|
118557
118594
|
hash.ripemd160 = hash.blake128WithKey = hash.blake128 = hash.blake160WithKey = hash.blake160 = hash.blake256WithKey = hash.blake256 = void 0;
|
|
118558
|
-
const crypto_js_1 =
|
|
118595
|
+
const crypto_js_1 = requireCryptoJs();
|
|
118559
118596
|
const utility_1 = requireUtility();
|
|
118560
118597
|
/**
|
|
118561
118598
|
* @hidden
|
|
118562
118599
|
*/
|
|
118563
|
-
const blake =
|
|
118600
|
+
const blake = requireBlakejs();
|
|
118564
118601
|
/**
|
|
118565
118602
|
* Gets data's 256 bit blake hash.
|
|
118566
118603
|
* @param data buffer or hexadecimal string
|