{"name":"@noble/hashes","version":"2.2.0","description":"Audited & minimal 0-dependency JS implementation of SHA, RIPEMD, BLAKE, HMAC, HKDF, PBKDF & Scrypt","devDependencies":{"@paulmillr/jsbt":"0.5.0","@types/node":"25.3.0","fast-check":"4.2.0","prettier":"3.6.2","typescript":"6.0.2"},"scripts":{"bench":"node test/benchmark/noble.ts","bench:compare":"MBENCH_DIMS='algorithm,buffer,library' node test/benchmark/hashes.ts","bench:compare-scrypt":"MBENCH_DIMS='iters,library' MBENCH_FILTER='async' node test/benchmark/scrypt.ts","bench:install":"cd test/benchmark; npm install","build":"tsc","build:release":"npx --no @paulmillr/jsbt esbuild test/build","check":"npm run check:readme && npm run check:treeshake && npm run check:jsdoc","check:readme":"npx --no @paulmillr/jsbt readme package.json","check:treeshake":"npx --no @paulmillr/jsbt treeshake package.json test/build/out-treeshake","check:jsdoc":"npx --no @paulmillr/jsbt tsdoc package.json","build:clean":"rm *.{js,js.map,d.ts,d.ts.map} 2> /dev/null","format":"prettier --write 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'","test":"node test/index.ts","test:bun":"bun test/index.ts","test:deno":"deno --allow-env --allow-read test/index.ts","test:node20":"cd test; npx tsc; node compiled/test/index.js","test:dos":"node test/slow-dos.test.ts","test:slow":"node test/slow-big.test.ts","test:acvp":"node test/slow-acvp.test.ts","test:kdf":"node test/slow-kdf.test.ts"},"exports":{".":"./index.js","./_md.js":"./_md.js","./argon2.js":"./argon2.js","./blake1.js":"./blake1.js","./blake2.js":"./blake2.js","./blake3.js":"./blake3.js","./eskdf.js":"./eskdf.js","./hkdf.js":"./hkdf.js","./hmac.js":"./hmac.js","./legacy.js":"./legacy.js","./pbkdf2.js":"./pbkdf2.js","./scrypt.js":"./scrypt.js","./sha2.js":"./sha2.js","./sha3-addons.js":"./sha3-addons.js","./sha3.js":"./sha3.js","./webcrypto.js":"./webcrypto.js","./utils.js":"./utils.js"},"engines":{"node":">= 20.19.0"},"keywords":["sha1","sha2","sha3","blake","blake2","blake3","hmac","hkdf","pbkdf2","scrypt","sha256","sha512","keccak","ripemd160","kdf","hash","cryptography","security","noble"],"homepage":"https://paulmillr.com/noble/","funding":"https://paulmillr.com/funding/","repository":{"type":"git","url":"git+https://github.com/paulmillr/noble-hashes.git"},"type":"module","main":"index.js","module":"index.js","types":"index.d.ts","sideEffects":false,"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","gitHead":"81983c2fffac48aa69dabc260b4192ad597d2734","_id":"@noble/hashes@2.2.0","bugs":{"url":"https://github.com/paulmillr/noble-hashes/issues"},"_nodeVersion":"24.11.0","_npmVersion":"11.6.1","dist":{"integrity":"sha512-IYqDGiTXab6FniAgnSdZwgWbomxpy9FtYvLKs7wCUs2a8RkITG+DFGO1DM9cr+E3/RgADRpFjrKVaJ1z6sjtEg==","shasum":"22da1d16a469954fce877055d559900a6c73b63b","tarball":"http://registry-npm.ywwl.com/@noble/hashes/download/@noble/hashes-2.2.0.tgz","fileCount":98,"unpackedSize":889457,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@noble%2fhashes@2.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDJw6iTHwkrzpJ95R62Y9u27nIVwTbQ8jQDVDzT0SHtLQIhAOcyNcX2DcQoKIksDUQxD4/WJsdhK3JQCUFhn0KGg+gM"}],"size":180002,"noattachment":false,"key":"/@noble/hashes/-/@noble/hashes-2.2.0.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:592eccb8-e7de-4f51-97d9-6df33e8a0c82"}},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hashes_2.2.0_1775927380885_0.5675721637136342"},"_hasShrinkwrap":false,"readme":"# noble-hashes\n\nAudited & minimal JS implementation of hash functions, MACs and KDFs.\n\n- 🔒 [**Audited**](#security) by an independent security firm\n- 🔻 Tree-shakeable: unused code is excluded from your builds\n- 🏎 Fast: hand-optimized for caveats of JS engines\n- 🔍 Reliable: chained / sliding window / DoS / ACVP tests and fuzzing\n- 🔁 No unrolled loops: makes it easier to verify and reduces source code size up to 5x\n- 🦘 Includes SHA, RIPEMD, BLAKE, HMAC, HKDF, PBKDF, Scrypt, Argon2\n- 🥈 Optional, friendly wrapper over native WebCrypto\n- 🪶 22KB (gzipped) for everything, 2.4KB for single-hash build\n\nUse [awasm-noble](https://github.com/paulmillr/awasm-noble) if you need an even faster (WASM) alternative.\nCheck out [Upgrading](#upgrading) for information about upgrading from previous versions.\nTake a glance at [GitHub Discussions](https://github.com/paulmillr/noble-hashes/discussions) for questions and support.\n\nThe library's initial development was funded by [Ethereum Foundation](https://ethereum.org/).\n\n### This library belongs to _noble_ cryptography\n\n> **noble cryptography** — high-security, easily auditable set of contained cryptographic libraries and tools.\n\n- Zero or minimal dependencies\n- Highly readable TypeScript / JS code\n- PGP-signed releases and transparent NPM builds\n- All libraries:\n  [ciphers](https://github.com/paulmillr/noble-ciphers),\n  [curves](https://github.com/paulmillr/noble-curves),\n  [hashes](https://github.com/paulmillr/noble-hashes),\n  [post-quantum](https://github.com/paulmillr/noble-post-quantum),\n  5kb [secp256k1](https://github.com/paulmillr/noble-secp256k1) /\n  [ed25519](https://github.com/paulmillr/noble-ed25519)\n- [Check out the homepage](https://paulmillr.com/noble/)\n  for reading resources, documentation, and apps built with noble\n\n## Usage\n\n> `npm install @noble/hashes`\n\n> `deno add jsr:@noble/hashes`\n\nWe support all major platforms and runtimes.\nFor React Native, you may need a [polyfill for getRandomValues](https://github.com/LinusU/react-native-get-random-values).\nA standalone file [noble-hashes.js](https://github.com/paulmillr/noble-hashes/releases) is also available.\n\n```js\n// import * from '@noble/hashes'; // Error: use sub-imports, to ensure small app size\nimport { sha256 as noble_sha256 } from '@noble/hashes/sha2.js';\nconst hash = noble_sha256(Uint8Array.from([0xca, 0xfe, 0x01, 0x23]));\n\n// Available modules\nimport { sha256, sha384, sha512, sha224, sha512_224, sha512_256 } from '@noble/hashes/sha2.js';\nimport {\n  sha3_256, sha3_512,\n  keccak_256, keccak_512,\n  shake128, shake256,\n} from '@noble/hashes/sha3.js';\nimport {\n  cshake256, turboshake256, kmac256, tuplehash256,\n  kt128, kt256, keccakprg,\n} from '@noble/hashes/sha3-addons.js';\nimport { blake3 } from '@noble/hashes/blake3.js';\nimport { blake2b, blake2s } from '@noble/hashes/blake2.js';\nimport { blake256, blake512 } from '@noble/hashes/blake1.js';\nimport { sha1, md5, ripemd160 } from '@noble/hashes/legacy.js';\nimport { hmac } from '@noble/hashes/hmac.js';\nimport { hkdf } from '@noble/hashes/hkdf.js';\nimport { pbkdf2, pbkdf2Async } from '@noble/hashes/pbkdf2.js';\nimport { scrypt, scryptAsync } from '@noble/hashes/scrypt.js';\nimport { argon2d, argon2i, argon2id } from '@noble/hashes/argon2.js';\nimport * as webcrypto from '@noble/hashes/webcrypto.js';\n// const { sha256, sha384, sha512, hmac, hkdf, pbkdf2 } = webcrypto;\nimport * as utils from '@noble/hashes/utils.js';\nconst { bytesToHex, concatBytes, equalBytes, hexToBytes } = utils;\n```\n\n- [sha2: sha256, sha384, sha512](#sha2-sha256-sha384-sha512-and-others)\n- [sha3: FIPS, SHAKE, Keccak](#sha3-fips-shake-keccak)\n- [sha3-addons: cSHAKE, KMAC, KT128, TurboSHAKE](#sha3-addons-cshake-kmac-kt128-turboshake)\n- [blake1, blake2, blake3](#blake1-blake2-blake3)\n- [legacy: sha1, md5, ripemd160](#legacy-sha1-md5-ripemd160)\n- MACs: [hmac](#hmac) | [kmac](#sha3-addons-cshake-kmac-kt128-turboshake) | [blake3 key mode](#blake1-blake2-blake3)\n- KDFs: [hkdf](#hkdf) | [pbkdf2](#pbkdf2) | [scrypt](#scrypt) | [argon2](#argon2)\n- [webcrypto: friendly wrapper](#webcrypto-friendly-wrapper)\n- [utils](#utils)\n- [Security](#security) | [Speed](#speed) | [Contributing & testing](#contributing--testing) | [License](#license)\n\n### Implementations\n\nHash functions:\n\n- `sha256()`: receive & return `Uint8Array`\n- `sha256.create().update(a).update(b).digest()`: support partial updates\n- `blake3.create({ context: 'e', dkLen: 32 })`: can have options\n- support little-endian architecture; also experimentally big-endian\n- can hash up to 4GB per chunk, with any amount of chunks\n\n#### sha2: sha256, sha384, sha512 and others\n\n```typescript\nimport { sha224, sha256, sha384, sha512, sha512_224, sha512_256 } from '@noble/hashes/sha2.js';\nconst res = sha256(Uint8Array.from([0xbc])); // basic\nfor (let hash of [sha256, sha384, sha512, sha224, sha512_224, sha512_256]) {\n  const arr = Uint8Array.from([0x10, 0x20, 0x30]);\n  const a = hash(arr);\n  const b = hash.create().update(arr).digest();\n}\n```\n\nCheck out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and\n[the paper on truncated SHA512/256](https://eprint.iacr.org/2010/548.pdf).\n\n#### sha3: FIPS, SHAKE, Keccak\n\n```typescript\nimport {\n  sha3_224, sha3_256, sha3_384, sha3_512,\n  keccak_224, keccak_256, keccak_384, keccak_512,\n  shake128, shake256,\n} from '@noble/hashes/sha3.js';\nfor (let hash of [\n  sha3_224, sha3_256, sha3_384, sha3_512,\n  keccak_224, keccak_256, keccak_384, keccak_512,\n]) {\n  const arr = Uint8Array.from([0x10, 0x20, 0x30]);\n  const a = hash(arr);\n  const b = hash.create().update(arr).digest();\n}\nconst shka = shake128(Uint8Array.from([0x10]), { dkLen: 512 });\nconst shkb = shake256(Uint8Array.from([0x30]), { dkLen: 512 });\n```\n\nCheck out [FIPS-202](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf),\n[Website](https://keccak.team/keccak.html).\n\nCheck out [the differences between SHA-3 and Keccak](https://crypto.stackexchange.com/questions/15727/what-are-the-key-differences-between-the-draft-sha-3-standard-and-the-keccak-sub)\n\n#### sha3-addons: cSHAKE, KMAC, K12, TurboSHAKE\n\n```typescript\nimport {\n  cshake128, cshake256, kt128, kt256,\n  keccakprg, kmac128, kmac256,\n  parallelhash256, tuplehash256,\n  turboshake128, turboshake256,\n} from '@noble/hashes/sha3-addons.js';\nconst data = Uint8Array.from([0x10, 0x20, 0x30]);\nconst personalization = new TextEncoder().encode('def');\nconst ec1 = cshake128(data, { personalization });\nconst ec2 = cshake256(data, { personalization });\nconst et1 = turboshake128(data);\nconst et2 = turboshake256(data, { D: 0x05 });\n// tuplehash(['ab', 'c']) !== tuplehash(['a', 'bc']) !== tuplehash([data])\nconst et3 = tuplehash256([new TextEncoder().encode('ab'), new TextEncoder().encode('c')]);\n// Not parallel in JS (similar to blake3 / kt128), added for compat\nconst ep1 = parallelhash256(data, { blockLen: 8 });\nconst kk = Uint8Array.from([0xca]);\nconst ek10 = kmac128(kk, data);\nconst ek11 = kmac256(kk, data);\nconst ek12 = kt128(data); // kangarootwelve 128-bit\nconst ek13 = kt256(data); // kangarootwelve 256-bit\n// pseudo-random generator, first argument is capacity. XKCP recommends 254 bits capacity for 128-bit security strength.\n// * with a capacity of 254 bits.\nconst p = keccakprg(254);\np.addEntropy(Uint8Array.from([1, 2, 3]));\nconst rand1b = p.randomBytes(32);\n```\n\n- cSHAKE, KMAC, TupleHash, ParallelHash + XOF are available, matching\n  [NIST SP 800-185](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf)\n- Reduced-round Keccak KT128 (KangarooTwelve 🦘, K12) and TurboSHAKE are available, matching\n  [RFC 9861](https://datatracker.ietf.org/doc/rfc9861/).\n- [KeccakPRG](https://keccak.team/files/CSF-0.1.pdf): pseudo-random generator based on Keccak\n\n#### blake1, blake2, blake3\n\n```typescript\nimport { blake224, blake256, blake384, blake512 } from '@noble/hashes/blake1.js';\nimport { blake2b, blake2s } from '@noble/hashes/blake2.js';\nimport { blake3 } from '@noble/hashes/blake3.js';\n\nfor (let hash of [blake224, blake256, blake384, blake512, blake2b, blake2s, blake3]) {\n  const arr = Uint8Array.from([0x10, 0x20, 0x30]);\n  const a = hash(arr);\n  const b = hash.create().update(arr).digest();\n}\n\n// blake2 advanced usage\nconst ab = Uint8Array.from([0x01]);\nconst txt = new TextEncoder();\nblake2s(ab);\nblake2s(ab, { key: new Uint8Array(32) });\nblake2s(ab, { personalization: txt.encode('pers1234') });\nblake2s(ab, { salt: txt.encode('salt1234') });\nblake2b(ab);\nblake2b(ab, { key: new Uint8Array(64) });\nblake2b(ab, { personalization: txt.encode('pers1234pers1234') });\nblake2b(ab, { salt: txt.encode('salt1234salt1234') });\n\n// blake3 advanced usage\nblake3(ab);\nblake3(ab, { dkLen: 256 });\nblake3(ab, { key: new Uint8Array(32) });\nblake3(ab, { context: txt.encode('application-name') });\n```\n\n- Blake1 is legacy hash, one of SHA3 proposals. It is rarely used anywhere. See [pdf](https://www.aumasson.jp/blake/blake.pdf).\n- Blake2 is popular fast hash. blake2b focuses on 64-bit platforms while blake2s is for 8-bit to 32-bit ones. See [RFC 7693](https://datatracker.ietf.org/doc/html/rfc7693), [Website](https://www.blake2.net)\n- Blake3 is faster, reduced-round blake2. See [Website & specs](https://blake3.io)\n\n#### legacy: sha1, md5, ripemd160\n\nSHA1 (RFC 3174), MD5 (RFC 1321) and RIPEMD160 (RFC 2286) legacy, weak hash functions.\nDon't use them in a new protocol. What \"weak\" means:\n\n- Collisions can be made with 2^18 effort in MD5, 2^60 in SHA1, 2^80 in RIPEMD160.\n- No practical pre-image attacks (only theoretical, 2^123.4)\n- HMAC seems kinda ok: https://datatracker.ietf.org/doc/html/rfc6151\n\n```typescript\nimport { md5, ripemd160, sha1 } from '@noble/hashes/legacy.js';\nfor (let hash of [md5, ripemd160, sha1]) {\n  const arr = Uint8Array.from([0x10, 0x20, 0x30]);\n  const a = hash(arr);\n  const b = hash.create().update(arr).digest();\n}\n```\n\n#### hmac\n\n```typescript\nimport { hmac } from '@noble/hashes/hmac.js';\nimport { sha256 } from '@noble/hashes/sha2.js';\nconst key = new Uint8Array(32).fill(1);\nconst msg = new Uint8Array(32).fill(2);\nconst mac1 = hmac(sha256, key, msg);\nconst mac2 = hmac.create(sha256, key).update(msg).digest();\n```\n\nConforms to [RFC 2104](https://datatracker.ietf.org/doc/html/rfc2104).\n\n#### hkdf\n\n```typescript\nimport { hkdf } from '@noble/hashes/hkdf.js';\nimport { randomBytes } from '@noble/hashes/utils.js';\nimport { sha256 } from '@noble/hashes/sha2.js';\nconst inputKey = randomBytes(32);\nconst salt = randomBytes(32);\nconst info = new TextEncoder().encode('application-key');\nconst hk1 = hkdf(sha256, inputKey, salt, info, 32);\n\n// == same as\nimport { extract, expand } from '@noble/hashes/hkdf.js';\nconst prk = extract(sha256, inputKey, salt);\nconst hk2 = expand(sha256, prk, info, 32);\n```\n\nConforms to [RFC 5869](https://datatracker.ietf.org/doc/html/rfc5869).\n\n#### pbkdf2\n\n```typescript\nimport { pbkdf2, pbkdf2Async } from '@noble/hashes/pbkdf2.js';\nimport { sha256 } from '@noble/hashes/sha2.js';\nconst pbkey1 = pbkdf2(sha256, 'password', 'salt', { c: 524288, dkLen: 32 });\nconst pbkey2 = await pbkdf2Async(sha256, 'password', 'salt', { c: 524288, dkLen: 32 });\nconst pbkey3 = await pbkdf2Async(sha256, Uint8Array.from([1, 2, 3]), Uint8Array.from([4, 5, 6]), {\n  c: 524288,\n  dkLen: 32,\n});\n```\n\nConforms to [RFC 2898](https://datatracker.ietf.org/doc/html/rfc2898).\n\n#### scrypt\n\n```typescript\nimport { scrypt, scryptAsync } from '@noble/hashes/scrypt.js';\nconst scr1 = scrypt('password', 'salt', { N: 2 ** 16, r: 8, p: 1, dkLen: 32 });\nconst scr2 = await scryptAsync('password', 'salt', { N: 2 ** 16, r: 8, p: 1, dkLen: 32 });\nconst scr3 = await scryptAsync(Uint8Array.from([1, 2, 3]), Uint8Array.from([4, 5, 6]), {\n  N: 2 ** 17,\n  r: 8,\n  p: 1,\n  dkLen: 32,\n  onProgress(percentage) {\n    console.log('progress', percentage);\n  },\n  maxmem: 2 ** 32 + 128 * 8 * 1, // N * r * p * 128 + (128*r*p)\n});\n```\n\nConforms to [RFC 7914](https://datatracker.ietf.org/doc/html/rfc7914),\n[Website](https://www.tarsnap.com/scrypt.html)\n\n- `N, r, p` are work factors. It is common to only adjust N, while keeping `r: 8, p: 1`.\n  See [the blog post](https://blog.filippo.io/the-scrypt-parameters/).\n  JS doesn't support parallelization, making increasing `p` meaningless.\n- `dkLen` is the length of output bytes e.g. `32` or `64`\n- `onProgress` can be used with async version of the function to report progress to a user.\n- `maxmem` prevents DoS and is limited to `1GB + 1KB` (`2**30 + 2**10`), but can be adjusted using formula: `N * r * p * 128 + (128 * r * p)`\n\nTime it takes to derive Scrypt key under different values of N (2\\*\\*N) on Apple M4 (mobile phones can be 1x-4x slower):\n\n| N pow | Time | RAM   |\n| ----- | ---- | ----- |\n| 16    | 0.1s | 64MB  |\n| 17    | 0.2s | 128MB |\n| 18    | 0.4s | 256MB |\n| 19    | 0.8s | 512MB |\n| 20    | 1.5s | 1GB   |\n| 21    | 3.1s | 2GB   |\n| 22    | 6.2s | 4GB   |\n| 23    | 13s  | 8GB   |\n| 24    | 27s  | 16GB  |\n\n> [!NOTE]\n> We support N larger than `2**20` where available, however,\n> not all JS engines support >= 2GB ArrayBuffer-s.\n> When using such N, you'll need to manually adjust `maxmem`, using formula above.\n> Other JS implementations don't support large N-s.\n\n#### argon2\n\n```ts\nimport { argon2d, argon2i, argon2id } from '@noble/hashes/argon2.js';\nconst arg1 = argon2id('password', 'saltsalt', { t: 2, m: 65536, p: 1, maxmem: 2 ** 32 - 1 });\n```\n\nArgon2 [RFC 9106](https://datatracker.ietf.org/doc/html/rfc9106) implementation.\n\n> [!WARNING]\n> Argon2 can't be fast in JS, because there is no fast Uint64Array.\n> It is suggested to use [Scrypt](#scrypt) instead.\n> Being 5x slower than native code means brute-forcing attackers have bigger advantage.\n\n#### webcrypto: friendly wrapper\n\n```js\nimport { sha256, sha384, sha512, hmac, hkdf, pbkdf2 } from '@noble/hashes/webcrypto.js';\nimport { randomBytes } from '@noble/hashes/utils.js';\nconst whash = await sha256(Uint8Array.from([0xca, 0xfe, 0x01, 0x23]));\n\nconst key = new Uint8Array(32).fill(1);\nconst msg = new Uint8Array(32).fill(2);\nconst wmac = await hmac(sha256, key, msg);\n\nconst inputKey = randomBytes(32);\nconst salt = randomBytes(32);\nconst info = new TextEncoder().encode('application-key');\nconst hk1 = await hkdf(sha256, inputKey, salt, info, 32);\n\nconst pbkey1 = await pbkdf2(sha256, 'password', 'salt', { c: 524288, dkLen: 32 });\n```\n\nSometimes people want to use built-in `crypto.subtle` instead of pure JS implementation.\nHowever, it has terrible API.\n\nWe simplify access to built-ins with API which mirrors noble-hashes.\nThe overhead is minimal - just 30+ lines of code, which verify input correctness.\n\n> [!NOTE]\n> Webcrypto methods are always async.\n\n#### utils\n\n```typescript\nimport { bytesToHex as toHex, randomBytes } from '@noble/hashes/utils.js';\nconsole.log(toHex(randomBytes(32)));\n```\n\n- `bytesToHex` will convert `Uint8Array` to a hex string\n- `randomBytes(bytes)` will produce cryptographically secure random `Uint8Array` of length `bytes`\n\n## Security\n\nThe library has been audited:\n\n- at version 2.2.0, in Apr 2026, by ourselves (self-audited)\n  - Scope: everything\n  - [Changes since audit](https://github.com/paulmillr/noble-hashes/compare/2.2.0..main)\n- at version 1.0.0, in Jan 2022, independently, by [Cure53](https://cure53.de)\n  - PDFs: [website](https://cure53.de/pentest-report_hashing-libs.pdf), [in-repo](./audit/2022-01-05-cure53-audit-nbl2.pdf)\n  - Scope: everything, besides `blake3`, `sha3-addons`, `sha1` and `argon2`, which have not been audited\n  - The audit has been funded by [Ethereum Foundation](https://ethereum.org/en/) with help of [Nomic Labs](https://nomiclabs.io)\n\nIt is tested against property-based, cross-library and Wycheproof vectors,\nand is being fuzzed in [the separate repo](https://github.com/paulmillr/fuzzing).\n\nIf you see anything unusual: investigate and report.\n\n### Constant-timeness\n\nWe're targetting algorithmic constant time. _JIT-compiler_ and _Garbage Collector_ make \"constant time\"\nextremely hard to achieve [timing attack](https://en.wikipedia.org/wiki/Timing_attack) resistance\nin a scripting language. Which means _any other JS library can't have\nconstant-timeness_. Even statically typed Rust, a language without GC,\n[makes it harder to achieve constant-time](https://www.chosenplaintext.ca/open-source/rust-timing-shield/security)\nfor some cases. If your goal is absolute security, don't use any JS lib — including bindings to native ones.\nUse low-level libraries & languages.\n\n### Memory dumping\n\nThe library shares state buffers between hash\nfunction calls. The buffers are zeroed-out after each call. However, if an attacker\ncan read application memory, you are doomed in any case:\n\n- At some point, input will be a string and strings are immutable in JS:\n  there is no way to overwrite them with zeros. For example: deriving\n  key from `scrypt(password, salt)` where password and salt are strings\n- Input from a file will stay in file buffers\n- Input / output will be re-used multiple times in application which means it could stay in memory\n- `await anything()` will always write all internal variables (including numbers)\n  to memory. With async functions / Promises there are no guarantees when the code\n  chunk would be executed. Which means attacker can have plenty of time to read data from memory\n- There is no way to guarantee anything about zeroing sensitive data without\n  complex tests-suite which will dump process memory and verify that there is\n  no sensitive data left. For JS it means testing all browsers (incl. mobile),\n  which is complex. And of course it will be useless without using the same\n  test-suite in the actual application that consumes the library\n\n### Supply chain security\n\n- **Commits** are signed with PGP keys to prevent forgery. Be sure to verify the commit signatures\n- **Releases** are made transparently through token-less GitHub CI and Trusted Publishing. Be sure to verify the [provenance logs](https://docs.npmjs.com/generating-provenance-statements) for authenticity.\n- **Rare releasing** is practiced to minimize the need for re-audits by end-users.\n- **Dependencies** are minimized and strictly pinned to reduce supply-chain risk.\n  - We use as few dependencies as possible.\n  - Version ranges are locked, and changes are checked with npm-diff.\n- **Dev dependencies** are excluded from end-user installs; they’re only used for development and build steps.\n\nFor this package, there are 0 dependencies; and a few dev dependencies:\n\n- jsbt contains helpers for building, benchmarking & testing secure JS apps. It is developed by the same author\n- prettier, fast-check and typescript are used for code quality / test generation / ts compilation\n\n### Randomness\n\nWe rely on the built-in\n[`crypto.getRandomValues`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues),\nwhich is considered a cryptographically secure PRNG.\n\nBrowsers have had weaknesses in the past - and could again - but implementing a userspace CSPRNG is even worse, as there’s no reliable userspace source of high-quality entropy.\n\n### Quantum computers\n\nCryptographically relevant quantum computer, if built, will allow to\nutilize Grover's algorithm to break hashes in 2^n/2 operations, instead of 2^n.\n\nThis means SHA256 should be replaced with SHA512, SHA3-256 with SHA3-512, SHAKE128 with SHAKE256 etc.\n\nAustralian ASD prohibits SHA256 and similar hashes [after 2030](https://www.cyber.gov.au/resources-business-and-government/essential-cyber-security/ism/cyber-security-guidelines/guidelines-cryptography).\n\n## Upgrading\n\nSupported node.js versions:\n\n- v2: v20.19+ (ESM-only)\n- v1: v14.21+ (ESM & CJS)\n\nv2.0 changelog:\n\n- The package is now ESM-only. ESM can finally be loaded from common.js on node v20.19+\n- `.js` extension must be used for all modules\n    - Old: `@noble/hashes/sha3`\n    - New: `@noble/hashes/sha3.js`\n    - This simplifies working in browsers natively without transpilers\n- Only allow Uint8Array as hash inputs, prohibit `string`\n    - Strict validation checks improve security\n    - To replicate previous behavior, use `utils.utf8ToBytes`\n- Rename / remove some modules for consistency. Previously, sha384 resided in sha512, which was weird\n    - `sha256`, `sha512` => `sha2.js` (consistent with `sha3.js`)\n    - `blake2b`, `blake2s` => `blake2.js` (consistent with `blake3.js`, `blake1.js`)\n    - `ripemd160`, `sha1`, `md5` => `legacy.js` (all low-security hashes are there)\n    - `_assert` => `utils.js`\n    - `crypto` internal module got removed: use built-in WebCrypto instead\n- Improve typescript types & option autocomplete\n- Bump compilation target from es2020 to es2022\n\n## Contributing & testing\n\n`test/misc` directory contains implementations of loop unrolling and md5.\n\n- `npm install && npm run build && npm test` will build the code and run tests.\n- `npm run lint` / `npm run format` will run linter / fix linter issues.\n- `npm run bench` will run benchmarks\n- `npm run build:release` will build single file\n- There is **additional** 20-min DoS test `npm run test:dos` and 2-hour multicore test `npm run test:slow`.\n  See [our approach to testing](./test/README.md)\n\nSome hashes are outside of scope of the library:\n- [Pedersen in micro-zk-proofs](https://github.com/paulmillr/micro-zk-proofs/blob/1ed5ce1253583b2e540eef7f3477fb52bf5344ff/src/pedersen.ts)\n- [Poseidon in noble-curves](https://github.com/paulmillr/noble-curves/blob/3d124dd3ecec8b6634cc0b2ba1c183aded5304f9/src/abstract/poseidon.ts)\n- [Poly1305 & GHash in noble-ciphers](https://github.com/paulmillr/noble-ciphers)\n\nSee [paulmillr.com/noble](https://paulmillr.com/noble/) for useful resources, articles, documentation and demos related to the library.\n\n## Speed\n\n```sh\nnpm run bench\n```\n\nBenchmarks measured on Apple M4. If you need truly exemplar performance, switch to [awasm-noble](https://github.com/paulmillr/awasm-noble).\n\n```\n# 32B\nsha256 x 2,016,129 ops/sec @ 496ns/op\nsha512 x 740,740 ops/sec @ 1μs/op\nsha3_256 x 287,686 ops/sec @ 3μs/op\nsha3_512 x 288,267 ops/sec @ 3μs/op\nk12 x 476,190 ops/sec @ 2μs/op\nblake2b x 410,340 ops/sec @ 2μs/op\nblake2s x 942,507 ops/sec @ 1μs/op\nblake3 x 1,006,036 ops/sec @ 994ns/op\nripemd160 x 1,410,437 ops/sec @ 709ns/op\nmd5 x 1,663,893 ops/sec @ 601ns/op\nsha1 x 1,589,825 ops/sec @ 629ns/op\n\n# 1MB\nsha256 x 331 ops/sec @ 3ms/op\nsha512 x 128 ops/sec @ 7ms/op\nsha3_256 x 39 ops/sec @ 25ms/op\nsha3_512 x 21 ops/sec @ 46ms/op\nkt128 x 91 ops/sec @ 10ms/op\nkt256 x 75 ops/sec @ 13ms/op\nturboshake128 x 93 ops/sec @ 10ms/op\nblake256 x 57 ops/sec @ 17ms/op\nblake2b x 61 ops/sec @ 16ms/op\nblake2s x 78 ops/sec @ 12ms/op\nblake3 x 95 ops/sec @ 10ms/op\nripemd160 x 177 ops/sec @ 5ms/op\nmd5 x 250 ops/sec @ 3ms/op\nsha1 x 416 ops/sec @ 2ms/op\n\n# MAC\nhmac(sha256) x 599,880 ops/sec @ 1μs/op\nhmac(sha512) x 197,122 ops/sec @ 5μs/op\nkmac256 x 87,981 ops/sec @ 11μs/op\nblake3(key) x 796,812 ops/sec @ 1μs/op\n\n# KDF\nhkdf(sha256) x 259,942 ops/sec @ 3μs/op\nblake3(context) x 424,808 ops/sec @ 2μs/op\npbkdf2(sha256, c: 2 ** 18) x 5 ops/sec @ 197ms/op\npbkdf2(sha512, c: 2 ** 18) x 1 ops/sec @ 630ms/op\nscrypt(n: 2 ** 18, r: 8, p: 1) x 2 ops/sec @ 400ms/op\nargon2id(t: 1, m: 256MB) 2881ms\n```\n\nThe library could be 3x faster by utilizing loop unrolling. It isn't used because\nunrolling a) would increase bundle size b) make lib un-readable c) current perf is \"fast enough\"\nfor most use-cases.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2022 Paul Miller [(https://paulmillr.com)](https://paulmillr.com)\n\nSee LICENSE file.\n","publish_time":1775927381131,"_cnpm_publish_time":1775927381131,"dist-tags":{"latest":"2.4.0"}}