Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@noble/hashes

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@noble/hashes - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

lib/crypto.d.ts

9

lib/_sha2.js

@@ -9,5 +9,8 @@ "use strict";

return view.setBigUint64(byteOffset, value, isLE);
const wh = Number((value >> 32n) & 0xffffffffn);
const wl = Number(value & 0xffffffffn);
const [h, l] = isLE ? [4, 0] : [0, 4];
const _32n = BigInt(32);
const _u32_max = BigInt(0xffffffff);
const wh = Number((value >> _32n) & _u32_max);
const wl = Number(value & _u32_max);
const h = isLE ? 4 : 0;
const l = isLE ? 0 : 4;
view.setUint32(byteOffset + h, wh, isLE);

@@ -14,0 +17,0 @@ view.setUint32(byteOffset + l, wl, isLE);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.add5H = exports.add5L = exports.add4H = exports.add4L = exports.add3H = exports.add3L = exports.add = exports.rotlBL = exports.rotlBH = exports.rotlSL = exports.rotlSH = exports.rotr32L = exports.rotr32H = exports.rotrBL = exports.rotrBH = exports.rotrSL = exports.rotrSH = exports.shrSL = exports.shrSH = exports.toBig = exports.split = exports.fromBig = void 0;
const U32_MASK64 = 2n ** 32n - 1n;
const U32_MASK64 = BigInt(2 ** 32 - 1);
const _32n = BigInt(32);
function fromBig(n, le = false) {
if (le)
return { h: Number(n & U32_MASK64), l: Number((n >> 32n) & U32_MASK64) };
return { h: Number((n >> 32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
}
exports.fromBig = fromBig;
function split(lst, le = false) {
let [Ah, Al] = [new Uint32Array(lst.length), new Uint32Array(lst.length)];
let Ah = new Uint32Array(lst.length);
let Al = new Uint32Array(lst.length);
for (let i = 0; i < lst.length; i++) {

@@ -20,3 +22,3 @@ const { h, l } = fromBig(lst[i], le);

exports.split = split;
const toBig = (h, l) => (BigInt(h >>> 0) << 32n) | BigInt(l >>> 0);
const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
exports.toBig = toBig;

@@ -23,0 +25,0 @@ // for Shift in [0, 32)

@@ -30,4 +30,4 @@ import * as blake2 from './_blake2';

private writeInto;
XOFInto(out: Uint8Array): Uint8Array;
XOF(bytes: number): Uint8Array;
xofInto(out: Uint8Array): Uint8Array;
xof(bytes: number): Uint8Array;
digestInto(out: Uint8Array): Uint8Array;

@@ -34,0 +34,0 @@ digest(): Uint8Array;

@@ -232,3 +232,3 @@ "use strict";

}
XOFInto(out) {
xofInto(out) {
if (!this.enableXOF)

@@ -238,5 +238,5 @@ throw new Error('XOF impossible after digest call');

}
XOF(bytes) {
xof(bytes) {
(0, utils_1.assertNumber)(bytes);
return this.XOFInto(new Uint8Array(bytes));
return this.xofInto(new Uint8Array(bytes));
}

@@ -243,0 +243,0 @@ digestInto(out) {

@@ -11,3 +11,4 @@ "use strict";

const Pi = Id.map((i) => (9 * i + 5) % 16);
let [idxL, idxR] = [[Id], [Pi]];
let idxL = [Id];
let idxR = [Pi];
for (let i = 0; i < 4; i++)

@@ -14,0 +15,0 @@ for (let j of [idxL, idxR])

@@ -78,3 +78,4 @@ "use strict";

// The block B is r 128-byte chunks (which is equivalent of 2r 64-byte chunks)
let [head, tail] = [oi + 0, oi + 16 * r];
let head = oi + 0;
let tail = oi + 16 * r;
for (let i = 0; i < 16; i++)

@@ -81,0 +82,0 @@ out[tail + i] = input[ii + (2 * r - 1) * 16 + i]; // X ← B[2r−1]

@@ -324,3 +324,3 @@ "use strict";

fetch(bytes) {
return this.XOF(bytes);
return this.xof(bytes);
}

@@ -327,0 +327,0 @@ // Ensure irreversibility (even if state leaked previous outputs cannot be computed)

@@ -20,4 +20,4 @@ import { Hash, Input, HashXOF } from './utils';

protected writeInto(out: Uint8Array): Uint8Array;
XOFInto(out: Uint8Array): Uint8Array;
XOF(bytes: number): Uint8Array;
xofInto(out: Uint8Array): Uint8Array;
xof(bytes: number): Uint8Array;
digestInto(out: Uint8Array): Uint8Array;

@@ -24,0 +24,0 @@ digest(): Uint8Array;

@@ -27,3 +27,9 @@ "use strict";

const [SHA3_PI, SHA3_ROTL, _SHA3_IOTA] = [[], [], []];
for (let round = 0, R = 1n, x = 1, y = 0; round < 24; round++) {
const _0n = BigInt(0);
const _1n = BigInt(1);
const _2n = BigInt(2);
const _7n = BigInt(7);
const _256n = BigInt(256);
const _0x71n = BigInt(0x71);
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
// Pi

@@ -35,7 +41,7 @@ [x, y] = [y, (2 * x + 3 * y) % 5];

// Iota
let t = 0n;
let t = _0n;
for (let j = 0; j < 7; j++) {
R = ((R << 1n) ^ ((R >> 7n) * 0x71n)) % 256n;
if (R & 2n)
t ^= 1n << ((1n << BigInt(j)) - 1n);
R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
if (R & _2n)
t ^= _1n << ((_1n << BigInt(j)) - _1n);
}

@@ -166,3 +172,3 @@ _SHA3_IOTA.push(t);

}
XOFInto(out) {
xofInto(out) {
// Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF

@@ -173,5 +179,5 @@ if (!this.enableXOF)

}
XOF(bytes) {
xof(bytes) {
(0, utils_1.assertNumber)(bytes);
return this.XOFInto(new Uint8Array(bytes));
return this.xofInto(new Uint8Array(bytes));
}

@@ -178,0 +184,0 @@ digestInto(out) {

@@ -29,23 +29,23 @@ "use strict";

const [SHA512_Kh, SHA512_Kl] = u64.split([
0x428a2f98d728ae22n, 0x7137449123ef65cdn, 0xb5c0fbcfec4d3b2fn, 0xe9b5dba58189dbbcn,
0x3956c25bf348b538n, 0x59f111f1b605d019n, 0x923f82a4af194f9bn, 0xab1c5ed5da6d8118n,
0xd807aa98a3030242n, 0x12835b0145706fben, 0x243185be4ee4b28cn, 0x550c7dc3d5ffb4e2n,
0x72be5d74f27b896fn, 0x80deb1fe3b1696b1n, 0x9bdc06a725c71235n, 0xc19bf174cf692694n,
0xe49b69c19ef14ad2n, 0xefbe4786384f25e3n, 0x0fc19dc68b8cd5b5n, 0x240ca1cc77ac9c65n,
0x2de92c6f592b0275n, 0x4a7484aa6ea6e483n, 0x5cb0a9dcbd41fbd4n, 0x76f988da831153b5n,
0x983e5152ee66dfabn, 0xa831c66d2db43210n, 0xb00327c898fb213fn, 0xbf597fc7beef0ee4n,
0xc6e00bf33da88fc2n, 0xd5a79147930aa725n, 0x06ca6351e003826fn, 0x142929670a0e6e70n,
0x27b70a8546d22ffcn, 0x2e1b21385c26c926n, 0x4d2c6dfc5ac42aedn, 0x53380d139d95b3dfn,
0x650a73548baf63den, 0x766a0abb3c77b2a8n, 0x81c2c92e47edaee6n, 0x92722c851482353bn,
0xa2bfe8a14cf10364n, 0xa81a664bbc423001n, 0xc24b8b70d0f89791n, 0xc76c51a30654be30n,
0xd192e819d6ef5218n, 0xd69906245565a910n, 0xf40e35855771202an, 0x106aa07032bbd1b8n,
0x19a4c116b8d2d0c8n, 0x1e376c085141ab53n, 0x2748774cdf8eeb99n, 0x34b0bcb5e19b48a8n,
0x391c0cb3c5c95a63n, 0x4ed8aa4ae3418acbn, 0x5b9cca4f7763e373n, 0x682e6ff3d6b2b8a3n,
0x748f82ee5defb2fcn, 0x78a5636f43172f60n, 0x84c87814a1f0ab72n, 0x8cc702081a6439ecn,
0x90befffa23631e28n, 0xa4506cebde82bde9n, 0xbef9a3f7b2c67915n, 0xc67178f2e372532bn,
0xca273eceea26619cn, 0xd186b8c721c0c207n, 0xeada7dd6cde0eb1en, 0xf57d4f7fee6ed178n,
0x06f067aa72176fban, 0x0a637dc5a2c898a6n, 0x113f9804bef90daen, 0x1b710b35131c471bn,
0x28db77f523047d84n, 0x32caab7b40c72493n, 0x3c9ebe0a15c9bebcn, 0x431d67c49c100d4cn,
0x4cc5d4becb3e42b6n, 0x597f299cfc657e2an, 0x5fcb6fab3ad6faecn, 0x6c44198c4a475817n
]);
'0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
'0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
'0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
'0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
'0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
'0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
'0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
'0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
'0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
'0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
'0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
'0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
'0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
'0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
'0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
'0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
'0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
'0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
'0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
'0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
].map(n => BigInt(n)));
// Temporary buffer, not used to store anything between runs

@@ -52,0 +52,0 @@ const SHA512_W_H = new Uint32Array(80);

@@ -27,4 +27,4 @@ /*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */

export declare type HashXOF<T extends Hash<T>> = Hash<T> & {
XOF(bytes: number): Uint8Array;
XOFInto(buf: Uint8Array): Uint8Array;
xof(bytes: number): Uint8Array;
xofInto(buf: Uint8Array): Uint8Array;
};

@@ -48,7 +48,3 @@ declare type EmptyObj = {};

};
export declare const crypto: {
node?: any;
web?: Crypto;
};
export declare function randomBytes(bytesLength?: number): Uint8Array;
export {};
"use strict";
/*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomBytes = exports.crypto = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.checkOpts = exports.Hash = exports.assertHash = exports.assertBool = exports.assertNumber = exports.toBytes = exports.asyncLoop = exports.nextTick = exports.bytesToHex = exports.isLE = exports.rotr = exports.createView = exports.u32 = exports.u8 = void 0;
exports.randomBytes = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.checkOpts = exports.Hash = exports.assertHash = exports.assertBool = exports.assertNumber = exports.toBytes = exports.asyncLoop = exports.nextTick = exports.bytesToHex = exports.isLE = exports.rotr = exports.createView = exports.u32 = exports.u8 = void 0;
// The import here is via the package name. This is to ensure
// that exports mapping/resolution does fall into place.
const crypto_1 = require("@noble/hashes/lib/crypto");
// Cast array to different type

@@ -123,16 +126,8 @@ const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);

exports.wrapConstructorWithOpts = wrapConstructorWithOpts;
exports.crypto = (() => {
const webCrypto = typeof self === 'object' && 'crypto' in self ? self.crypto : undefined;
const nodeRequire = typeof module !== 'undefined' && typeof require === 'function';
return {
node: nodeRequire && !webCrypto ? require('crypto') : undefined,
web: webCrypto,
};
})();
function randomBytes(bytesLength = 32) {
if (exports.crypto.web) {
return exports.crypto.web.getRandomValues(new Uint8Array(bytesLength));
if (crypto_1.crypto.web) {
return crypto_1.crypto.web.getRandomValues(new Uint8Array(bytesLength));
}
else if (exports.crypto.node) {
return new Uint8Array(exports.crypto.node.randomBytes(bytesLength).buffer);
else if (crypto_1.crypto.node) {
return new Uint8Array(crypto_1.crypto.node.randomBytes(bytesLength).buffer);
}

@@ -139,0 +134,0 @@ else {

{
"name": "@noble/hashes",
"version": "0.4.1",
"version": "0.4.2",
"description": "Fast 0-dependency JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2, Scrypt",
"main": "lib/index.js",
"directories": {

@@ -16,3 +15,3 @@ "lib": "lib",

"bench-install": "cd test/benchmark && npm install && cd ../../",
"build": "tsc -d",
"build": "tsc -d && tsc -p tsconfig.esm.json",
"build-release": "rollup -c rollup.config.js",

@@ -34,8 +33,7 @@ "lint": "prettier --print-width 100 --single-quote --check src",

"devDependencies": {
"@rollup/plugin-commonjs": "21.0.0",
"@rollup/plugin-node-resolve": "13.0.5",
"@rollup/plugin-node-resolve": "13.0.6",
"micro-bmark": "^0.1.3",
"micro-should": "^0.2.0",
"prettier": "2.4.1",
"rollup": "~2.59.0",
"rollup": "~2.60.1",
"typescript": "~4.4.0"

@@ -63,3 +61,82 @@ },

"noble"
]
],
"exports": {
"./lib": {
"import": "./lib/esm/index.js",
"default": "./lib/index.js"
},
"./lib/crypto": {
"browser": {
"import": "./lib/esm/cryptoBrowser.js",
"default": "./lib/crypto.js"
},
"import": "./lib/esm/cryptoNode.js",
"default": "./lib/crypto.js"
},
"./lib/blake2b": {
"import": "./lib/esm/blake2b.js",
"default": "./lib/blake2b.js"
},
"./lib/blake2b.d.ts": "./lib/blake2b.d.ts",
"./lib/blake2s": {
"import": "./lib/esm/blake2s.js",
"default": "./lib/blake2s.js"
},
"./lib/blake2s.d.ts": "./lib/blake2s.d.ts",
"./lib/blake3": {
"import": "./lib/esm/blake3.js",
"default": "./lib/blake3.js"
},
"./lib/blake3.d.ts": "./lib/blake3.d.ts",
"./lib/hkdf": {
"import": "./lib/esm/hkdf.js",
"default": "./lib/hkdf.js"
},
"./lib/hkdf.d.ts": "./lib/hkdf.d.ts",
"./lib/hmac": {
"import": "./lib/esm/hmac.js",
"default": "./lib/hmac.js"
},
"./lib/hmac.d.ts": "./lib/hmac.d.ts",
"./lib/pbkdf2": {
"import": "./lib/esm/pbkdf2.js",
"default": "./lib/pbkdf2.js"
},
"./lib/pbkdf2.d.ts": "./lib/pbkdf2.d.ts",
"./lib/ripemd160": {
"import": "./lib/esm/ripemd160.js",
"default": "./lib/ripemd160.js"
},
"./lib/ripemd160.d.ts": "./lib/ripemd160.d.ts",
"./lib/scrypt": {
"import": "./lib/esm/scrypt.js",
"default": "./lib/scrypt.js"
},
"./lib/scrypt.d.ts": "./lib/scrypt.d.ts",
"./lib/sha3-addons": {
"import": "./lib/esm/sha3-addons.js",
"default": "./lib/sha3-addons.js"
},
"./lib/sha3-addons.d.ts": "./lib/sha3-addons.d.ts",
"./lib/sha3": {
"import": "./lib/esm/sha3.js",
"default": "./lib/sha3.js"
},
"./lib/sha3.d.ts": "./lib/sha3.d.ts",
"./lib/sha256": {
"import": "./lib/esm/sha256.js",
"default": "./lib/sha256.js"
},
"./lib/sha256.d.ts": "./lib/sha256.d.ts",
"./lib/sha512": {
"import": "./lib/esm/sha512.js",
"default": "./lib/sha512.js"
},
"./lib/sha512.d.ts": "./lib/sha512.d.ts",
"./lib/utils": {
"import": "./lib/esm/utils.js",
"default": "./lib/utils.js"
},
"./lib/utils.d.ts": "./lib/utils.d.ts"
}
}

@@ -114,3 +114,3 @@ # noble-hashes ![Node CI](https://github.com/paulmillr/noble-hashes/workflows/Node%20CI/badge.svg) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

- [SHA3 (FIPS, SHAKE, Keccak)](#sha3-fips-shake-keccak)
- [SHA3 Addons (cSHAKE, KMAC, KangarooTwelve, MarsupilamiFourteen)](#sha3-addons-cshake-kmac-kangarootwelve-marsupilamifourteen)
- [SHA3 Addons (cSHAKE, KMAC, KangarooTwelve, MarsupilamiFourteen)](#sha3-addons-cshake-kmac-tuplehash-parallelhash-kangarootwelve-marsupilamifourteen)
- [RIPEMD-160](#ripemd-160)

@@ -192,3 +192,3 @@ - [BLAKE2b, BLAKE2s](#blake2b-blake2s)

##### SHA3 Addons (cSHAKE, KMAC, TupleHash, ParalllelHash, KangarooTwelve, MarsupilamiFourteen)
##### SHA3 Addons (cSHAKE, KMAC, TupleHash, ParallelHash, KangarooTwelve, MarsupilamiFourteen)

@@ -374,3 +374,3 @@ ```typescript

Benchmarks measured on Apple M1 with macOS 12 using 32-byte inputs.
Benchmarks measured on Apple M1 with macOS 12.
Note that PBKDF2 and Scrypt are tested with extremely high work factor.

@@ -380,14 +380,14 @@ To run benchmarks, execute `npm run bench-install` and then `npm run bench`

```
SHA256 x 1,131,221 ops/sec @ 884ns/op
SHA384 x 452,284 ops/sec @ 2μs/op
SHA512 x 451,059 ops/sec @ 2μs/op
SHA3-256, keccak256, shake256 x 185,494 ops/sec @ 5μs/op
Kangaroo12 x 300,480 ops/sec @ 3μs/op
Marsupilami14 x 269,614 ops/sec @ 3μs/op
BLAKE2b x 291,375 ops/sec @ 3μs/op
BLAKE2s x 505,561 ops/sec @ 1μs/op
BLAKE3 x 576,036 ops/sec @ 1μs/op
HMAC-SHA256 x 342,583 ops/sec @ 2μs/op
RIPEMD160 x 1,191,895 ops/sec @ 839ns/op
HKDF-SHA256 x 115,500 ops/sec @ 8μs/op
SHA256 32B x 1,126,126 ops/sec @ 888ns/op
SHA384 32B x 443,458 ops/sec @ 2μs/op
SHA512 32B x 448,631 ops/sec @ 2μs/op
SHA3-256, keccak256, shake256 32B x 183,621 ops/sec @ 5μs/op
Kangaroo12 32B x 310,077 ops/sec @ 3μs/op
Marsupilami14 32B x 278,164 ops/sec @ 3μs/op
BLAKE2b 32B x 297,353 ops/sec @ 3μs/op
BLAKE2s 32B x 507,614 ops/sec @ 1μs/op
BLAKE3 32B x 584,795 ops/sec @ 1μs/op
RIPEMD160 32B x 1,186,239 ops/sec @ 843ns/op
HMAC-SHA256 32B x 346,860 ops/sec @ 2μs/op
HKDF-SHA256 32B x 153,045 ops/sec @ 6μs/op
PBKDF2-HMAC-SHA256 262144 x 2 ops/sec @ 338ms/op

@@ -394,0 +394,0 @@ PBKDF2-HMAC-SHA512 262144 x 0 ops/sec @ 1024ms/op

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc