diff options
| author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-02-20 22:22:28 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-20 22:22:28 +0530 |
| commit | ea7ca00c895c401af57a7201f3c41524333e7939 (patch) | |
| tree | a238ea54a003111ab6c1b7b1cb14e0669cb4f7af /ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes | |
| parent | a16c11c5d10052c688ba4c2eca09fd1a225e395a (diff) | |
perf: use ops for node:crypto ciphers (#17819)
Towards #17809
Diffstat (limited to 'ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes')
8 files changed, 0 insertions, 430 deletions
diff --git a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cbc.js b/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cbc.js deleted file mode 100644 index 837adf32f..000000000 --- a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cbc.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// Copyright 2014-2017 browserify-aes contributors. All rights reserved. MIT license. -// Copyright 2013 Maxwell Krohn. All rights reserved. MIT license. -// Copyright 2009-2013 Jeff Mott. All rights reserved. MIT license. - -import { xor } from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/xor.ts"; - -export const encrypt = function (self, block) { - const data = xor(block, self._prev); - - self._prev = self._cipher.encryptBlock(data); - return self._prev; -}; - -export const decrypt = function (self, block) { - const pad = self._prev; - - self._prev = block; - const out = self._cipher.decryptBlock(block); - - return xor(out, pad); -}; diff --git a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb.js b/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb.js deleted file mode 100644 index 8bfd81463..000000000 --- a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// Copyright 2014-2017 browserify-aes contributors. All rights reserved. MIT license. -// Copyright 2013 Maxwell Krohn. All rights reserved. MIT license. -// Copyright 2009-2013 Jeff Mott. All rights reserved. MIT license. - -import { xor } from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/xor.ts"; -import { Buffer } from "internal:deno_node/polyfills/buffer.ts"; - -function encryptStart(self, data, decrypt) { - const len = data.length; - const out = xor(data, self._cache); - self._cache = self._cache.slice(len); - self._prev = Buffer.concat([self._prev, decrypt ? data : out]); - return out; -} - -export const encrypt = function (self, data, decrypt) { - let out = Buffer.allocUnsafe(0); - let len; - - while (data.length) { - if (self._cache.length === 0) { - self._cache = self._cipher.encryptBlock(self._prev); - self._prev = Buffer.allocUnsafe(0); - } - - if (self._cache.length <= data.length) { - len = self._cache.length; - out = Buffer.concat([ - out, - encryptStart(self, data.slice(0, len), decrypt), - ]); - data = data.slice(len); - } else { - out = Buffer.concat([out, encryptStart(self, data, decrypt)]); - break; - } - } - - return out; -}; diff --git a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb1.js b/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb1.js deleted file mode 100644 index 2af8824f0..000000000 --- a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb1.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// Copyright 2014-2017 browserify-aes contributors. All rights reserved. MIT license. -// Copyright 2013 Maxwell Krohn. All rights reserved. MIT license. -// Copyright 2009-2013 Jeff Mott. All rights reserved. MIT license. - -import { Buffer } from "internal:deno_node/polyfills/buffer.ts"; - -function encryptByte(self, byteParam, decrypt) { - let pad; - let i = -1; - const len = 8; - let out = 0; - let bit, value; - while (++i < len) { - pad = self._cipher.encryptBlock(self._prev); - bit = (byteParam & (1 << (7 - i))) ? 0x80 : 0; - value = pad[0] ^ bit; - out += (value & 0x80) >> (i % 8); - self._prev = shiftIn(self._prev, decrypt ? bit : value); - } - return out; -} - -function shiftIn(buffer, value) { - const len = buffer.length; - let i = -1; - const out = Buffer.allocUnsafe(buffer.length); - buffer = Buffer.concat([buffer, Buffer.from([value])]); - - while (++i < len) { - out[i] = buffer[i] << 1 | buffer[i + 1] >> (7); - } - - return out; -} - -export const encrypt = function (self, chunk, decrypt) { - const len = chunk.length; - const out = Buffer.allocUnsafe(len); - let i = -1; - - while (++i < len) { - out[i] = encryptByte(self, chunk[i], decrypt); - } - - return out; -}; diff --git a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb8.js b/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb8.js deleted file mode 100644 index 262494a81..000000000 --- a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb8.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// Copyright 2014-2017 browserify-aes contributors. All rights reserved. MIT license. -// Copyright 2013 Maxwell Krohn. All rights reserved. MIT license. -// Copyright 2009-2013 Jeff Mott. All rights reserved. MIT license. - -import { Buffer } from "internal:deno_node/polyfills/buffer.ts"; - -function encryptByte(self, byteParam, decrypt) { - const pad = self._cipher.encryptBlock(self._prev); - const out = pad[0] ^ byteParam; - - self._prev = Buffer.concat([ - self._prev.slice(1), - Buffer.from([decrypt ? byteParam : out]), - ]); - - return out; -} - -export const encrypt = function (self, chunk, decrypt) { - const len = chunk.length; - const out = Buffer.allocUnsafe(len); - let i = -1; - - while (++i < len) { - out[i] = encryptByte(self, chunk[i], decrypt); - } - - return out; -}; diff --git a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ctr.js b/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ctr.js deleted file mode 100644 index fd1781ab2..000000000 --- a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ctr.js +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// Copyright 2014-2017 browserify-aes contributors. All rights reserved. MIT license. -// Copyright 2013 Maxwell Krohn. All rights reserved. MIT license. -// Copyright 2009-2013 Jeff Mott. All rights reserved. MIT license. - -import { xor } from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/xor.ts"; -import { Buffer } from "internal:deno_node/polyfills/buffer.ts"; -import { incr32 } from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/incr32.js"; - -function getBlock(self) { - const out = self._cipher.encryptBlockRaw(self._prev); - incr32(self._prev); - return out; -} - -const blockSize = 16; -export const encrypt = function (self, chunk) { - const chunkNum = Math.ceil(chunk.length / blockSize); - const start = self._cache.length; - self._cache = Buffer.concat([ - self._cache, - Buffer.allocUnsafe(chunkNum * blockSize), - ]); - for (let i = 0; i < chunkNum; i++) { - const out = getBlock(self); - const offset = start + i * blockSize; - self._cache.writeUInt32BE(out[0], offset + 0); - self._cache.writeUInt32BE(out[1], offset + 4); - self._cache.writeUInt32BE(out[2], offset + 8); - self._cache.writeUInt32BE(out[3], offset + 12); - } - const pad = self._cache.slice(0, chunk.length); - self._cache = self._cache.slice(chunk.length); - return xor(chunk, pad); -}; diff --git a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ecb.js b/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ecb.js deleted file mode 100644 index b4f99cffb..000000000 --- a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ecb.js +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// Copyright 2014-2017 browserify-aes contributors. All rights reserved. MIT license. -// Copyright 2013 Maxwell Krohn. All rights reserved. MIT license. -// Copyright 2009-2013 Jeff Mott. All rights reserved. MIT license. - -export const encrypt = function (self, block) { - return self._cipher.encryptBlock(block); -}; - -export const decrypt = function (self, block) { - return self._cipher.decryptBlock(block); -}; diff --git a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/mod.js b/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/mod.js deleted file mode 100644 index b30ed0b25..000000000 --- a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/mod.js +++ /dev/null @@ -1,221 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// Copyright 2014-2017 browserify-aes contributors. All rights reserved. MIT license. -// Copyright 2013 Maxwell Krohn. All rights reserved. MIT license. -// Copyright 2009-2013 Jeff Mott. All rights reserved. MIT license. - -import * as ECB from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ecb.js"; -import * as CBC from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cbc.js"; -import * as CFB from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb.js"; -import * as CFB8 from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb8.js"; -import * as CFB1 from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/cfb1.js"; -import * as OFB from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ofb.js"; -import * as CTR from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ctr.js"; - -const GCM = CTR; - -const modeModules = { - ECB, - CBC, - CFB, - CFB8, - CFB1, - OFB, - CTR, - GCM, -}; - -export const MODES = { - "aes-128-ecb": { - "cipher": "AES", - "key": 128, - "iv": 0, - "mode": "ECB", - "type": "block", - }, - "aes-192-ecb": { - "cipher": "AES", - "key": 192, - "iv": 0, - "mode": "ECB", - "type": "block", - }, - "aes-256-ecb": { - "cipher": "AES", - "key": 256, - "iv": 0, - "mode": "ECB", - "type": "block", - }, - "aes-128-cbc": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CBC", - "type": "block", - }, - "aes-192-cbc": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CBC", - "type": "block", - }, - "aes-256-cbc": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CBC", - "type": "block", - }, - "aes128": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CBC", - "type": "block", - }, - "aes192": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CBC", - "type": "block", - }, - "aes256": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CBC", - "type": "block", - }, - "aes-128-cfb": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CFB", - "type": "stream", - }, - "aes-192-cfb": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CFB", - "type": "stream", - }, - "aes-256-cfb": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CFB", - "type": "stream", - }, - "aes-128-cfb8": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CFB8", - "type": "stream", - }, - "aes-192-cfb8": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CFB8", - "type": "stream", - }, - "aes-256-cfb8": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CFB8", - "type": "stream", - }, - "aes-128-cfb1": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CFB1", - "type": "stream", - }, - "aes-192-cfb1": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CFB1", - "type": "stream", - }, - "aes-256-cfb1": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CFB1", - "type": "stream", - }, - "aes-128-ofb": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "OFB", - "type": "stream", - }, - "aes-192-ofb": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "OFB", - "type": "stream", - }, - "aes-256-ofb": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "OFB", - "type": "stream", - }, - "aes-128-ctr": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CTR", - "type": "stream", - }, - "aes-192-ctr": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CTR", - "type": "stream", - }, - "aes-256-ctr": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CTR", - "type": "stream", - }, - "aes-128-gcm": { - "cipher": "AES", - "key": 128, - "iv": 12, - "mode": "GCM", - "type": "auth", - }, - "aes-192-gcm": { - "cipher": "AES", - "key": 192, - "iv": 12, - "mode": "GCM", - "type": "auth", - }, - "aes-256-gcm": { - "cipher": "AES", - "key": 256, - "iv": 12, - "mode": "GCM", - "type": "auth", - }, -}; - -for (const mode of Object.values(MODES)) { - mode.module = modeModules[mode.mode]; -} diff --git a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ofb.js b/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ofb.js deleted file mode 100644 index 20ccdf015..000000000 --- a/ext/node/polyfills/_crypto/crypto_browserify/browserify_aes/modes/ofb.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// Copyright 2014-2017 browserify-aes contributors. All rights reserved. MIT license. -// Copyright 2013 Maxwell Krohn. All rights reserved. MIT license. -// Copyright 2009-2013 Jeff Mott. All rights reserved. MIT license. - -import { xor } from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/xor.ts"; -import { Buffer } from "internal:deno_node/polyfills/buffer.ts"; - -function getBlock(self) { - self._prev = self._cipher.encryptBlock(self._prev); - return self._prev; -} - -export const encrypt = function (self, chunk) { - while (self._cache.length < chunk.length) { - self._cache = Buffer.concat([self._cache, getBlock(self)]); - } - - const pad = self._cache.slice(0, chunk.length); - self._cache = self._cache.slice(chunk.length); - return xor(chunk, pad); -}; |
