// import * from '@noble/hashes'; // Error: use sub-imports, to ensure small app sizeimport { sha256 } from '@noble/hashes/sha2.js';const hash = sha256(Uint8Array.from([0xca, 0xfe, 0x01, 0x23]));
N, r, p are work factors. It is common to only adjust N, while keeping r: 8, p: 1.
See the blog post.
JS doesn't support parallelization, making increasing p meaningless.
dkLen is the length of output bytes e.g. 32 or 64
onProgress can be used with async version of the function to report progress to a user.
maxmem prevents DoS and defaults to 1GiB + 2KiB (2**30 + 2**11), enough for N: 2**20, r: 8, p: 1. It can be adjusted using formula: 128 * r * (N + p + 1)
On Apple M4, N: 2**16 takes 0.1s and 64MB RAM; each increment of N doubles both,
up to N: 2**24 at 27s and 16GB. Mobile phones can be 1x-4x slower.
[!NOTE]
We support N larger than 2**20 where available, however,
not all JS engines support >= 2GB ArrayBuffer-s.
When using such N, you'll need to manually adjust maxmem, using formula above.
Other JS implementations don't support large N-s.
argon2
import { argon2d, argon2i, argon2id } from '@noble/hashes/argon2.js';// Defaults to t=3, m=1GiB (specified in KiB), p=1, and a 1GiB maxmem limit.const arg1 = argon2id('password', 'saltsalt');
[!WARNING]
Argon2 can't be fast in JS, because there is no fast Uint64Array.
It is suggested to use Scrypt instead.
Being 5x slower than native code means brute-forcing attackers have bigger advantage.
Experimental KDF for deriving application-specific child keys from a username + password pair,
built on scrypt, pbkdf2 and hkdf with fixed work factors.
Non-standard: prefer scrypt or argon2 for new designs.
webcrypto: friendly wrapper
import { sha256, sha384, sha512, hmac, hkdf, pbkdf2 } from '@noble/hashes/webcrypto.js';import { randomBytes } from '@noble/hashes/utils.js';const whash = await sha256(Uint8Array.from([0xca, 0xfe, 0x01, 0x23]));const key = new Uint8Array(32).fill(1);const msg = new Uint8Array(32).fill(2);const wmac = await hmac(sha256, key, msg);const inputKey = randomBytes(
A thin wrapper over built-in crypto.subtle, mirroring the noble-hashes API and validating
inputs, in just 30+ lines of code. Webcrypto methods are always async.
utils
import { bytesToHex as toHex, randomBytes } from '@noble/hashes/utils.js';console.log(toHex(randomBytes(32)));
bytesToHex will convert Uint8Array to a hex string
randomBytes(bytes) will produce cryptographically secure random Uint8Array of length bytes
We've started regular AI-assisted self-audits in Apr 2026.
It is tested against official (ACVP / KAT) vectors, cross-library chained hashing,
sliding-window length sweeps and property-based tests (fast-check),
and is being fuzzed in CI.
If you see anything unusual: investigate and report.
Constant-timeness
We're targetting algorithmic constant time. JIT-compiler and Garbage Collector make "constant time"
extremely hard to achieve timing attack resistance
in a scripting language. Which means any other JS library can't have
constant-timeness. Even statically typed Rust, a language without GC,
makes it harder to achieve constant-time
for some cases. If your goal is absolute security, don't use any JS lib — including bindings to native ones.
Use low-level libraries & languages.
Memory dumping
The library shares state buffers between hash function calls. Library-owned working buffers are
zeroed after use, including mutable UTF-8 copies created from password-KDF string inputs.
However, if an attacker can read application memory, you are doomed in any case:
JS strings are immutable and can't be overwritten with zeros — e.g. a password passed
to scrypt(password, salt) as a string stays in memory
Inputs & outputs are re-used across the application and stay in file buffers / memory anyway
await anything() writes all internal variables (including numbers) to memory, with no
guarantee of when they get overwritten — plenty of time for an attacker to read them
Supply chain security
Commits are signed with PGP keys to prevent forgery. Be sure to verify the commit signatures
Releases are made transparently through token-less GitHub CI and Trusted Publishing. Be sure to verify the provenance logs for authenticity.
Rare releasing is practiced to minimize the need for re-audits by end-users.
Dependencies are minimized, strictly pinned, and changes are checked with npm-diff.
Dev dependencies are excluded from end-user installs; they’re only used for development and build steps.
For this package, there are 0 dependencies; and a few dev dependencies:
jsbt contains helpers for building, benchmarking & testing secure JS apps. It is developed by the same author
prettier, fast-check and typescript are used for code quality / test generation / ts compilation
Randomness
We rely on the built-in
crypto.getRandomValues,
which is considered a cryptographically secure PRNG.
Browsers 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.
Quantum computers
Cryptographically relevant quantum computer, if built, will allow to
utilize Grover's algorithm to break hashes in 2^n/2 operations, instead of 2^n.
This means SHA256 should be replaced with SHA512, SHA3-256 with SHA3-512, SHAKE128 with SHAKE256 etc.
Australian ASD prohibits SHA256 and similar hashes after 2030.
Upgrading
Supported node.js versions:
v2: v20.19+ (ESM-only)
v1: v14.21+ (ESM & CJS)
v2.0 changelog:
The package is now ESM-only. ESM can finally be loaded from common.js on node v20.19+
.js extension must be used for all modules
Old: @noble/hashes/sha3
New: @noble/hashes/sha3.js
This simplifies working in browsers natively without transpilers
Only allow Uint8Array as hash inputs, prohibit string
Strict validation checks improve security
To replicate previous behavior, use utils.utf8ToBytes
Rename / remove some modules for consistency. Previously, sha384 resided in sha512, which was weird
sha256, sha512 => sha2.js (consistent with sha3.js)
blake2b, blake2s => blake2.js (consistent with blake3.js, blake1.js)
ripemd160, sha1, md5 => legacy.js (all low-security hashes are there)
_assert => utils.js
crypto internal module got removed: use built-in WebCrypto instead
Improve typescript types & option autocomplete
Bump compilation target from es2020 to es2022
Contributing & testing
npm install && npm run build && npm test will build the code and run tests.
There are additional slow suites: timing-based DoS tests npm run test:dos,
multi-hour large-input tests npm run test:slow, ACVP LDT vectors npm run test:acvp,
and memory-intensive KDF tests npm run test:ultra. The 9–17GiB scrypt cases require an
explicitly provisioned machine and run separately with npm run test:ultra:scrypt.
See paulmillr.com/noble for useful resources, articles, documentation and demos related to the library.
Speed
npm run benchmark
Benchmarks measured on Apple M4.
The library could be 3x faster by utilizing loop unrolling. It isn't used because
unrolling a) would increase bundle size b) make lib un-readable c) current perf is "fast enough"
for most use-cases.
If you need truly exemplar performance, switch to awasm-noble,
which does unrolling in an auditable way and allows to achieve 10GB/s BLAKE3.
# 32Bsha256 438 nssha512 1219 nssha3_256 1853 nssha3_512 1864 nskt128 1380 nskt256 1370 nsturboshake128 1191 nsblake256 1335 nsblake2b 2186 nsblake2s 1055 nsblake3 981 nsripemd160 563 nsmd5 449 nssha1 507 nshmac(sha256) 1955 nshmac(sha512) 5126 nskmac256 6653 nsblake3(key) 1120 ns# 1MBsha256 x 297 mib/secsha512 x 130 mib/secsha3_256 x 78.1 mib/secsha3_512 x 41.9 mib/seckt128 x 184 mib/seckt256 x 147 mib/secturboshake128 x 186 mib/secblake256 x 56.7 mib/secblake2b x 66.2 mib/secblake2s x 62.9 mib/secblake3 x 90 mib/secripemd160 x 179 mib/secmd5 x 275 mib/secsha1 x 417 mib/sechmac(sha256) x 290 mib/sechmac(sha512) x 129 mib/seckmac256 x 78.4 mib/sec