mol_crypto2_lib 0.0.1 → 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/node.meta.tree CHANGED
@@ -26,3 +26,4 @@
26
26
  include \/mol/crypto2/cipher
27
27
  include \/mol/crypto2/public
28
28
  include \/mol/crypto2/private
29
+ include \/mol/crypto2/nonce
package/node.mjs CHANGED
@@ -2580,11 +2580,17 @@ var $;
2580
2580
  "use strict";
2581
2581
  var $;
2582
2582
  (function ($) {
2583
- function $mol_crypto_salt() {
2583
+ function $mol_crypto2_nonce() {
2584
2584
  return $mol_crypto_native.getRandomValues(new Uint8Array(16));
2585
2585
  }
2586
- $.$mol_crypto_salt = $mol_crypto_salt;
2587
- $.$mol_crypto_salt_once = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6]);
2586
+ $.$mol_crypto2_nonce = $mol_crypto2_nonce;
2587
+ })($ || ($ = {}));
2588
+
2589
+ ;
2590
+ "use strict";
2591
+ var $;
2592
+ (function ($) {
2593
+ $.$mol_crypto_salt = $mol_crypto2_nonce;
2588
2594
  })($ || ($ = {}));
2589
2595
 
2590
2596
  ;
package/node.test.js CHANGED
@@ -2571,11 +2571,17 @@ var $;
2571
2571
  "use strict";
2572
2572
  var $;
2573
2573
  (function ($) {
2574
- function $mol_crypto_salt() {
2574
+ function $mol_crypto2_nonce() {
2575
2575
  return $mol_crypto_native.getRandomValues(new Uint8Array(16));
2576
2576
  }
2577
- $.$mol_crypto_salt = $mol_crypto_salt;
2578
- $.$mol_crypto_salt_once = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6]);
2577
+ $.$mol_crypto2_nonce = $mol_crypto2_nonce;
2578
+ })($ || ($ = {}));
2579
+
2580
+ ;
2581
+ "use strict";
2582
+ var $;
2583
+ (function ($) {
2584
+ $.$mol_crypto_salt = $mol_crypto2_nonce;
2579
2585
  })($ || ($ = {}));
2580
2586
 
2581
2587
  ;
@@ -5112,18 +5118,18 @@ var $;
5112
5118
  var $;
5113
5119
  (function ($) {
5114
5120
  let sponge = new Uint32Array(80);
5115
- function $mol_crypto_hash(input) {
5121
+ function $mol_crypto2_hash(input) {
5116
5122
  const data = input instanceof Uint8Array
5117
5123
  ? input
5118
5124
  : new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
5119
5125
  const bits = data.byteLength << 3;
5120
5126
  const kbits = bits >> 5;
5121
5127
  const kword = 0x80 << (24 - bits & 0b11111);
5122
- const bytes = 16 + (bits + 64 >>> 9 << 4);
5128
+ const bytes = 16 + ((bits + 64) >>> 9 << 4);
5123
5129
  const klens = bytes - 1;
5124
- const words = new DataView(data.buffer, data.byteOffset, data.byteLength >> 2 << 2);
5130
+ const wlen = data.byteLength >> 2 << 2;
5125
5131
  let tail = 0;
5126
- for (let i = words.byteLength; i < data.length; ++i) {
5132
+ for (let i = wlen; i < data.length; ++i) {
5127
5133
  tail |= data[i] << ((3 - i & 0b11) << 3);
5128
5134
  }
5129
5135
  const hash = new Int32Array([1732584193, -271733879, -1732584194, 271733878, -1009589776]);
@@ -5140,9 +5146,9 @@ var $;
5140
5146
  }
5141
5147
  else {
5142
5148
  const pos = k << 2;
5143
- let word = pos === words.byteLength ? tail :
5144
- pos > words.byteLength ? 0 :
5145
- words.getInt32(pos, false);
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]);
5146
5152
  if (k === kbits)
5147
5153
  word |= kword;
5148
5154
  sponge[j] = word;
@@ -5206,7 +5212,7 @@ var $;
5206
5212
  }
5207
5213
  return new Uint8Array(hash.buffer);
5208
5214
  }
5209
- $.$mol_crypto_hash = $mol_crypto_hash;
5215
+ $.$mol_crypto2_hash = $mol_crypto2_hash;
5210
5216
  })($ || ($ = {}));
5211
5217
 
5212
5218
  ;
@@ -5215,24 +5221,24 @@ var $;
5215
5221
  (function ($) {
5216
5222
  $mol_test({
5217
5223
  'empty hash'() {
5218
- $mol_assert_equal($mol_crypto_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]));
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]));
5219
5225
  },
5220
5226
  'three bytes hash'() {
5221
- $mol_assert_equal($mol_crypto_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]));
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]));
5222
5228
  },
5223
5229
  'six bytes hash'() {
5224
- $mol_assert_equal($mol_crypto_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]));
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]));
5225
5231
  },
5226
5232
  'seven bytes hash'() {
5227
- $mol_assert_equal($mol_crypto_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]));
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]));
5228
5234
  },
5229
5235
  'unaligned hash'() {
5230
5236
  const data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
5231
- $mol_assert_equal($mol_crypto_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]));
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]));
5232
5238
  },
5233
5239
  async 'reference'() {
5234
5240
  const data = new Uint8Array([255, 254, 253]);
5235
- $mol_assert_equal($mol_crypto_hash(data), new Uint8Array(await $mol_crypto_native.subtle.digest('SHA-1', data)));
5241
+ $mol_assert_equal($mol_crypto2_hash(data), new Uint8Array(await $mol_crypto_native.subtle.digest('SHA-1', data)));
5236
5242
  },
5237
5243
  });
5238
5244
  })($ || ($ = {}));
@@ -5251,12 +5257,12 @@ var $;
5251
5257
  const secretB = await Bella.cipher().secret(Alice.socket());
5252
5258
  $mol_assert_equal(secretA, secretB);
5253
5259
  const data = new Uint8Array([1, 2, 3]);
5254
- const salt = $mol_crypto_salt();
5255
- const closed = await secretA.encrypt(data, salt);
5256
- const digest = $mol_crypto_hash(closed);
5260
+ const nonce = $mol_crypto2_nonce();
5261
+ const closed = await secretA.encrypt(data, nonce);
5262
+ const digest = $mol_crypto2_hash(closed);
5257
5263
  const sign = await Alice.signer().sign(digest);
5258
5264
  $mol_assert_equal(true, await Alice.auditor().verify(digest, sign));
5259
- $mol_assert_equal(data, await secretA.decrypt(closed, salt));
5265
+ $mol_assert_equal(data, await secretA.decrypt(closed, nonce));
5260
5266
  },
5261
5267
  async "Serial & Deserial"($) {
5262
5268
  const orig = await $mol_crypto2_private.generate();