<s>
bcrypt	B-Algorithm
is	O
a	O
password-hashing	B-Algorithm
function	I-Algorithm
designed	O
by	O
Niels	O
Provos	O
and	O
David	O
Mazières	O
,	O
based	O
on	O
the	O
Blowfish	B-Algorithm
cipher	I-Algorithm
and	O
presented	O
at	O
USENIX	B-Operating_System
in	O
1999	O
.	O
</s>
<s>
Besides	O
incorporating	O
a	O
salt	O
to	O
protect	O
against	O
rainbow	B-Algorithm
table	I-Algorithm
attacks	O
,	O
bcrypt	B-Algorithm
is	O
an	O
adaptive	O
function	O
:	O
over	O
time	O
,	O
the	O
iteration	O
count	O
can	O
be	O
increased	O
to	O
make	O
it	O
slower	O
,	O
so	O
it	O
remains	O
resistant	O
to	O
brute-force	B-Algorithm
search	I-Algorithm
attacks	O
even	O
with	O
increasing	O
computation	O
power	O
.	O
</s>
<s>
The	O
bcrypt	B-Algorithm
function	O
is	O
the	O
default	O
password	B-Algorithm
hash	I-Algorithm
algorithm	O
for	O
OpenBSD	B-Operating_System
and	O
was	O
the	O
default	O
for	O
some	O
Linux	B-Application
distributions	I-Application
such	O
as	O
SUSE	O
Linux	O
.	O
</s>
<s>
There	O
are	O
implementations	O
of	O
bcrypt	B-Algorithm
in	O
C	B-Language
,	O
C++	B-Language
,	O
C#	B-Application
,	O
Embarcadero	B-Language
Delphi	I-Language
,	O
Elixir	B-Language
,	O
Go	B-Application
,	O
Java	B-Language
,	O
JavaScript	B-Language
,	O
Perl	B-Language
,	O
PHP	B-Application
,	O
Python	B-Language
,	O
Ruby	B-Language
,	O
and	O
other	O
languages	O
.	O
</s>
<s>
Blowfish	B-Algorithm
is	O
notable	O
among	O
block	O
ciphers	O
for	O
its	O
expensive	O
key	O
setup	O
phase	O
.	O
</s>
<s>
It	O
proceeds	O
in	O
this	O
fashion	O
,	O
using	O
a	O
progressively	O
modified	O
state	O
to	O
hash	B-Error_Name
the	O
key	O
and	O
replace	O
bits	O
of	O
state	O
,	O
until	O
all	O
subkeys	O
have	O
been	O
set	O
.	O
</s>
<s>
They	O
developed	O
a	O
new	O
key	O
setup	O
algorithm	O
for	O
Blowfish	B-Algorithm
,	O
dubbing	O
the	O
resulting	O
cipher	O
"	O
Eksblowfish	O
"	O
(	O
"	O
expensive	O
key	O
schedule	O
Blowfish	B-Algorithm
"	O
)	O
.	O
</s>
<s>
The	O
key	O
setup	O
begins	O
with	O
a	O
modified	O
form	O
of	O
the	O
standard	O
Blowfish	B-Algorithm
key	I-Algorithm
setup	O
,	O
in	O
which	O
both	O
the	O
salt	O
and	O
password	O
are	O
used	O
to	O
set	O
all	O
subkeys	O
.	O
</s>
<s>
There	O
are	O
then	O
a	O
number	O
of	O
rounds	O
in	O
which	O
the	O
standard	O
Blowfish	B-Algorithm
keying	O
algorithm	O
is	O
applied	O
,	O
using	O
alternatively	O
the	O
salt	O
and	O
the	O
password	O
as	O
the	O
key	O
,	O
each	O
round	O
starting	O
with	O
the	O
subkey	O
state	O
from	O
the	O
previous	O
round	O
.	O
</s>
<s>
In	O
theory	O
,	O
this	O
is	O
no	O
stronger	O
than	O
the	O
standard	O
Blowfish	B-Algorithm
key	I-Algorithm
schedule	O
,	O
but	O
the	O
number	O
of	O
rekeying	O
rounds	O
is	O
configurable	O
;	O
this	O
process	O
can	O
therefore	O
be	O
made	O
arbitrarily	O
slow	O
,	O
which	O
helps	O
deter	O
brute-force	O
attacks	O
upon	O
the	O
hash	B-Error_Name
or	O
salt	O
.	O
</s>
<s>
The	O
input	O
to	O
the	O
bcrypt	B-Algorithm
function	O
is	O
the	O
password	O
string	O
(	O
up	O
to	O
72	O
bytes	O
)	O
,	O
a	O
numeric	O
cost	O
,	O
and	O
a	O
16-byte	O
(	O
128-bit	O
)	O
salt	O
value	O
.	O
</s>
<s>
The	O
bcrypt	B-Algorithm
function	O
uses	O
these	O
inputs	O
to	O
compute	O
a	O
24-byte	O
(	O
192-bit	O
)	O
hash	B-Error_Name
.	O
</s>
<s>
The	O
final	O
output	O
of	O
the	O
bcrypt	B-Algorithm
function	O
is	O
a	O
string	O
of	O
the	O
form	O
:	O
</s>
<s>
The	O
base-64	B-Protocol
encoding	O
in	O
bcrypt	B-Algorithm
uses	O
the	O
table	O
./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789	O
,	O
which	O
is	O
different	O
than	O
Base64	B-Protocol
encoding	I-Protocol
.	O
</s>
<s>
The	O
original	O
bcrypt	B-Algorithm
specification	O
defined	O
a	O
prefix	O
of	O
$2$	O
.	O
</s>
<s>
This	O
follows	O
the	O
Modular	O
Crypt	B-Algorithm
Format	O
format	O
used	O
when	O
storing	O
passwords	O
in	O
the	O
OpenBSD	B-Operating_System
password	O
file	O
:	O
</s>
<s>
In	O
June	O
2011	O
,	O
a	O
bug	O
was	O
discovered	O
in	O
crypt_blowfish	O
,	O
a	O
PHP	B-Application
implementation	O
of	O
bcrypt	B-Algorithm
.	O
</s>
<s>
They	O
suggested	O
that	O
system	O
administrators	O
update	O
their	O
existing	O
password	O
database	O
,	O
replacing	O
$2a$	O
with	O
$2x$	O
,	O
to	O
indicate	O
that	O
those	O
hashes	B-Error_Name
are	O
bad	O
(	O
and	O
need	O
to	O
use	O
the	O
old	O
broken	O
algorithm	O
)	O
.	O
</s>
<s>
They	O
also	O
suggested	O
the	O
idea	O
of	O
having	O
crypt_blowfish	O
emit	O
$2y$	O
for	O
hashes	B-Error_Name
generated	O
by	O
the	O
fixed	O
algorithm	O
.	O
</s>
<s>
Nobody	O
else	O
,	O
including	O
canonical	O
OpenBSD	B-Operating_System
,	O
adopted	O
the	O
idea	O
of	O
2x/2y	O
.	O
</s>
<s>
A	O
bug	O
was	O
discovered	O
in	O
the	O
OpenBSD	B-Operating_System
implementation	O
of	O
bcrypt	B-Algorithm
.	O
</s>
<s>
bcrypt	B-Algorithm
was	O
created	O
for	O
OpenBSD	B-Operating_System
.	O
</s>
<s>
The	O
bcrypt	B-Algorithm
function	O
below	O
encrypts	O
the	O
text	O
"	O
OrpheanBeholderScryDoubt	O
"	O
64	O
times	O
using	O
Blowfish	B-Algorithm
.	O
</s>
<s>
In	O
bcrypt	B-Algorithm
the	O
usual	O
Blowfish	B-Algorithm
key	I-Algorithm
setup	O
function	O
is	O
replaced	O
with	O
an	O
expensive	O
key	O
setup	O
(	O
EksBlowfishSetup	O
)	O
function	O
:	O
</s>
<s>
The	O
bcrypt	B-Algorithm
algorithm	O
depends	O
heavily	O
on	O
its	O
"	O
Eksblowfish	O
"	O
key	O
setup	O
algorithm	O
,	O
which	O
runs	O
as	O
follows	O
:	O
</s>
<s>
//Otherwise	O
the	O
key	O
setup	O
is	O
identical	O
to	O
Blowfish	B-Algorithm
.	O
</s>
<s>
InitialState	O
works	O
as	O
in	O
the	O
original	O
Blowfish	B-Algorithm
algorithm	O
,	O
populating	O
the	O
P-array	O
and	O
S-box	O
entries	O
with	O
the	O
fractional	O
part	O
of	O
in	O
hexadecimal	O
.	O
</s>
<s>
//Treat	O
the	O
128-bit	O
salt	O
as	O
two	O
64-bit	O
halves	O
(	O
the	O
Blowfish	B-Algorithm
block	O
size	O
)	O
.	O
</s>
<s>
Hence	O
,	O
ExpandKey(state, 0, key )	O
is	O
the	O
same	O
as	O
regular	O
Blowfish	B-Algorithm
key	I-Algorithm
schedule	O
since	O
all	O
XORs	O
with	O
the	O
all-zero	O
salt	O
value	O
are	O
ineffectual	O
.	O
</s>
<s>
Many	O
implementations	O
of	O
bcrypt	B-Algorithm
truncate	O
the	O
password	O
to	O
the	O
first	O
72	O
bytes	O
,	O
following	O
the	O
OpenBSD	B-Operating_System
implementation	O
.	O
</s>
<s>
The	O
original	O
specification	O
of	O
bcrypt	B-Algorithm
does	O
not	O
mandate	O
any	O
one	O
particular	O
method	O
for	O
mapping	O
text-based	O
passwords	O
from	O
userland	B-Operating_System
into	O
numeric	O
values	O
for	O
the	O
algorithm	O
.	O
</s>
<s>
Although	O
Provos	O
and	O
Mazières	O
do	O
not	O
state	O
the	O
reason	O
for	O
the	O
shorter	O
restriction	O
,	O
they	O
may	O
have	O
been	O
motivated	O
by	O
the	O
following	O
statement	O
from	O
Bruce	O
Schneier	O
's	O
original	O
specification	O
of	O
Blowfish	B-Algorithm
,	O
"	O
The	O
448	O
 [ bit ] 	O
limit	O
on	O
the	O
key	O
size	O
ensures	O
that	O
the	O
every	O
bit	O
of	O
every	O
subkey	O
depends	O
on	O
every	O
bit	O
of	O
the	O
key.	O
"	O
</s>
<s>
It	O
is	O
important	O
to	O
note	O
that	O
bcrypt	B-Algorithm
is	O
not	O
a	O
key	B-Algorithm
derivation	I-Algorithm
function	I-Algorithm
(	O
KDF	O
)	O
.	O
</s>
<s>
For	O
example	O
,	O
bcrypt	B-Algorithm
cannot	O
be	O
used	O
to	O
derive	O
a	O
512-bit	O
key	O
from	O
a	O
password	O
.	O
</s>
<s>
At	O
the	O
same	O
time	O
,	O
algorithms	O
like	O
pbkdf2	O
,	O
scrypt	B-Algorithm
,	O
and	O
argon2	B-Algorithm
are	O
password-based	B-Algorithm
key	I-Algorithm
derivation	I-Algorithm
functions	I-Algorithm
-	O
where	O
the	O
output	O
is	O
then	O
used	O
for	O
the	O
purpose	O
of	O
password	O
hashing	O
rather	O
than	O
just	O
key	O
derivation	O
.	O
</s>
<s>
In	O
this	O
scenario	O
,	O
bcrypt	B-Algorithm
is	O
stronger	O
than	O
pbkdf2	O
,	O
scrypt	B-Algorithm
,	O
and	O
argon2	B-Algorithm
.	O
</s>
<s>
PBKDF2	O
:	O
pbkdf2	O
is	O
weaker	O
than	O
bcrypt	B-Algorithm
.	O
</s>
<s>
The	O
commonly	O
used	O
SHA2	O
hashing	B-Error_Name
algorithm	I-Error_Name
is	O
not	O
memory-hard	O
.	O
</s>
<s>
scrypt	B-Algorithm
:	O
scrypt	B-Algorithm
is	O
weaker	O
than	O
bcrypt	B-Algorithm
for	O
memory	O
requirements	O
less	O
than	O
4	O
MB	O
.	O
</s>
<s>
scrypt	B-Algorithm
requires	O
approximately	O
1000	O
times	O
the	O
memory	O
of	O
bcrypt	B-Algorithm
to	O
achieve	O
a	O
comparable	O
level	O
of	O
defense	O
against	O
GPU	O
based	O
attacks	O
(	O
for	O
password	O
storage	O
)	O
.	O
</s>
<s>
argon2	B-Algorithm
:	O
Argon2	B-Algorithm
is	O
weaker	O
than	O
bcrypt	B-Algorithm
for	O
run	O
times	O
less	O
than	O
1	O
second	O
(	O
i.e.	O
</s>
<s>
Argon2	B-Algorithm
does	O
not	O
match	O
or	O
surpass	O
bcrypt	B-Algorithm
's	O
strength	O
until	O
>=	O
~	O
1000ms	O
runtimes	O
(	O
which	O
is	O
unsuitable	O
for	O
password	O
hashing	O
,	O
but	O
is	O
perfectly	O
acceptable	O
for	O
key-derivation	O
)	O
.	O
</s>
<s>
pufferfish2	O
is	O
an	O
evolution	O
of	O
bcrypt	B-Algorithm
that	O
uses	O
a	O
tunable	O
memory	O
footprint	O
(	O
like	O
scrypt	B-Algorithm
and	O
argon2	B-Algorithm
)	O
,	O
rather	O
than	O
the	O
fixed	O
4	O
KB	O
memory	O
footprint	O
of	O
bcrypt	B-Algorithm
.	O
</s>
<s>
Similar	O
to	O
scrypt	B-Algorithm
or	O
argon2	B-Algorithm
,	O
pufferfish2	O
gains	O
its	O
difficulty	O
by	O
using	O
more	O
memory	O
.	O
</s>
<s>
Unlike	O
scrypt	B-Algorithm
and	O
argon2	B-Algorithm
,	O
pufferfish2	O
only	O
operates	O
in	O
a	O
CPU	O
core	O
's	O
L2	O
cache	O
.	O
</s>
<s>
While	O
scrypt	B-Algorithm
and	O
argon2	B-Algorithm
gain	O
their	O
memory	O
hardness	O
by	O
randomly	O
accessing	O
lots	O
of	O
RAM	O
,	O
pufferfish2	O
limits	O
itself	O
to	O
just	O
the	O
dedicated	O
L2	O
cache	O
available	O
to	O
a	O
CPU	O
core	O
.	O
</s>
<s>
This	O
makes	O
it	O
even	O
harder	O
to	O
implement	O
in	O
custom	O
hardware	O
than	O
scrypt	B-Algorithm
and	O
argon2	B-Algorithm
.	O
</s>
<s>
bcrypt	B-Algorithm
has	O
a	O
maximum	O
password	O
length	O
of	O
72	O
bytes	O
.	O
</s>
<s>
The	O
bcrypt	B-Algorithm
algorithm	O
involves	O
repeatedly	O
encrypting	O
the	O
24-byte	O
text	O
:	O
</s>
<s>
The	O
canonical	O
OpenBSD	B-Operating_System
implementation	O
truncates	O
this	O
to	O
23	O
bytes	O
:	O
</s>
<s>
It	O
is	O
unclear	O
why	O
the	O
canonical	O
implementation	O
deletes	O
8-bits	O
from	O
the	O
resulting	O
password	B-Algorithm
hash	I-Algorithm
.	O
</s>
<s>
The	O
encoding	O
used	O
by	O
the	O
canonical	O
OpenBSD	B-Operating_System
implementation	O
uses	O
the	O
same	O
Base64	B-Protocol
alphabet	O
as	O
crypt	B-Algorithm
,	O
which	O
is	O
./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789	O
.	O
</s>
