diff options
Diffstat (limited to 'std/hash')
-rw-r--r-- | std/hash/_fnv/util.ts | 2 | ||||
-rw-r--r-- | std/hash/hash_test.ts | 2 | ||||
-rw-r--r-- | std/hash/sha1.ts | 6 | ||||
-rw-r--r-- | std/hash/sha1_test.ts | 15 | ||||
-rw-r--r-- | std/hash/sha256.ts | 46 | ||||
-rw-r--r-- | std/hash/sha256_test.ts | 37 | ||||
-rw-r--r-- | std/hash/sha3_test.ts | 4 | ||||
-rw-r--r-- | std/hash/sha512.ts | 11 | ||||
-rw-r--r-- | std/hash/sha512_test.ts | 45 |
9 files changed, 69 insertions, 99 deletions
diff --git a/std/hash/_fnv/util.ts b/std/hash/_fnv/util.ts index 3d1cb5bac..096b70815 100644 --- a/std/hash/_fnv/util.ts +++ b/std/hash/_fnv/util.ts @@ -45,7 +45,7 @@ export function mul32(a: number, b: number): number { */ export function mul64( [ah, al]: [number, number], - [bh, bl]: [number, number] + [bh, bl]: [number, number], ): [number, number] { const [n, c] = mul32WithCarry(al, bl); return [n32(mul32(al, bh) + mul32(ah, bl) + c), n]; diff --git a/std/hash/hash_test.ts b/std/hash/hash_test.ts index 5169c2107..4d7d7465d 100644 --- a/std/hash/hash_test.ts +++ b/std/hash/hash_test.ts @@ -311,6 +311,6 @@ Deno.test("[hash/double_digest] testDoubleDigest", () => { assertEquals(h1, h2); }, Error, - "hash: already digested" + "hash: already digested", ); }); diff --git a/std/hash/sha1.ts b/std/hash/sha1.ts index e55b5e8d3..6a79db27b 100644 --- a/std/hash/sha1.ts +++ b/std/hash/sha1.ts @@ -33,6 +33,7 @@ export class Sha1 { constructor(sharedMemory = false) { if (sharedMemory) { + // deno-fmt-ignore blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; this.#blocks = blocks; } else { @@ -70,6 +71,7 @@ export class Sha1 { if (this.#hashed) { this.#hashed = false; blocks[0] = this.#block; + // deno-fmt-ignore blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; } @@ -90,8 +92,7 @@ export class Sha1 { blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; } else { - code = - 0x10000 + + code = 0x10000 + (((code & 0x3ff) << 10) | (msg.charCodeAt(++index) & 0x3ff)); blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; @@ -134,6 +135,7 @@ export class Sha1 { this.hash(); } blocks[0] = this.#block; + // deno-fmt-ignore blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; } blocks[14] = (this.#hBytes << 3) | (this.#bytes >>> 29); diff --git a/std/hash/sha1_test.ts b/std/hash/sha1_test.ts index 2c78bb1c8..25571947f 100644 --- a/std/hash/sha1_test.ts +++ b/std/hash/sha1_test.ts @@ -16,7 +16,6 @@ function toHexString(value: number[] | ArrayBuffer): string { return hex; } -// prettier-ignore // deno-fmt-ignore const fixtures: { sha1: Record<string, Record<string, Message>>; @@ -74,10 +73,9 @@ for (const method of methods) { fn() { const algorithm = new Sha1(); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -94,10 +92,9 @@ for (const method of methods) { fn() { const algorithm = new Sha1(true); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); diff --git a/std/hash/sha256.ts b/std/hash/sha256.ts index 61da5a578..e2456d7a1 100644 --- a/std/hash/sha256.ts +++ b/std/hash/sha256.ts @@ -14,7 +14,6 @@ export type Message = string | number[] | ArrayBuffer; const HEX_CHARS = "0123456789abcdef".split(""); const EXTRA = [-2147483648, 8388608, 32768, 128] as const; const SHIFT = [24, 16, 8, 0] as const; -// prettier-ignore // deno-fmt-ignore const K = [ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, @@ -58,6 +57,7 @@ export class Sha256 { protected init(is224: boolean, sharedMemory: boolean): void { if (sharedMemory) { + // deno-fmt-ignore blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; this.#blocks = blocks; } else { @@ -116,6 +116,7 @@ export class Sha256 { if (this.#hashed) { this.#hashed = false; blocks[0] = this.#block; + // deno-fmt-ignore blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; } @@ -136,8 +137,7 @@ export class Sha256 { blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; } else { - code = - 0x10000 + + code = 0x10000 + (((code & 0x3ff) << 10) | (msg.charCodeAt(++index) & 0x3ff)); blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; @@ -180,6 +180,7 @@ export class Sha256 { this.hash(); } blocks[0] = this.#block; + // deno-fmt-ignore blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; } blocks[14] = (this.#hBytes << 3) | (this.#bytes >>> 29); @@ -213,8 +214,8 @@ export class Sha256 { t1 = blocks[j - 15]; s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3); t1 = blocks[j - 2]; - s1 = - ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10); + s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ + (t1 >>> 10); blocks[j] = (blocks[j - 16] + s0 + blocks[j - 7] + s1) << 0; } @@ -234,12 +235,10 @@ export class Sha256 { } this.#first = false; } else { - s0 = - ((a >>> 2) | (a << 30)) ^ + s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10)); - s1 = - ((e >>> 6) | (e << 26)) ^ + s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7)); ab = a & b; @@ -250,12 +249,10 @@ export class Sha256 { h = (d + t1) << 0; d = (t1 + t2) << 0; } - s0 = - ((d >>> 2) | (d << 30)) ^ + s0 = ((d >>> 2) | (d << 30)) ^ ((d >>> 13) | (d << 19)) ^ ((d >>> 22) | (d << 10)); - s1 = - ((h >>> 6) | (h << 26)) ^ + s1 = ((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7)); da = d & a; @@ -265,12 +262,10 @@ export class Sha256 { t2 = s0 + maj; g = (c + t1) << 0; c = (t1 + t2) << 0; - s0 = - ((c >>> 2) | (c << 30)) ^ + s0 = ((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10)); - s1 = - ((g >>> 6) | (g << 26)) ^ + s1 = ((g >>> 6) | (g << 26)) ^ ((g >>> 11) | (g << 21)) ^ ((g >>> 25) | (g << 7)); cd = c & d; @@ -280,12 +275,10 @@ export class Sha256 { t2 = s0 + maj; f = (b + t1) << 0; b = (t1 + t2) << 0; - s0 = - ((b >>> 2) | (b << 30)) ^ + s0 = ((b >>> 2) | (b << 30)) ^ ((b >>> 13) | (b << 19)) ^ ((b >>> 22) | (b << 10)); - s1 = - ((f >>> 6) | (f << 26)) ^ + s1 = ((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7)); bc = b & c; @@ -320,8 +313,7 @@ export class Sha256 { const h6 = this.#h6; const h7 = this.#h7; - let hex = - HEX_CHARS[(h0 >> 28) & 0x0f] + + let hex = HEX_CHARS[(h0 >> 28) & 0x0f] + HEX_CHARS[(h0 >> 24) & 0x0f] + HEX_CHARS[(h0 >> 20) & 0x0f] + HEX_CHARS[(h0 >> 16) & 0x0f] + @@ -378,8 +370,7 @@ export class Sha256 { HEX_CHARS[(h6 >> 4) & 0x0f] + HEX_CHARS[h6 & 0x0f]; if (!this.#is224) { - hex += - HEX_CHARS[(h7 >> 28) & 0x0f] + + hex += HEX_CHARS[(h7 >> 28) & 0x0f] + HEX_CHARS[(h7 >> 24) & 0x0f] + HEX_CHARS[(h7 >> 20) & 0x0f] + HEX_CHARS[(h7 >> 16) & 0x0f] + @@ -444,7 +435,7 @@ export class Sha256 { (h7 >> 24) & 0xff, (h7 >> 16) & 0xff, (h7 >> 8) & 0xff, - h7 & 0xff + h7 & 0xff, ); } return arr; @@ -501,8 +492,7 @@ export class HmacSha256 extends Sha256 { bytes[index++] = 0x80 | ((code >> 6) & 0x3f); bytes[index++] = 0x80 | (code & 0x3f); } else { - code = - 0x10000 + + code = 0x10000 + (((code & 0x3ff) << 10) | (secretKey.charCodeAt(++i) & 0x3ff)); bytes[index++] = 0xf0 | (code >> 18); bytes[index++] = 0x80 | ((code >> 12) & 0x3f); diff --git a/std/hash/sha256_test.ts b/std/hash/sha256_test.ts index 3cf4cbdf2..ba7efe4d1 100644 --- a/std/hash/sha256_test.ts +++ b/std/hash/sha256_test.ts @@ -16,7 +16,6 @@ function toHexString(value: number[] | ArrayBuffer): string { return hex; } -// prettier-ignore // deno-fmt-ignore const fixtures: { sha256: Record<string, Record<string, Message>>; @@ -155,35 +154,29 @@ const fixtures: { }, }; -// prettier-ignore // deno-fmt-ignore fixtures.sha256.Uint8Array = { '182889f925ae4e5cc37118ded6ed87f7bdc7cab5ec5e78faef2e50048999473f': new Uint8Array([211, 212]), 'd7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) }; -// prettier-ignore // deno-fmt-ignore fixtures.sha256.Int8Array = { 'd7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) }; -// prettier-ignore // deno-fmt-ignore fixtures.sha256.ArrayBuffer = { 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855': new ArrayBuffer(0), '6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d': new ArrayBuffer(1) }; -// prettier-ignore // deno-fmt-ignore fixtures.sha224.Uint8Array = { 'e17541396a3ecd1cd5a2b968b84e597e8eae3b0ea3127963bf48dd3b': new Uint8Array([211, 212]), '730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525': new Uint8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) }; -// prettier-ignore // deno-fmt-ignore fixtures.sha224.Int8Array = { '730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525': new Int8Array([84, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 115, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 100, 111, 103]) }; -// prettier-ignore // deno-fmt-ignore fixtures.sha224.ArrayBuffer = { 'd14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f': new ArrayBuffer(0), @@ -225,10 +218,9 @@ for (const method of methods) { fn() { const algorithm = new Sha256(); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -245,10 +237,9 @@ for (const method of methods) { fn() { const algorithm = new Sha256(true); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -265,10 +256,9 @@ for (const method of methods) { fn() { const algorithm = new HmacSha256(key); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -285,10 +275,9 @@ for (const method of methods) { fn() { const algorithm = new HmacSha256(key, true); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -302,6 +291,6 @@ Deno.test("[hash/sha256] test Uint8Array from Reader", async () => { const hash = new Sha256().update(data).hex(); assertEquals( hash, - "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" + "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", ); }); diff --git a/std/hash/sha3_test.ts b/std/hash/sha3_test.ts index 64e426385..b5936f960 100644 --- a/std/hash/sha3_test.ts +++ b/std/hash/sha3_test.ts @@ -554,7 +554,7 @@ Deno.test("[hash/sha3] testSha3-256Chain", () => { assertEquals( output, - "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532" + "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", ); }); @@ -567,6 +567,6 @@ Deno.test("[hash/sha3] testSha3UpdateFinalized", () => { assertEquals(hash, hash2); }, Error, - "sha3: cannot update already finalized hash" + "sha3: cannot update already finalized hash", ); }); diff --git a/std/hash/sha512.ts b/std/hash/sha512.ts index b55069f4d..1eef85a47 100644 --- a/std/hash/sha512.ts +++ b/std/hash/sha512.ts @@ -9,11 +9,11 @@ export type Message = string | number[] | ArrayBuffer; -// prettier-ignore +// deno-fmt-ignore const HEX_CHARS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"] as const; const EXTRA = [-2147483648, 8388608, 32768, 128] as const; const SHIFT = [24, 16, 8, 0] as const; -// prettier-ignore +// deno-fmt-ignore const K = [ 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, 0xd807aa98, 0xa3030242, @@ -37,7 +37,7 @@ const K = [ const blocks: number[] = []; -// prettier-ignore +// deno-fmt-ignore export class Sha512 { #blocks!: number[]; #block!: number; @@ -564,7 +564,7 @@ export class Sha512 { h0h = this.#h0h, h0l = this.#h0l, h1h = this.#h1h, h1l = this.#h1l, h2h = this.#h2h, h2l = this.#h2l, h3h = this.#h3h, h3l = this.#h3l, h4h = this.#h4h, h4l = this.#h4l, h5h = this.#h5h, h5l = this.#h5l, h6h = this.#h6h, h6l = this.#h6l, h7h = this.#h7h, h7l = this.#h7l, bits = this.#bits; - let hex = + let hex = HEX_CHARS[(h0h >> 28) & 0x0f] + HEX_CHARS[(h0h >> 24) & 0x0f] + HEX_CHARS[(h0h >> 20) & 0x0f] + HEX_CHARS[(h0h >> 16) & 0x0f] + HEX_CHARS[(h0h >> 12) & 0x0f] + HEX_CHARS[(h0h >> 8) & 0x0f] + @@ -747,8 +747,7 @@ export class HmacSha512 extends Sha512 { bytes[index++] = 0x80 | ((code >> 6) & 0x3f); bytes[index++] = 0x80 | (code & 0x3f); } else { - code = - 0x10000 + + code = 0x10000 + (((code & 0x3ff) << 10) | (secretKey.charCodeAt(++i) & 0x3ff)); bytes[index++] = 0xf0 | (code >> 18); bytes[index++] = 0x80 | ((code >> 12) & 0x3f); diff --git a/std/hash/sha512_test.ts b/std/hash/sha512_test.ts index c656731a3..d8d69a923 100644 --- a/std/hash/sha512_test.ts +++ b/std/hash/sha512_test.ts @@ -16,7 +16,6 @@ function toHexString(value: number[] | ArrayBuffer): string { return hex; } -// prettier-ignore // deno-fmt-ignore const fixtures: { sha512bits224: Record<string, Record<string, Message>>, @@ -285,10 +284,9 @@ for (const method of methods) { fn() { const algorithm = new Sha512(224); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -305,10 +303,9 @@ for (const method of methods) { fn() { const algorithm = new Sha512(256); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -325,10 +322,9 @@ for (const method of methods) { fn() { const algorithm = new Sha512(); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -345,10 +341,9 @@ for (const method of methods) { fn() { const algorithm = new HmacSha512(key, 224); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -365,10 +360,9 @@ for (const method of methods) { fn() { const algorithm = new HmacSha512(key, 256); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -385,10 +379,9 @@ for (const method of methods) { fn() { const algorithm = new HmacSha512(key); algorithm.update(message); - const actual = - method === "hex" - ? algorithm[method]() - : toHexString(algorithm[method]()); + const actual = method === "hex" + ? algorithm[method]() + : toHexString(algorithm[method]()); assertEquals(actual, expected); }, }); @@ -401,6 +394,6 @@ Deno.test("[hash/sha512] test Uint8Array from Reader", async () => { const hash = new Sha512().update(data).hex(); assertEquals( hash, - "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff" + "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff", ); }); |