mol_crypto2_lib 0.0.2 → 0.0.3
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/README.md +18 -5
- package/node.deps.json +1 -1
- package/node.js.map +1 -1
- package/node.test.js +15 -15
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.deps.json +1 -1
- package/web.js.map +1 -1
- package/web.test.js +15 -15
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -5118,18 +5118,18 @@ var $;
|
|
|
5118
5118
|
var $;
|
|
5119
5119
|
(function ($) {
|
|
5120
5120
|
let sponge = new Uint32Array(80);
|
|
5121
|
-
function $
|
|
5121
|
+
function $mol_crypto2_hash(input) {
|
|
5122
5122
|
const data = input instanceof Uint8Array
|
|
5123
5123
|
? input
|
|
5124
5124
|
: new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
5125
5125
|
const bits = data.byteLength << 3;
|
|
5126
5126
|
const kbits = bits >> 5;
|
|
5127
5127
|
const kword = 0x80 << (24 - bits & 0b11111);
|
|
5128
|
-
const bytes = 16 + (bits + 64 >>> 9 << 4);
|
|
5128
|
+
const bytes = 16 + ((bits + 64) >>> 9 << 4);
|
|
5129
5129
|
const klens = bytes - 1;
|
|
5130
|
-
const
|
|
5130
|
+
const wlen = data.byteLength >> 2 << 2;
|
|
5131
5131
|
let tail = 0;
|
|
5132
|
-
for (let i =
|
|
5132
|
+
for (let i = wlen; i < data.length; ++i) {
|
|
5133
5133
|
tail |= data[i] << ((3 - i & 0b11) << 3);
|
|
5134
5134
|
}
|
|
5135
5135
|
const hash = new Int32Array([1732584193, -271733879, -1732584194, 271733878, -1009589776]);
|
|
@@ -5146,9 +5146,9 @@ var $;
|
|
|
5146
5146
|
}
|
|
5147
5147
|
else {
|
|
5148
5148
|
const pos = k << 2;
|
|
5149
|
-
let word = pos ===
|
|
5150
|
-
pos >
|
|
5151
|
-
|
|
5149
|
+
let word = pos === wlen ? tail :
|
|
5150
|
+
pos > wlen ? 0 :
|
|
5151
|
+
(data[pos] << 24 | data[pos + 1] << 16 | data[pos + 2] << 8 | data[pos + 3]);
|
|
5152
5152
|
if (k === kbits)
|
|
5153
5153
|
word |= kword;
|
|
5154
5154
|
sponge[j] = word;
|
|
@@ -5212,7 +5212,7 @@ var $;
|
|
|
5212
5212
|
}
|
|
5213
5213
|
return new Uint8Array(hash.buffer);
|
|
5214
5214
|
}
|
|
5215
|
-
$.$
|
|
5215
|
+
$.$mol_crypto2_hash = $mol_crypto2_hash;
|
|
5216
5216
|
})($ || ($ = {}));
|
|
5217
5217
|
|
|
5218
5218
|
;
|
|
@@ -5221,24 +5221,24 @@ var $;
|
|
|
5221
5221
|
(function ($) {
|
|
5222
5222
|
$mol_test({
|
|
5223
5223
|
'empty hash'() {
|
|
5224
|
-
$mol_assert_equal($
|
|
5224
|
+
$mol_assert_equal($mol_crypto2_hash(new Uint8Array([])), new Uint8Array([218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9]));
|
|
5225
5225
|
},
|
|
5226
5226
|
'three bytes hash'() {
|
|
5227
|
-
$mol_assert_equal($
|
|
5227
|
+
$mol_assert_equal($mol_crypto2_hash(new Uint8Array([255, 254, 253])), new Uint8Array([240, 150, 38, 243, 255, 128, 96, 0, 72, 215, 207, 228, 19, 149, 113, 52, 2, 125, 27, 77]));
|
|
5228
5228
|
},
|
|
5229
5229
|
'six bytes hash'() {
|
|
5230
|
-
$mol_assert_equal($
|
|
5230
|
+
$mol_assert_equal($mol_crypto2_hash(new Uint8Array([0, 255, 10, 250, 32, 128])), new Uint8Array([23, 25, 155, 181, 46, 200, 221, 83, 254, 0, 166, 68, 91, 255, 67, 140, 114, 88, 218, 155]));
|
|
5231
5231
|
},
|
|
5232
5232
|
'seven bytes hash'() {
|
|
5233
|
-
$mol_assert_equal($
|
|
5233
|
+
$mol_assert_equal($mol_crypto2_hash(new Uint8Array([1, 2, 3, 4, 5, 6, 7])), new Uint8Array([140, 31, 40, 252, 47, 72, 194, 113, 214, 196, 152, 240, 242, 73, 205, 222, 54, 92, 84, 197]));
|
|
5234
5234
|
},
|
|
5235
5235
|
'unaligned hash'() {
|
|
5236
5236
|
const data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
|
|
5237
|
-
$mol_assert_equal($
|
|
5237
|
+
$mol_assert_equal($mol_crypto2_hash(new Uint8Array(data.buffer, 1, 7)), new Uint8Array([140, 31, 40, 252, 47, 72, 194, 113, 214, 196, 152, 240, 242, 73, 205, 222, 54, 92, 84, 197]));
|
|
5238
5238
|
},
|
|
5239
5239
|
async 'reference'() {
|
|
5240
5240
|
const data = new Uint8Array([255, 254, 253]);
|
|
5241
|
-
$mol_assert_equal($
|
|
5241
|
+
$mol_assert_equal($mol_crypto2_hash(data), new Uint8Array(await $mol_crypto_native.subtle.digest('SHA-1', data)));
|
|
5242
5242
|
},
|
|
5243
5243
|
});
|
|
5244
5244
|
})($ || ($ = {}));
|
|
@@ -5259,7 +5259,7 @@ var $;
|
|
|
5259
5259
|
const data = new Uint8Array([1, 2, 3]);
|
|
5260
5260
|
const nonce = $mol_crypto2_nonce();
|
|
5261
5261
|
const closed = await secretA.encrypt(data, nonce);
|
|
5262
|
-
const digest = $
|
|
5262
|
+
const digest = $mol_crypto2_hash(closed);
|
|
5263
5263
|
const sign = await Alice.signer().sign(digest);
|
|
5264
5264
|
$mol_assert_equal(true, await Alice.auditor().verify(digest, sign));
|
|
5265
5265
|
$mol_assert_equal(data, await secretA.decrypt(closed, nonce));
|