{"name":"@noble/hashes","version":"1.7.0","keywords":["sha","sha2","sha3","sha256","sha512","keccak","kangarootwelve","ripemd160","blake2","blake3","hmac","hkdf","pbkdf2","scrypt","kdf","hash","cryptography","security","noble"],"author":{"url":"https://paulmillr.com","name":"Paul Miller"},"license":"MIT","_id":"@noble/hashes@1.7.0","homepage":"https://paulmillr.com/noble/","bugs":{"url":"https://github.com/paulmillr/noble-hashes/issues"},"dist":{"shasum":"5d9e33af2c7d04fee35de1519b80c958b2e35e39","tarball":"http://registry-npm.ywwl.com/@noble/hashes/download/@noble/hashes-1.7.0.tgz","fileCount":220,"integrity":"sha512-HXydb0DgzTpDPwbVeDGCG1gIu7X6+AuU6Zl6av/E/KG8LMsvPntvq+w17CHRpKBmN6Ybdrt1eP3k4cj8DJa78w==","signatures":[{"sig":"MEQCIAi3f8HYMKiqg6K2MnEi6X9e8MLqlqPhPr4f/Z5GHxopAiBKN2R3OrZ3bAXCTFEiacUTOvSvsIBhvIrquxG27O7vwg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":924107,"size":133040,"noattachment":false,"key":"/@noble/hashes/-/@noble/hashes-1.7.0.tgz"},"types":"./index.d.ts","browser":{"./crypto":"./crypto.js","node:crypto":false},"engines":{"node":"^14.21.3 || >=16"},"exports":{".":{"import":"./esm/index.js","require":"./index.js"},"./_md":{"import":"./esm/_md.js","require":"./_md.js"},"./hkdf":{"import":"./esm/hkdf.js","require":"./hkdf.js"},"./hmac":{"import":"./esm/hmac.js","require":"./hmac.js"},"./sha1":{"import":"./esm/sha1.js","require":"./sha1.js"},"./sha2":{"import":"./esm/sha2.js","require":"./sha2.js"},"./sha3":{"import":"./esm/sha3.js","require":"./sha3.js"},"./eskdf":{"import":"./esm/eskdf.js","require":"./eskdf.js"},"./utils":{"import":"./esm/utils.js","require":"./utils.js"},"./argon2":{"import":"./esm/argon2.js","require":"./argon2.js"},"./blake3":{"import":"./esm/blake3.js","require":"./blake3.js"},"./crypto":{"node":{"import":"./esm/cryptoNode.js","default":"./cryptoNode.js"},"import":"./esm/crypto.js","default":"./crypto.js"},"./pbkdf2":{"import":"./esm/pbkdf2.js","require":"./pbkdf2.js"},"./scrypt":{"import":"./esm/scrypt.js","require":"./scrypt.js"},"./sha256":{"import":"./esm/sha256.js","require":"./sha256.js"},"./sha512":{"import":"./esm/sha512.js","require":"./sha512.js"},"./_assert":{"import":"./esm/_assert.js","require":"./_assert.js"},"./blake2b":{"import":"./esm/blake2b.js","require":"./blake2b.js"},"./blake2s":{"import":"./esm/blake2s.js","require":"./blake2s.js"},"./ripemd160":{"import":"./esm/ripemd160.js","require":"./ripemd160.js"},"./sha3-addons":{"import":"./esm/sha3-addons.js","require":"./sha3-addons.js"}},"funding":"https://paulmillr.com/funding/","gitHead":"4a16f7cf966e03a6fce237e43c87d0dd516d30bc","scripts":{"lint":"prettier --check 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'","test":"node test/index.js","bench":"node benchmark/noble.js","build":"npm run build:clean; tsc && tsc -p tsconfig.esm.json","format":"prettier --write 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'","test:big":"node test/slow-big.test.js","test:dos":"node test/slow-dos.test.js","build:clean":"rm -f *.{js,d.ts,js.map,d.ts.map} esm/*.{js,js.map,d.ts.map}","bench:compare":"node benchmark/hashes.js; node benchmark/kdf.js","bench:install":"cd benchmark; npm install; npm install .. --install-links","test:coverage":"c8 node test/index.js"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"repository":{"url":"git+https://github.com/paulmillr/noble-hashes.git","type":"git"},"_npmVersion":"11.0.0","description":"Audited & minimal 0-dependency JS implementation of SHA, RIPEMD, BLAKE, HMAC, HKDF, PBKDF & Scrypt","directories":{},"sideEffects":false,"_nodeVersion":"20.18.1","_hasShrinkwrap":false,"devDependencies":{"c8":"10.1.2","prettier":"3.3.2","fast-check":"3.0.0","typescript":"5.5.2","micro-bmark":"0.3.1","micro-should":"0.4.0","@paulmillr/jsbt":"0.2.1"},"_npmOperationalInternal":{"tmp":"tmp/hashes_1.7.0_1735865496854_0.670757327918468","host":"s3://npm-registry-packages-npm-production"},"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 tests and fuzzing ensure correctness\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 & KangarooTwelve\n- 🪶 47KB for everything, 5KB (2.5KB gzipped) for single-hash build\n\nTake a glance at [GitHub Discussions](https://github.com/paulmillr/noble-hashes/discussions) for questions and support.\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  4kb [secp256k1](https://github.com/paulmillr/noble-secp256k1) /\n  [ed25519](https://github.com/paulmillr/noble-ed25519)\n- [Check out 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\n> `deno doc jsr:@noble/hashes`  # command-line documentation\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 } from '@noble/hashes/sha2'; // ECMAScript modules (ESM) and Common.js\n// u8a is accepted\nconsole.log(sha256(new Uint8Array([1, 2, 3]))); // Uint8Array(32) [3, 144, 88, 198, 242...]\n// strings are also accepted and auto-encoded into u8a\nconsole.log(sha256('abc')); // == sha256(new TextEncoder().encode('abc'))\n```\n\n- [Implementations](#implementations)\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, K12, M14, TurboSHAKE](#sha3-addons-cshake-kmac-k12-m14-turboshake)\n  - [ripemd160](#ripemd160) | [blake, blake2b, blake2s, blake3](#blake-blake2b-blake2s-blake3) | [sha1: legacy hash](#sha1-legacy-hash)\n  - MACs: [hmac](#hmac) (also sha3-addons [kmac](#sha3-addons-cshake-kmac-k12-m14-turboshake), blake3 [key mode](#blake2b-blake2s-blake3))\n  - KDFs: [hkdf](#hkdf) | [pbkdf2](#pbkdf2) | [scrypt](#scrypt) | [argon2](#argon2)\n  - [utils](#utils)\n  - [All available imports](#all-available-imports)\n- [Security](#security) | [Speed](#speed) | [Contributing & testing](#contributing--testing) | [License](#license)\n\n\n### Implementations\n\n```ts\n// function hash(message: Uint8Array | string): Uint8Array;\nhash(new Uint8Array([1, 3]));\nhash('string'); // == hash(new TextEncoder().encode('string'));\n// prettier-ignore\nhash.create().update(new Uint8Array([1, 3])).digest();\n```\n\nHash functions:\n\n- receive & return `Uint8Array`\n- may receive `string` **(not hex)**, which is automatically utf8-encoded to `Uint8Array`\n- support little-endian architecture; also experimentally big-endian\n- can hash up to 4GB per chunk, with any amount of chunks\n- can be constructed via `hash.create()` method\n    - the result is `Hash` subclass instance, which has `update()` and `digest()` methods\n    - `digest()` finalizes the hash and makes it no longer usable\n- some of them can receive `options`:\n    - second argument to hash function: `blake3('abc', { key: 'd', dkLen: 32 })`\n    - first argument to class initializer: `blake3.create({ context: 'e', dkLen: 32 })`\n\n#### sha2: sha256, sha384, sha512 and others\n\n```typescript\nimport { sha256, sha384, sha512, sha224, sha512_256, sha512_384 } from '@noble/hashes/sha2';\n// also available as aliases:\n// import ... from '@noble/hashes/sha256'\n// import ... from '@noble/hashes/sha512'\n\n// Variant A:\nconst h1a = sha256('abc');\n\n// Variant B:\nconst h1b = sha256\n  .create()\n  .update(Uint8Array.from([1, 2, 3]))\n  .digest();\n\nfor (let hash of [sha384, sha512, sha224, sha512_256, sha512_384]) {\n  const res1 = hash('abc');\n  const res2 = hash\n    .create()\n    .update('def')\n    .update(Uint8Array.from([1, 2, 3]))\n    .digest();\n}\n```\n\nSee [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\n// prettier-ignore\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';\nconst h5a = sha3_256('abc');\nconst h5b = sha3_256\n  .create()\n  .update(Uint8Array.from([1, 2, 3]))\n  .digest();\nconst h6a = keccak_256('abc');\nconst h7a = shake128('abc', { dkLen: 512 });\nconst h7b = shake256('abc', { dkLen: 512 });\n```\n\nSee [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, M14, TurboSHAKE\n\n```typescript\n// prettier-ignore\nimport {\n  cshake128, cshake256,\n  turboshake128, turboshake256,\n  kmac128, kmac256,\n  tuplehash256, parallelhash256,\n  k12, m14, keccakprg\n} from '@noble/hashes/sha3-addons';\nconst h7c = cshake128('abc', { personalization: 'def' });\nconst h7d = cshake256('abc', { personalization: 'def' });\nconst h7e = kmac128('key', 'message');\nconst h7f = kmac256('key', 'message');\nconst h7h = k12('abc');\nconst h7g = m14('abc');\nconst h7t1 = turboshake128('abc');\nconst h7t2 = turboshake256('def', { D: 0x05 });\nconst h7i = tuplehash256(['ab', 'c']); // tuplehash(['ab', 'c']) !== tuplehash(['a', 'bc']) !== tuplehash(['abc'])\n// Same as k12/blake3, but without reduced number of rounds. Doesn't speedup anything due lack of SIMD and threading,\n// added for compatibility.\nconst h7j = parallelhash256('abc', { blockLen: 8 });\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.feed('test');\nconst rand1b = p.fetch(1);\n```\n\n- Full [NIST SP 800-185](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf):\n  cSHAKE, KMAC, TupleHash, ParallelHash + XOF variants\n- [Reduced-round Keccak](https://datatracker.ietf.org/doc/draft-irtf-cfrg-kangarootwelve/):\n  - 🦘 K12 aka KangarooTwelve\n  - M14 aka MarsupilamiFourteen\n  - TurboSHAKE\n- [KeccakPRG](https://keccak.team/files/CSF-0.1.pdf): Pseudo-random generator based on Keccak\n\n#### ripemd160\n\n```typescript\nimport { ripemd160 } from '@noble/hashes/ripemd160';\n// function ripemd160(data: Uint8Array): Uint8Array;\nconst hash8 = ripemd160('abc');\nconst hash9 = ripemd160\n  .create()\n  .update(Uint8Array.from([1, 2, 3]))\n  .digest();\n```\n\nSee [RFC 2286](https://datatracker.ietf.org/doc/html/rfc2286),\n[Website](https://homes.esat.kuleuven.be/~bosselae/ripemd160.html)\n\n#### blake, blake2b, blake2s, blake3\n\n```typescript\nimport { blake224, blake256, blake384, blake512 } from '@noble/hashes/blake1';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { blake2s } from '@noble/hashes/blake2s';\nimport { blake3 } from '@noble/hashes/blake3';\n\nconst h_b1_224 = blake224('abc');\nconst h_b1_256 = blake256('abc');\nconst h_b1_384 = blake384('abc');\nconst h_b1_512 = blake512('abc');\n\nconst h10a = blake2s('abc');\nconst b2params = { key: new Uint8Array([1]), personalization: t, salt: t, dkLen: 32 };\nconst h10b = blake2s('abc', b2params);\nconst h10c = blake2s\n  .create(b2params)\n  .update(Uint8Array.from([1, 2, 3]))\n  .digest();\n\n// All params are optional\nconst h11 = blake3('abc', { dkLen: 256 });\nconst h11_mac = blake3('abc', { key: new Uint8Array(32) });\nconst h11_kdf = blake3('abc', { context: '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#### sha1: legacy hash\n\nSHA1 was cryptographically broken, however, it was not broken for cases like HMAC.\n\nSee [RFC4226 B.2](https://datatracker.ietf.org/doc/html/rfc4226#appendix-B.2).\n\nDon't use it for a new protocol.\n\n```typescript\nimport { sha1 } from '@noble/hashes/sha1';\nconst h12 = sha1('def');\n```\n\n#### hmac\n\n```typescript\nimport { hmac } from '@noble/hashes/hmac';\nimport { sha256 } from '@noble/hashes/sha2';\nconst mac1 = hmac(sha256, 'key', 'message');\nconst mac2 = hmac\n  .create(sha256, Uint8Array.from([1, 2, 3]))\n  .update(Uint8Array.from([4, 5, 6]))\n  .digest();\n```\n\nMatches [RFC 2104](https://datatracker.ietf.org/doc/html/rfc2104).\n\n#### hkdf\n\n```typescript\nimport { hkdf } from '@noble/hashes/hkdf';\nimport { sha256 } from '@noble/hashes/sha2';\nimport { randomBytes } from '@noble/hashes/utils';\nconst inputKey = randomBytes(32);\nconst salt = randomBytes(32);\nconst info = 'application-key';\nconst hk1 = hkdf(sha256, inputKey, salt, info, 32);\n\n// == same as\nimport * as hkdf from '@noble/hashes/hkdf';\nimport { sha256 } from '@noble/hashes/sha2';\nconst prk = hkdf.extract(sha256, inputKey, salt);\nconst hk2 = hkdf.expand(sha256, prk, info, dkLen);\n```\n\nMatches [RFC 5869](https://datatracker.ietf.org/doc/html/rfc5869).\n\n#### pbkdf2\n\n```typescript\nimport { pbkdf2, pbkdf2Async } from '@noble/hashes/pbkdf2';\nimport { sha256 } from '@noble/hashes/sha2';\nconst pbkey1 = pbkdf2(sha256, 'password', 'salt', { c: 32, dkLen: 32 });\nconst pbkey2 = await pbkdf2Async(sha256, 'password', 'salt', { c: 32, dkLen: 32 });\nconst pbkey3 = await pbkdf2Async(sha256, Uint8Array.from([1, 2, 3]), Uint8Array.from([4, 5, 6]), {\n  c: 32,\n  dkLen: 32,\n});\n```\n\nMatches [RFC 2898](https://datatracker.ietf.org/doc/html/rfc2898).\n\n#### scrypt\n\n```typescript\nimport { scrypt, scryptAsync } from '@noble/hashes/scrypt';\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. To understand them, see [the blog post](https://blog.filippo.io/the-scrypt-parameters/).\n  `r: 8, p: 1` are common. 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 M2 (mobile phones can be 1x-4x slower):\n\n| N pow  | Time  |\n|----|-------|\n| 16 | 0.17s |\n| 17 | 0.35s |\n| 18 | 0.7s  |\n| 19 | 1.4s  |\n| 20 | 2.9s  |\n| 21 | 5.6s  |\n| 22 | 11s   |\n| 23 | 26s   |\n| 24 | 56s   |\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\n#### argon2\n\n```ts\nimport { argon2d, argon2i, argon2id } from '@noble/hashes/argon2';\nconst result = 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#### utils\n\n```typescript\nimport { bytesToHex as toHex, randomBytes } from '@noble/hashes/utils';\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#### All available imports\n\n```js\nimport { sha256, sha384, sha512, sha224, sha512_256, sha512_384 } from '@noble/hashes/sha2';\n// prettier-ignore\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';\n// prettier-ignore\nimport {\n  cshake128, cshake256,\n  turboshake128, turboshake256,\n  kmac128, kmac256,\n  tuplehash256, parallelhash256,\n  k12, m14, keccakprg\n} from '@noble/hashes/sha3-addons';\nimport { ripemd160 } from '@noble/hashes/ripemd160';\nimport { blake3 } from '@noble/hashes/blake3';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { blake2s } from '@noble/hashes/blake2s';\nimport { hmac } from '@noble/hashes/hmac';\nimport { hkdf } from '@noble/hashes/hkdf';\nimport { pbkdf2, pbkdf2Async } from '@noble/hashes/pbkdf2';\nimport { scrypt, scryptAsync } from '@noble/hashes/scrypt';\n\nimport { sha1 } from '@noble/hashes/sha1'; // legacy\n\n// small utility method that converts bytes to hex\nimport { bytesToHex as toHex } from '@noble/hashes/utils';\nconsole.log(toHex(sha256('abc'))); // ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\n```\n\n## Security\n\nThe library has been independently audited:\n\n- at version 1.0.0, in Jan 2022, 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  - [Changes since audit](https://github.com/paulmillr/noble-hashes/compare/1.0.0..main).\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 has fuzzing by [Guido Vranken's cryptofuzz](https://github.com/guidovranken/cryptofuzz).\n\nIf you see anything unusual: investigate and report.\n\n### Constant-timeness\n\n_JIT-compiler_ and _Garbage Collector_ make \"constant time\" extremely hard to\nachieve [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. Nonetheless we're targetting algorithmic constant time.\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. Make sure to verify commit signatures.\n- **Releases** are transparent and built on GitHub CI. Make sure to verify [provenance](https://docs.npmjs.com/generating-provenance-statements) logs\n- **Rare releasing** is followed to ensure less re-audit need for end-users\n- **Dependencies** are minimized and locked-down:\n  - If your app has 500 dependencies, any dep could get hacked and you'll be downloading\n    malware with every install. We make sure to use as few dependencies as possible\n  - We prevent automatic dependency updates by locking-down version ranges. Every update is checked with `npm-diff`\n- **Dev Dependencies** are only used if you want to contribute to the repo. They are disabled for end-users:\n  - scure-base, scure-bip32, scure-bip39, micro-bmark and micro-should are developed by the same author and follow identical security practices\n  - prettier (linter), fast-check (property-based testing) and typescript are used for code quality, vector generation and ts compilation. The packages are big, which makes it hard to audit their source code thoroughly and fully\n\n### Randomness\n\nWe're deferring to built-in\n[crypto.getRandomValues](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues)\nwhich is considered cryptographically secure (CSPRNG).\n\nIn the past, browsers had bugs that made it weak: it may happen again.\nImplementing a userspace CSPRNG to get resilient to the weakness\nis even worse: there is no reliable userspace source of 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## Speed\n\n    npm run bench\n\nBenchmarks measured on Apple M2 with node v22.\n\n```\n32B\nsha256 x 1,377,410 ops/sec @ 726ns/op\nsha384 x 518,403 ops/sec @ 1μs/op\nsha512 x 518,941 ops/sec @ 1μs/op\nsha3_256 x 188,608 ops/sec @ 5μs/op\nsha3_512 x 190,114 ops/sec @ 5μs/op\nk12 x 324,254 ops/sec @ 3μs/op\nm14 x 286,204 ops/sec @ 3μs/op\nblake2b x 352,236 ops/sec @ 2μs/op\nblake2s x 586,510 ops/sec @ 1μs/op\nblake3 x 681,198 ops/sec @ 1μs/op\nripemd160 x 1,275,510 ops/sec @ 784ns/op\n\n1MB\nsha256 x 197 ops/sec @ 5ms/op\nsha384 x 86 ops/sec @ 11ms/op\nsha512 x 86 ops/sec @ 11ms/op\nsha3_256 x 25 ops/sec @ 39ms/op\nsha3_512 x 13 ops/sec @ 74ms/op\nk12 x 58 ops/sec @ 17ms/op\nm14 x 41 ops/sec @ 24ms/op\nblake2b x 50 ops/sec @ 19ms/op\nblake2s x 44 ops/sec @ 22ms/op\nblake3 x 57 ops/sec @ 17ms/op\nripemd160 x 193 ops/sec @ 5ms/op\n\n# MAC\nhmac(sha256) x 404,203 ops/sec @ 2μs/op\nhmac(sha512) x 137,136 ops/sec @ 7μs/op\nkmac256 x 58,799 ops/sec @ 17μs/op\nblake3(key) x 619,962 ops/sec @ 1μs/op\n\n# KDF\nhkdf(sha256) x 180,538 ops/sec @ 5μs/op\nblake3(context) x 336,247 ops/sec @ 2μs/op\npbkdf2(sha256, c: 2 ** 18) x 3 ops/sec @ 292ms/op\npbkdf2(sha512, c: 2 ** 18) x 1 ops/sec @ 920ms/op\nscrypt(n: 2 ** 18, r: 8, p: 1) x 1 ops/sec @ 605ms/op\nargon2id(t: 1, m: 256MB) x 0 ops/sec @ 4021ms/op\n```\n\nCompare to native node.js implementation that uses C bindings instead of pure-js code:\n\n```\nSHA256 32B node x 1,302,083 ops/sec @ 768ns/op\nSHA384 32B node x 975,609 ops/sec @ 1μs/op\nSHA512 32B node x 983,284 ops/sec @ 1μs/op\nSHA3-256 32B node x 910,746 ops/sec @ 1μs/op\n# keccak, k12, m14 are not implemented\nBLAKE2b 32B node x 967,117 ops/sec @ 1μs/op\nBLAKE2s 32B node x 1,055,966 ops/sec @ 947ns/op\n# BLAKE3 is not implemented\nRIPEMD160 32B node x 1,002,004 ops/sec @ 998ns/op\nHMAC-SHA256 32B node x 919,963 ops/sec @ 1μs/op\nHKDF-SHA256 32 node x 369,276 ops/sec @ 2μs/op\nPBKDF2-HMAC-SHA256 262144 node x 25 ops/sec @ 39ms/op\nPBKDF2-HMAC-SHA512 262144 node x 7 ops/sec @ 132ms/op\nScrypt r: 8, p: 1, n: 262144 node x 1 ops/sec @ 523ms/op\n```\n\nIt is possible to [make this library 4x+ faster](./benchmark/README.md) by\n_doing code generation of full loop unrolls_. We've decided against it. Reasons:\n\n- the library must be auditable, with minimum amount of code, and zero dependencies\n- most method invocations with the lib are going to be something like hashing 32b to 64kb of data\n- hashing big inputs is 10x faster with low-level languages, which means you should probably pick 'em instead\n\nThe current performance is good enough when compared to other projects; SHA256 takes only 900 nanoseconds to run.\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, which may need their deps first (`npm run bench:install`)\n* `cd build && npm install && npm run build:release` will build single file\n* There is **additional** 20-min DoS test `npm run test:dos` and 2-hour \"big\" multicore test `npm run test:big`.\nSee [our approach to testing](./test/README.md)\n\nCheck out [github.com/paulmillr/guidelines](https://github.com/paulmillr/guidelines)\nfor general coding practices and rules.\n\nSee [paulmillr.com/noble](https://paulmillr.com/noble/)\nfor useful resources, articles, documentation and demos\nrelated to the library.\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":1735865497115,"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_cnpm_publish_time":1735865497115,"dist-tags":{"latest":"2.4.0"}}