<s>
In	O
cryptography	O
,	O
the	O
Merkle	B-Algorithm
–	I-Algorithm
Damgård	I-Algorithm
construction	I-Algorithm
or	O
Merkle	B-Algorithm
–	I-Algorithm
Damgård	I-Algorithm
hash	B-Algorithm
function	I-Algorithm
is	O
a	O
method	O
of	O
building	O
collision-resistant	O
cryptographic	B-Algorithm
hash	I-Algorithm
functions	I-Algorithm
from	O
collision-resistant	O
one-way	B-Algorithm
compression	I-Algorithm
functions	I-Algorithm
.	O
</s>
<s>
This	O
construction	O
was	O
used	O
in	O
the	O
design	O
of	O
many	O
popular	O
hash	B-Algorithm
algorithms	O
such	O
as	O
MD5	B-Algorithm
,	O
SHA-1	B-Algorithm
and	O
SHA-2	B-Algorithm
.	O
</s>
<s>
The	O
Merkle	B-Algorithm
–	I-Algorithm
Damgård	I-Algorithm
construction	I-Algorithm
was	O
described	O
in	O
Ralph	O
Merkle	O
's	O
Ph.D.	O
thesis	O
in	O
1979	O
.	O
</s>
<s>
Ralph	O
Merkle	O
and	O
Ivan	O
Damgård	O
independently	O
proved	O
that	O
the	O
structure	O
is	O
sound	O
:	O
that	O
is	O
,	O
if	O
an	O
appropriate	O
padding	B-Algorithm
scheme	I-Algorithm
is	O
used	O
and	O
the	O
compression	O
function	O
is	O
collision-resistant	O
,	O
then	O
the	O
hash	B-Algorithm
function	I-Algorithm
will	O
also	O
be	O
collision-resistant	O
.	O
</s>
<s>
The	O
Merkle	B-Algorithm
–	I-Algorithm
Damgård	I-Algorithm
hash	B-Algorithm
function	I-Algorithm
first	O
applies	O
an	O
MD-compliant	O
padding	B-Algorithm
function	O
to	O
create	O
an	O
input	O
whose	O
size	O
is	O
a	O
multiple	O
of	O
a	O
fixed	O
number	O
(	O
e.g.	O
</s>
<s>
The	O
hash	B-Algorithm
function	I-Algorithm
then	O
breaks	O
the	O
result	O
into	O
blocks	O
of	O
fixed	O
size	O
,	O
and	O
processes	O
them	O
one	O
at	O
a	O
time	O
with	O
the	O
compression	O
function	O
,	O
each	O
time	O
combining	O
a	O
block	O
of	O
the	O
input	O
with	O
the	O
output	O
of	O
the	O
previous	O
round	O
.	O
</s>
<s>
In	O
order	O
to	O
make	O
the	O
construction	O
secure	O
,	O
Merkle	O
and	O
Damgård	O
proposed	O
that	O
messages	O
be	O
padded	O
with	O
a	O
padding	B-Algorithm
that	O
encodes	O
the	O
length	O
of	O
the	O
original	O
message	O
.	O
</s>
<s>
This	O
is	O
called	O
length	O
padding	B-Algorithm
or	O
Merkle	B-Algorithm
–	I-Algorithm
Damgård	I-Algorithm
strengthening	O
.	O
</s>
<s>
In	O
the	O
diagram	O
,	O
the	O
one-way	B-Algorithm
compression	I-Algorithm
function	I-Algorithm
is	O
denoted	O
by	O
f	O
,	O
and	O
transforms	O
two	O
fixed	O
length	O
inputs	O
to	O
an	O
output	O
of	O
the	O
same	O
size	O
as	O
one	O
of	O
the	O
inputs	O
.	O
</s>
<s>
The	O
algorithm	O
starts	O
with	O
an	O
initial	O
value	O
,	O
the	O
initialization	B-Algorithm
vector	I-Algorithm
(	O
IV	O
)	O
.	O
</s>
<s>
(	O
See	O
below	O
for	O
a	O
detailed	O
length	O
padding	B-Algorithm
example	O
.	O
)	O
</s>
<s>
To	O
harden	O
the	O
hash	B-Algorithm
further	O
,	O
the	O
last	O
result	O
is	O
then	O
sometimes	O
fed	O
through	O
a	O
finalisation	O
function	O
.	O
</s>
<s>
The	O
finalisation	O
function	O
can	O
have	O
several	O
purposes	O
such	O
as	O
compressing	O
a	O
bigger	O
internal	O
state	O
(	O
the	O
last	O
result	O
)	O
into	O
a	O
smaller	O
output	O
hash	B-Algorithm
size	O
or	O
to	O
guarantee	O
a	O
better	O
mixing	O
and	O
avalanche	O
effect	O
on	O
the	O
bits	O
in	O
the	O
hash	B-Algorithm
sum	O
.	O
</s>
<s>
(	O
Note	O
that	O
in	O
some	O
documents	O
a	O
different	O
terminology	O
is	O
used	O
:	O
the	O
act	O
of	O
length	O
padding	B-Algorithm
is	O
called	O
"	O
finalisation	O
"	O
.	O
)	O
</s>
<s>
The	O
popularity	O
of	O
this	O
construction	O
is	O
due	O
to	O
the	O
fact	O
,	O
proven	O
by	O
Merkle	O
and	O
Damgård	O
,	O
that	O
if	O
the	O
one-way	B-Algorithm
compression	I-Algorithm
function	I-Algorithm
f	O
is	O
collision	O
resistant	O
,	O
then	O
so	O
is	O
the	O
hash	B-Algorithm
function	I-Algorithm
constructed	O
using	O
it	O
.	O
</s>
<s>
Multicollisions	O
(	O
many	O
messages	O
with	O
the	O
same	O
hash	B-Algorithm
)	O
can	O
be	O
found	O
with	O
only	O
a	O
little	O
more	O
work	O
than	O
collisions	O
.	O
</s>
<s>
This	O
allows	O
for	O
constructing	O
highly	O
specific	O
colliding	O
documents	O
,	O
and	O
it	O
can	O
be	O
done	O
for	O
more	O
work	O
than	O
finding	O
a	O
collision	O
,	O
but	O
much	O
less	O
than	O
would	O
be	O
expected	O
to	O
do	O
this	O
for	O
a	O
random	B-Application
oracle	I-Application
.	O
</s>
<s>
Length	O
extension	O
:	O
Given	O
the	O
hash	B-Algorithm
of	O
an	O
unknown	O
input	O
X	O
,	O
it	O
is	O
easy	O
to	O
find	O
the	O
value	O
of	O
,	O
where	O
pad	O
is	O
the	O
padding	B-Algorithm
function	O
of	O
the	O
hash	B-Algorithm
.	O
</s>
<s>
That	O
is	O
,	O
it	O
is	O
possible	O
to	O
find	O
hashes	B-Algorithm
of	O
inputs	O
related	O
to	O
X	O
even	O
though	O
X	O
remains	O
unknown	O
.	O
</s>
<s>
Length	O
extension	O
attacks	O
were	O
actually	O
used	O
to	O
attack	O
a	O
number	O
of	O
commercial	O
web	O
message	O
authentication	O
schemes	O
such	O
as	O
one	O
used	O
by	O
Flickr	B-Algorithm
.	O
</s>
<s>
Due	O
to	O
several	O
structural	O
weaknesses	O
of	O
Merkle	B-Algorithm
–	I-Algorithm
Damgård	I-Algorithm
construction	I-Algorithm
,	O
especially	O
the	O
length	O
extension	O
problem	O
and	O
multicollision	O
attacks	O
,	O
Stefan	O
Lucks	O
proposed	O
the	O
use	O
of	O
the	O
wide-pipe	O
hash	B-Algorithm
instead	O
of	O
Merkle	B-Algorithm
–	I-Algorithm
Damgård	I-Algorithm
construction	I-Algorithm
.	O
</s>
<s>
The	O
wide-pipe	O
hash	B-Algorithm
is	O
very	O
similar	O
to	O
the	O
Merkle	B-Algorithm
–	I-Algorithm
Damgård	I-Algorithm
construction	I-Algorithm
but	O
has	O
a	O
larger	O
internal	O
state	O
size	O
,	O
meaning	O
that	O
the	O
bit-length	O
that	O
is	O
internally	O
used	O
is	O
larger	O
than	O
the	O
output	O
bit-length	O
.	O
</s>
<s>
If	O
a	O
hash	B-Algorithm
of	O
n	O
bits	O
is	O
desired	O
,	O
the	O
compression	O
function	O
f	O
takes	O
2n	O
bits	O
of	O
chaining	O
value	O
and	O
m	O
bits	O
of	O
the	O
message	O
and	O
compresses	O
this	O
to	O
an	O
output	O
of	O
2n	O
bits	O
.	O
</s>
<s>
Therefore	O
,	O
in	O
a	O
final	O
step	O
a	O
second	O
compression	O
function	O
compresses	O
the	O
last	O
internal	O
hash	B-Algorithm
value	O
(	O
2n	O
bit	O
)	O
to	O
the	O
final	O
hash	B-Algorithm
value	O
(	O
n	O
bit	O
)	O
.	O
</s>
<s>
SHA-512/224	B-Algorithm
and	O
SHA-512/256	B-Algorithm
take	O
this	O
form	O
since	O
they	O
are	O
derived	O
from	O
a	O
variant	O
of	O
SHA-512	B-Algorithm
.	O
</s>
<s>
SHA-384	B-Algorithm
and	O
SHA-224	B-Algorithm
are	O
similarly	O
derived	O
from	O
SHA-512	B-Algorithm
and	O
SHA-256	B-Algorithm
,	O
respectively	O
,	O
but	O
the	O
width	O
of	O
their	O
pipe	O
is	O
much	O
less	O
than	O
2n	O
.	O
</s>
<s>
It	O
has	O
been	O
demonstrated	O
by	O
Mridul	O
Nandi	O
and	O
Souradyuti	O
Paul	O
that	O
the	O
Widepipe	O
hash	B-Algorithm
function	I-Algorithm
can	O
be	O
made	O
approximately	O
twice	O
as	O
fast	O
if	O
the	O
widepipe	O
state	O
can	O
be	O
divided	O
in	O
half	O
in	O
the	O
following	O
manner	O
:	O
one	O
half	O
is	O
input	O
to	O
the	O
succeeding	O
compression	O
function	O
while	O
the	O
other	O
half	O
is	O
combined	O
with	O
the	O
output	O
of	O
that	O
compression	O
function	O
.	O
</s>
<s>
The	O
main	O
idea	O
of	O
the	O
hash	B-Algorithm
construction	O
is	O
to	O
forward	O
half	O
of	O
the	O
previous	O
chaining	O
value	O
forward	O
to	O
XOR	O
it	O
to	O
the	O
output	O
of	O
the	O
compression	O
function	O
.	O
</s>
<s>
As	O
mentioned	O
in	O
the	O
introduction	O
,	O
the	O
padding	B-Algorithm
scheme	I-Algorithm
used	O
in	O
the	O
Merkle	B-Algorithm
–	I-Algorithm
Damgård	I-Algorithm
construction	I-Algorithm
must	O
be	O
chosen	O
carefully	O
to	O
ensure	O
the	O
security	O
of	O
the	O
scheme	O
.	O
</s>
<s>
Mihir	O
Bellare	O
gives	O
sufficient	O
conditions	O
for	O
a	O
padding	B-Algorithm
scheme	I-Algorithm
to	O
possess	O
to	O
ensure	O
that	O
the	O
MD	O
construction	O
is	O
secure	O
:	O
it	O
suffices	O
that	O
the	O
scheme	O
be	O
"	O
MD-compliant	O
"	O
(	O
the	O
original	O
length-padding	O
scheme	O
used	O
by	O
Merkle	O
is	O
an	O
example	O
of	O
MD-compliant	O
padding	B-Algorithm
)	O
.	O
</s>
<s>
With	O
these	O
conditions	O
in	O
place	O
,	O
we	O
find	O
a	O
collision	O
in	O
the	O
MD	O
hash	B-Algorithm
function	I-Algorithm
exactly	O
when	O
we	O
find	O
a	O
collision	O
in	O
the	O
underlying	O
compression	O
function	O
.	O
</s>
<s>
Therefore	O
,	O
the	O
Merkle	B-Algorithm
–	I-Algorithm
Damgård	I-Algorithm
construction	I-Algorithm
is	O
provably	O
secure	O
when	O
the	O
underlying	O
compression	O
function	O
is	O
secure	O
.	O
</s>
<s>
For	O
example	O
,	O
suppose	O
the	O
message	O
to	O
be	O
hashed	O
is	O
"	O
HashInput	O
"	O
(	O
9	O
octet	O
string	O
,	O
0x48617368496e707574	O
in	O
ASCII	B-Protocol
)	O
and	O
the	O
block	O
size	O
of	O
the	O
compression	O
function	O
is	O
8	O
bytes	O
(	O
64	O
bits	O
)	O
.	O
</s>
<s>
We	O
get	O
two	O
blocks	O
(	O
the	O
padding	B-Algorithm
octets	O
shown	O
with	O
lightblue	O
background	O
color	O
)	O
:	O
</s>
<s>
This	O
implies	O
that	O
other	O
messages	O
having	O
the	O
same	O
content	O
but	O
ending	O
with	O
additional	O
zeros	O
at	O
the	O
end	O
will	O
result	O
in	O
the	O
same	O
hash	B-Algorithm
value	O
.	O
</s>
<s>
In	O
the	O
above	O
example	O
,	O
another	O
almost	O
identical	O
message	O
(	O
0x48617368496e7075	O
74	O
)	O
will	O
generate	O
the	O
same	O
hash	B-Algorithm
value	O
as	O
the	O
original	O
message	O
"	O
HashInput	O
"	O
above	O
.	O
</s>
<s>
To	O
prevent	O
this	O
situation	O
,	O
the	O
first	O
bit	O
of	O
the	O
first	O
padding	B-Algorithm
octet	O
is	O
changed	O
to	O
"	O
1	O
"	O
(	O
0x80	O
)	O
,	O
yielding	O
:	O
</s>
<s>
However	O
,	O
most	O
common	O
implementations	O
use	O
a	O
fixed	O
bit-size	O
(	O
generally	O
64	O
or	O
128	O
bits	O
in	O
modern	O
algorithms	O
)	O
at	O
a	O
fixed	O
position	O
at	O
the	O
end	O
of	O
the	O
last	O
block	O
for	O
inserting	O
the	O
message	O
length	O
value	O
(	O
see	O
SHA-1	B-Algorithm
pseudocode	O
)	O
.	O
</s>
