SHA-256's, HMAC's, and PBKDF2's own Pitfalls sections all name the same pair of algorithms as the real fix for a weakness none of those three pages can fix on their own — a password hash that's hard to parallelize on custom hardware, not just slow on one core — and all three leave both "not built on this site." bcrypt, designed by Niels Provos and David Mazières and presented in 1999, is the first of the two actually built here. It doesn't chain an existing hash the way PBKDF2 chains HMAC; it repurposes a block cipher's own key schedule as the slow part, so that every single guess has to rebuild roughly 4 kilobytes of internal state completely from scratch — not just repeat updating one small running accumulator the way PBKDF2's chained HMAC calls do.
Argon2, named right alongside bcrypt on all three of those pages, is still not built here — though its own internal hash function, BLAKE2b, now is, the same supporting-primitive role this site's own HMAC plays underneath PBKDF2. See Complexity below for exactly why Argon2 itself being unbuilt is a real, measured gap and not just unfinished business — bcrypt's 4 KB is fixed and small enough that dedicated hardware can still brute-force it in parallel, which is precisely the limit Argon2's own tunable, much larger memory parameter exists to close.
Pick a password and a cost factor, then hash. A fresh random 16-byte salt is drawn on every click —
real bcrypt never reuses one — and the full result, salt and cost included, comes back as one
self-describing string: $2a$<cost>$<22-character salt><31-character hash>.
Nothing about checking a password later needs a separately stored salt column; it's already embedded in
the string a real system would store.
Now check a password against a stored hash — the way a real login does. The field below starts filled with a hash this page already verified offline (see Reference implementation); hashing above also fills it with your own result, so you can feed that straight back in.
Same password, five cost factors, timed back to back — watch the elapsed time roughly double each step, because the cost factor is a power-of-two round count, not a plain multiplier the way PBKDF2's iteration count is.
bcrypt's core is a modified Blowfish key schedule, EksBlowfishSetup ("Expensive Key Schedule Blowfish"), run once per hash:
EksBlowfishSetup(password, salt, cost):
state <- InitState() // the standard Blowfish P-array/S-boxes, pi digits in hex
state <- ExpandKey(state, salt, password) // first pass: salt AND password both perturb state
repeat (2^cost) times:
state <- ExpandKey(state, 0, password) // password only
state <- ExpandKey(state, 0, salt) // salt only
return state
ExpandKey itself has two halves. First, the key bytes (password or salt, repeated
cyclically) are XORed into Blowfish's 18-word P-array. Then P and all four
256-word S-boxes — 1,042 words, about 4 KB, every one of them — are regenerated by
encrypting a running 64-bit value with the current, just-perturbed state and feeding the output
back in as the next P/S entries; when a salt is supplied, it's XORed into that
running value on every one of those internal encryptions too, which is what makes the derived state
depend on both inputs at once rather than one after the other. Each loop iteration touches every
byte of that 4 KB, which is the entire point: there's no small summary of the work done so far to carry
forward the way PBKDF2 only ever carries forward one 32-byte accumulator.
Once 2^cost rounds finish, the resulting state is used to encrypt a fixed 24-byte string,
"OrpheanBeholderScryDoubt", 64 times over in ECB mode. The first 23 of those 24 output bytes,
plus the cost and the salt, are encoded with bcrypt's own base64 variant (same 6-bit grouping as standard
base64, a different 64-character alphabet, and no padding characters) into the familiar
$2a$10$N9qo8uLOickgx2ZMRZo... shape: a dollar-prefixed version tag, a two-digit cost, 22
characters of salt, 31 characters of hash.
Two real quirks, inherited from the original C implementation rather than anything in the design above: the password is treated as a null-terminated C string, so a trailing zero byte is silently included as part of the key material every implementation must agree to add; and anything past the first 72 bytes of the password is silently ignored. Both are implemented here to match real bcrypt exactly — see Pitfalls for why the second one is a genuine footgun, not a historical curiosity.
Blowfish's own round function and Feistel structure, unchanged from the cipher's 1993 publication —
ORIG_P/ORIG_S are the hexadecimal digits of π, exactly as Bruce Schneier's
original specification defines them:
var ORIG_P = [ /* 18 words, hex digits of π — Blowfish's own fixed starting P-array */
0x243f6a88, 0x85a308d3, 0x13198a2e, /* … */ 0x9216d5d9, 0x8979fb1b
];
var ORIG_S = [ /* 4 S-boxes x 256 words each, same source — 1,024 words, ~4 KB */
[0xd1310ba6, 0x98dfb5ac, /* … */ 0x6e85076a], /* … three more boxes … */
];
function F(state, x) { // Blowfish's own round function
var a = (x >>> 24) & 0xff, b = (x >>> 16) & 0xff, c = (x >>> 8) & 0xff, d = x & 0xff;
return (((state.S[0][a] + state.S[1][b]) | 0) ^ state.S[2][c]) + state.S[3][d] | 0;
}
function encryptBlock(state, L, R) { // one 64-bit ECB block, 16 Feistel rounds
for (var i = 0; i < 16; i++) {
L = (L ^ state.P[i]) >>> 0;
R = (R ^ F(state, L)) >>> 0;
var t = L; L = R; R = t;
}
var t2 = L; L = R; R = t2; // undo the final swap
R = (R ^ state.P[16]) >>> 0;
L = (L ^ state.P[17]) >>> 0;
return [L, R];
}
The expensive key-schedule machinery, built directly on top of encryptBlock above:
function expandKey(state, keyBytes) { // XOR key bytes cyclically into P[0..17]
var keylen = keyBytes.length, kbit = 0;
for (var n = 0; n < 18; n++) {
var word = 0;
for (var i = 0; i < 4; i++) { word = ((word << 8) | keyBytes[kbit % keylen]) >>> 0; kbit++; }
state.P[n] = (state.P[n] ^ word) >>> 0;
}
}
function expandState(state, dataBytes) { // re-derive P and all 4 S-boxes, salt (or nothing) mixed in
var L = 0, R = 0, dlen = dataBytes.length, dbit = 0;
function nextWord() {
if (dlen === 0) return 0;
var word = 0;
for (var i = 0; i < 4; i++) { word = ((word << 8) | dataBytes[dbit % dlen]) >>> 0; dbit++; }
return word;
}
for (var i = 0; i < 18; i += 2) {
L = (L ^ nextWord()) >>> 0; R = (R ^ nextWord()) >>> 0;
var pair = encryptBlock(state, L, R); L = pair[0]; R = pair[1];
state.P[i] = L; state.P[i + 1] = R;
}
for (var box = 0; box < 4; box++) {
for (var j = 0; j < 256; j += 2) {
L = (L ^ nextWord()) >>> 0; R = (R ^ nextWord()) >>> 0;
var pair2 = encryptBlock(state, L, R); L = pair2[0]; R = pair2[1];
state.S[box][j] = L; state.S[box][j + 1] = R;
}
}
}
function eksBlowfishSetup(passwordBytes, saltBytes, cost) {
var state = { P: ORIG_P.slice(), S: [ORIG_S[0].slice(), ORIG_S[1].slice(), ORIG_S[2].slice(), ORIG_S[3].slice()] };
expandKey(state, passwordBytes);
expandState(state, saltBytes);
for (var r = 0, rounds = 1 << cost; r < rounds; r++) {
expandKey(state, passwordBytes); expandState(state, new Uint8Array(0));
expandKey(state, saltBytes); expandState(state, new Uint8Array(0));
}
return state;
}
// bcryptHash(password, salt16, cost): truncates to 72 bytes, appends the trailing NUL, runs
// eksBlowfishSetup, encrypts "OrpheanBeholderScryDoubt" 64 times, and base64-encodes the result —
// the exact code this page's own demos call, omitted here only because it's a short, mechanical
// composition of everything already shown above.
Verified two ways before any of it reached the page above. First, against the single official
Blowfish test vector most implementations cite (all-zero 64-bit key, all-zero plaintext block →
ciphertext 4ef99745 6198dd78) — confirms the base cipher and key schedule independent of
bcrypt's own modifications. Second, against Python's bcrypt library (a wrapper around the
same reference algorithm production systems use) across 35 random password/cost/salt combinations —
password lengths from 0 to 120 bytes, costs 4 through 12, random salts — 0 mismatches. Unlike SHA-256's, HMAC's, and PBKDF2's own demos, there's no live cross-check running on this page:
bcrypt was never added to the Web Crypto API, so no browser-native implementation exists to compare
against on every click the way those three pages do. The verification above happened once, offline,
not continuously here.
Anything past the first 72 bytes of a password is silently ignored. Not an
implementation bug — the P-array's 18 words only ever absorb the first 72 bytes of cyclic
key material before ExpandKey moves on, so bytes beyond that position change nothing about
the result at all. A password manager or pass-phrase generator that produces something longer than 72
bytes (a real possibility — a handful of generated pass-phrases or a pasted multi-line secret can exceed
it) silently collapses onto whatever its first 72 bytes happen to be, with no error and no warning from
bcrypt itself. Real systems that need more headroom pre-hash the password with something fixed-length
first (SHA-256, say) and bcrypt that instead — trading one pitfall for the much smaller one of
picking a pre-hash that itself has no known weaknesses.
The null terminator is part of the key material, not a detail that can be dropped. Every bcrypt-compatible implementation must treat the password as a C string and include its trailing zero byte in the cyclic key schedule above — leave it out and every single hash comes out different from every other implementation's, with no error to flag the mismatch. This page includes it for exactly that reason: dropping it would make this implementation internally consistent but incompatible with every real one.
"bcrypt" names a family of close-but-not-identical implementations, not one interoperable
spec the way SHA-256 is. The version tag at the front of the hash string — 2a here
— has a real history of revisions (2x, then 2y, then 2b) tracking
bugs in how different C implementations handled 8-bit characters and very long passwords over the years.
This page implements the modern, maximally compatible behavior; a hash produced by an older or
differently-configured library in the wild is not guaranteed to match it byte-for-byte even for the
identical password, salt, and cost.
The 4 KB of state is fixed size, not a tunable memory cost. Raising cost
above makes an attacker redo that same 4 KB more times, but never makes any single redo larger. Custom
hardware with roughly 4 KB of fast memory per parallel lane — well within reach of a purpose-built ASIC
or FPGA — still parallelizes bcrypt cracking far more cheaply than it could against a true
memory-hardness design with a large, independently tunable memory parameter. See Complexity for the honest comparison; this is the real reason Argon2 exists and
the real reason it's still an open gap on this site.
Comparing the computed hash against the stored one needs a constant-time compare in a real
system — the identical lesson HMAC's own Pitfalls section
already makes about tag verification, for the identical reason: a naive byte-by-byte ===
that returns on the first mismatching byte leaks, through timing, how many leading bytes matched. The
Verify demo above uses a plain string compare for clarity, not as a model to copy into a real login
check.
Time: each round of EksBlowfishSetup calls expandState
twice, and each expandState call performs 9 + 512 = 521 encryptBlock calls (9
pairs to regenerate the 18-word P-array, 512 pairs to regenerate the four 256-word
S-boxes) — 1,042 Blowfish-block encryptions per round, repeated 2^cost times.
Raising cost by one doubles the total work, exactly the doubling the timing demo above
measures live; this is bcrypt's entire tunable knob, the same role PBKDF2's iteration count plays, just
exponential in the parameter instead of linear. Space: a fixed 1,042 words — about 4
KB — per guess, regardless of cost: dramatically more than PBKDF2's single 32-byte running
accumulator, which is the real memory-hardness improvement bcrypt offers, but still small and fixed
rather than independently tunable. Security: rests on Blowfish's own unbroken-cipher
assumption (no feasible attack faster than brute-forcing the key is known, even decades after
publication) plus the cost parameter chosen at design time, same tunable-constant caveat PBKDF2's own Complexity section already makes about its iteration
count. Argon2's own memory parameter can be pushed into the hundreds of megabytes or beyond,
independently of its time cost — a scale no fixed ~4 KB footprint can match no matter how high
cost is set, which is the precise, measured sense in which bcrypt's memory-hardness is real
but limited, and Argon2's is the stronger, still-unbuilt alternative.