/
opt
/
canhelp
/
node_modules
/
@noble
/
ciphers
/
/opt/canhelp/node_modules/@noble/ciphers
mkdir
upload
Name
Size
Mode
Actions
src/
-
0755
rm
aes.d.ts
8307
0644
edit
dl
rm
aes.d.ts.map
4772
0644
edit
dl
rm
aes.js
50350
0644
edit
dl
rm
aes.js.map
54638
0644
edit
dl
rm
chacha.d.ts
3296
0644
edit
dl
rm
chacha.d.ts.map
943
0644
edit
dl
rm
chacha.js
14213
0644
edit
dl
rm
chacha.js.map
18406
0644
edit
dl
rm
ff1.d.ts
420
0644
edit
dl
rm
ff1.d.ts.map
452
0644
edit
dl
rm
ff1.js
6172
0644
edit
dl
rm
ff1.js.map
7851
0644
edit
dl
rm
index.d.ts
46
0644
edit
dl
rm
index.d.ts.map
101
0644
edit
dl
rm
index.js
1102
0644
edit
dl
rm
index.js.map
173
0644
edit
dl
rm
LICENSE
1161
0644
edit
dl
rm
package.json
2170
0644
edit
dl
rm
README.md
26826
0644
edit
dl
rm
salsa.d.ts
1327
0644
edit
dl
rm
salsa.d.ts.map
679
0644
edit
dl
rm
salsa.js
11271
0644
edit
dl
rm
salsa.js.map
13769
0644
edit
dl
rm
utils.d.ts
8116
0644
edit
dl
rm
utils.d.ts.map
5024
0644
edit
dl
rm
utils.js
13458
0644
edit
dl
rm
utils.js.map
11582
0644
edit
dl
rm
webcrypto.d.ts
1096
0644
edit
dl
rm
webcrypto.d.ts.map
935
0644
edit
dl
rm
webcrypto.js
3917
0644
edit
dl
rm
webcrypto.js.map
3333
0644
edit
dl
rm
_arx.d.ts
3417
0644
edit
dl
rm
_arx.d.ts.map
1653
0644
edit
dl
rm
_arx.js
9728
0644
edit
dl
rm
_arx.js.map
9097
0644
edit
dl
rm
_poly1305.d.ts
1947
0644
edit
dl
rm
_poly1305.d.ts.map
997
0644
edit
dl
rm
_poly1305.js
12035
0644
edit
dl
rm
_poly1305.js.map
17809
0644
edit
dl
rm
_polyval.d.ts
2035
0644
edit
dl
rm
_polyval.d.ts.map
1608
0644
edit
dl
rm
_polyval.js
7922
0644
edit
dl
rm
_polyval.js.map
10164
0644
edit
dl
rm
Edit:
/opt/canhelp/node_modules/@noble/ciphers/_polyval.js
(7922B)
/** * GHash from AES-GCM and its little-endian "mirror image" Polyval from AES-SIV. * * Implemented in terms of GHash with conversion function for keys * GCM GHASH from * [NIST SP800-38d](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf), * SIV from * [RFC 8452](https://www.rfc-editor.org/rfc/rfc8452). * * GHASH modulo: x^128 + x^7 + x^2 + x + 1 * POLYVAL modulo: x^128 + x^127 + x^126 + x^121 + 1 * * @module */ import { abytes, aexists, aoutput, clean, copyBytes, createView, u32, } from "./utils.js"; const BLOCK_SIZE = 16; // TODO: rewrite // temporary padding buffer const ZEROS16 = /* @__PURE__ */ new Uint8Array(16); const ZEROS32 = u32(ZEROS16); const POLY = 0xe1; // v = 2*v % POLY // v = 2*v % POLY // NOTE: because x + x = 0 (add/sub is same), mul2(x) != x+x // We can multiply any number using montgomery ladder and this function (works as double, add is simple xor) const mul2 = (s0, s1, s2, s3) => { const hiBit = s3 & 1; return { s3: (s2 << 31) | (s3 >>> 1), s2: (s1 << 31) | (s2 >>> 1), s1: (s0 << 31) | (s1 >>> 1), s0: (s0 >>> 1) ^ ((POLY << 24) & -(hiBit & 1)), // reduce % poly }; }; const swapLE = (n) => (((n >>> 0) & 0xff) << 24) | (((n >>> 8) & 0xff) << 16) | (((n >>> 16) & 0xff) << 8) | ((n >>> 24) & 0xff) | 0; /** * `mulX_POLYVAL(ByteReverse(H))` from spec * @param k mutated in place */ export function _toGHASHKey(k) { k.reverse(); const hiBit = k[15] & 1; // k >>= 1 let carry = 0; for (let i = 0; i < k.length; i++) { const t = k[i]; k[i] = (t >>> 1) | carry; carry = (t & 1) << 7; } k[0] ^= -hiBit & 0xe1; // if (hiBit) n ^= 0xe1000000000000000000000000000000; return k; } const estimateWindow = (bytes) => { if (bytes > 64 * 1024) return 8; if (bytes > 1024) return 4; return 2; }; export class GHASH { blockLen = BLOCK_SIZE; outputLen = BLOCK_SIZE; s0 = 0; s1 = 0; s2 = 0; s3 = 0; finished = false; t; W; windowSize; // We select bits per window adaptively based on expectedLength constructor(key, expectedLength) { abytes(key, 16, 'key'); key = copyBytes(key); const kView = createView(key); let k0 = kView.getUint32(0, false); let k1 = kView.getUint32(4, false); let k2 = kView.getUint32(8, false); let k3 = kView.getUint32(12, false); // generate table of doubled keys (half of montgomery ladder) const doubles = []; for (let i = 0; i < 128; i++) { doubles.push({ s0: swapLE(k0), s1: swapLE(k1), s2: swapLE(k2), s3: swapLE(k3) }); ({ s0: k0, s1: k1, s2: k2, s3: k3 } = mul2(k0, k1, k2, k3)); } const W = estimateWindow(expectedLength || 1024); if (![1, 2, 4, 8].includes(W)) throw new Error('ghash: invalid window size, expected 2, 4 or 8'); this.W = W; const bits = 128; // always 128 bits; const windows = bits / W; const windowSize = (this.windowSize = 2 ** W); const items = []; // Create precompute table for window of W bits for (let w = 0; w < windows; w++) { // truth table: 00, 01, 10, 11 for (let byte = 0; byte < windowSize; byte++) { // prettier-ignore let s0 = 0, s1 = 0, s2 = 0, s3 = 0; for (let j = 0; j < W; j++) { const bit = (byte >>> (W - j - 1)) & 1; if (!bit) continue; const { s0: d0, s1: d1, s2: d2, s3: d3 } = doubles[W * w + j]; ((s0 ^= d0), (s1 ^= d1), (s2 ^= d2), (s3 ^= d3)); } items.push({ s0, s1, s2, s3 }); } } this.t = items; } _updateBlock(s0, s1, s2, s3) { ((s0 ^= this.s0), (s1 ^= this.s1), (s2 ^= this.s2), (s3 ^= this.s3)); const { W, t, windowSize } = this; // prettier-ignore let o0 = 0, o1 = 0, o2 = 0, o3 = 0; const mask = (1 << W) - 1; // 2**W will kill performance. let w = 0; for (const num of [s0, s1, s2, s3]) { for (let bytePos = 0; bytePos < 4; bytePos++) { const byte = (num >>> (8 * bytePos)) & 0xff; for (let bitPos = 8 / W - 1; bitPos >= 0; bitPos--) { const bit = (byte >>> (W * bitPos)) & mask; const { s0: e0, s1: e1, s2: e2, s3: e3 } = t[w * windowSize + bit]; ((o0 ^= e0), (o1 ^= e1), (o2 ^= e2), (o3 ^= e3)); w += 1; } } } this.s0 = o0; this.s1 = o1; this.s2 = o2; this.s3 = o3; } update(data) { aexists(this); abytes(data); data = copyBytes(data); const b32 = u32(data); const blocks = Math.floor(data.length / BLOCK_SIZE); const left = data.length % BLOCK_SIZE; for (let i = 0; i < blocks; i++) { this._updateBlock(b32[i * 4 + 0], b32[i * 4 + 1], b32[i * 4 + 2], b32[i * 4 + 3]); } if (left) { ZEROS16.set(data.subarray(blocks * BLOCK_SIZE)); this._updateBlock(ZEROS32[0], ZEROS32[1], ZEROS32[2], ZEROS32[3]); clean(ZEROS32); // clean tmp buffer } return this; } destroy() { const { t } = this; // clean precompute table for (const elm of t) { ((elm.s0 = 0), (elm.s1 = 0), (elm.s2 = 0), (elm.s3 = 0)); } } digestInto(out) { aexists(this); aoutput(out, this); this.finished = true; const { s0, s1, s2, s3 } = this; const o32 = u32(out); o32[0] = s0; o32[1] = s1; o32[2] = s2; o32[3] = s3; return out; } digest() { const res = new Uint8Array(BLOCK_SIZE); this.digestInto(res); this.destroy(); return res; } } export class Polyval extends GHASH { constructor(key, expectedLength) { abytes(key); const ghKey = _toGHASHKey(copyBytes(key)); super(ghKey, expectedLength); clean(ghKey); } update(data) { aexists(this); abytes(data); data = copyBytes(data); const b32 = u32(data); const left = data.length % BLOCK_SIZE; const blocks = Math.floor(data.length / BLOCK_SIZE); for (let i = 0; i < blocks; i++) { this._updateBlock(swapLE(b32[i * 4 + 3]), swapLE(b32[i * 4 + 2]), swapLE(b32[i * 4 + 1]), swapLE(b32[i * 4 + 0])); } if (left) { ZEROS16.set(data.subarray(blocks * BLOCK_SIZE)); this._updateBlock(swapLE(ZEROS32[3]), swapLE(ZEROS32[2]), swapLE(ZEROS32[1]), swapLE(ZEROS32[0])); clean(ZEROS32); } return this; } digestInto(out) { aexists(this); aoutput(out, this); this.finished = true; // tmp ugly hack const { s0, s1, s2, s3 } = this; const o32 = u32(out); o32[0] = s0; o32[1] = s1; o32[2] = s2; o32[3] = s3; return out.reverse(); } } function wrapConstructorWithKey(hashCons) { const hashC = (msg, key) => hashCons(key, msg.length).update(msg).digest(); const tmp = hashCons(new Uint8Array(16), 0); hashC.outputLen = tmp.outputLen; hashC.blockLen = tmp.blockLen; hashC.create = (key, expectedLength) => hashCons(key, expectedLength); return hashC; } /** GHash MAC for AES-GCM. */ export const ghash = wrapConstructorWithKey((key, expectedLength) => new GHASH(key, expectedLength)); /** Polyval MAC for AES-SIV. */ export const polyval = wrapConstructorWithKey((key, expectedLength) => new Polyval(key, expectedLength)); //# sourceMappingURL=_polyval.js.map
Save
cmd:
run