<s>
In	O
cryptography	O
,	O
a	O
cipher	O
block	O
chaining	O
message	B-Algorithm
authentication	I-Algorithm
code	I-Algorithm
(	O
CBC-MAC	B-Algorithm
)	O
is	O
a	O
technique	O
for	O
constructing	O
a	O
message	B-Algorithm
authentication	I-Algorithm
code	I-Algorithm
(	O
MAC	O
)	O
from	O
a	O
block	O
cipher	O
.	O
</s>
<s>
To	O
calculate	O
the	O
CBC-MAC	B-Algorithm
of	O
message	O
,	O
one	O
encrypts	O
in	O
CBC	O
mode	O
with	O
zero	O
initialization	B-Algorithm
vector	I-Algorithm
and	O
keeps	O
the	O
last	O
block	O
.	O
</s>
<s>
The	O
following	O
figure	O
sketches	O
the	O
computation	O
of	O
the	O
CBC-MAC	B-Algorithm
of	O
a	O
message	O
comprising	O
blocks	O
using	O
a	O
secret	O
key	O
and	O
a	O
block	O
cipher	O
:	O
</s>
<s>
If	O
the	O
block	O
cipher	O
used	O
is	O
secure	O
(	O
meaning	O
that	O
it	O
is	O
a	O
pseudorandom	O
permutation	O
)	O
,	O
then	O
CBC-MAC	B-Algorithm
is	O
secure	O
for	O
fixed-length	O
messages	O
.	O
</s>
<s>
CBC-MAC	B-Algorithm
)	O
pairs	O
for	O
two	O
messages	O
and	O
can	O
generate	O
a	O
third	O
message	O
whose	O
CBC-MAC	B-Algorithm
will	O
also	O
be	O
.	O
</s>
<s>
There	O
are	O
three	O
main	O
ways	O
of	O
modifying	O
CBC-MAC	B-Algorithm
so	O
that	O
it	O
is	O
secure	O
for	O
variable	O
length	O
messages	O
:	O
1	O
)	O
Input-length	O
key	O
separation	O
;	O
2	O
)	O
Length-prepending	O
;	O
3	O
)	O
Encrypt	O
last	O
block	O
.	O
</s>
<s>
In	O
such	O
a	O
case	O
,	O
it	O
may	O
also	O
be	O
recommended	O
to	O
use	O
a	O
different	O
mode	O
of	O
operation	O
,	O
for	O
example	O
,	O
CMAC	B-Algorithm
or	O
HMAC	B-Algorithm
to	O
protect	O
the	O
integrity	O
of	O
variable-length	O
messages	O
.	O
</s>
<s>
One	O
solution	O
is	O
to	O
include	O
the	O
length	O
of	O
the	O
message	O
in	O
the	O
first	O
block	O
;	O
in	O
fact	O
CBC-MAC	B-Algorithm
has	O
been	O
proven	O
secure	O
as	O
long	O
as	O
no	O
two	O
messages	O
that	O
are	O
prefixes	O
of	O
each	O
other	O
are	O
ever	O
used	O
and	O
prepending	O
the	O
length	O
is	O
a	O
special	O
case	O
of	O
this	O
.	O
</s>
<s>
Encrypt-last-block	O
CBC-MAC	B-Algorithm
(	O
ECBC-MAC	O
)	O
is	O
defined	O
as	O
.	O
</s>
<s>
Compared	O
to	O
the	O
other	O
discussed	O
methods	O
of	O
extending	O
CBC-MAC	B-Algorithm
to	O
variable-length	O
messages	O
,	O
encrypt-last-block	O
has	O
the	O
advantage	O
of	O
not	O
needing	O
to	O
know	O
the	O
length	O
of	O
the	O
message	O
until	O
the	O
end	O
of	O
the	O
computation	O
.	O
</s>
<s>
We	O
present	O
attacks	O
which	O
are	O
possible	O
due	O
to	O
using	O
the	O
CBC-MAC	B-Algorithm
incorrectly	O
.	O
</s>
<s>
One	O
common	O
mistake	O
is	O
to	O
reuse	O
the	O
same	O
key	O
for	O
CBC	O
encryption	O
and	O
CBC-MAC	B-Algorithm
.	O
</s>
<s>
We	O
assume	O
,	O
for	O
the	O
purposes	O
of	O
this	O
example	O
and	O
without	O
loss	O
of	O
generality	O
,	O
that	O
the	O
initialization	B-Algorithm
vector	I-Algorithm
used	O
for	O
the	O
encryption	O
process	O
is	O
a	O
vector	O
of	O
zeroes	O
.	O
</s>
<s>
It	O
follows	O
that	O
Bob	O
will	O
now	O
compute	O
the	O
authentication	O
tag	O
using	O
CBC-MAC	B-Algorithm
over	O
all	O
the	O
values	O
of	O
plain	O
text	O
which	O
he	O
decoded	O
.	O
</s>
<s>
By	O
definition	O
,	O
a	O
Message	B-Algorithm
Authentication	I-Algorithm
Code	I-Algorithm
is	O
broken	O
if	O
we	O
can	O
find	O
a	O
different	O
message	O
(	O
a	O
sequence	O
of	O
plain-text	O
pairs	O
)	O
which	O
produces	O
the	O
same	O
tag	O
as	O
the	O
previous	O
message	O
,	O
,	O
with	O
.	O
</s>
<s>
However	O
,	O
due	O
to	O
the	O
MAC	O
's	O
usage	O
of	O
a	O
different	O
key	O
,	O
we	O
cannot	O
"	O
undo	O
"	O
the	O
decryption	O
process	O
in	O
the	O
forward	O
step	O
of	O
the	O
computation	O
of	O
the	O
message	B-Algorithm
authentication	I-Algorithm
code	I-Algorithm
so	O
as	O
to	O
produce	O
the	O
same	O
tag	O
;	O
each	O
modified	O
will	O
now	O
be	O
encrypted	O
by	O
in	O
the	O
CBC-MAC	B-Algorithm
process	O
to	O
some	O
value	O
.	O
</s>
<s>
This	O
example	O
also	O
shows	O
that	O
a	O
CBC-MAC	B-Algorithm
cannot	O
be	O
used	O
as	O
a	O
collision-resistant	O
one-way	O
function	O
:	O
given	O
a	O
key	O
it	O
is	O
trivial	O
to	O
create	O
a	O
different	O
message	O
which	O
"	O
hashes	B-Algorithm
"	O
to	O
the	O
same	O
tag	O
.	O
</s>
<s>
When	O
encrypting	O
data	O
using	O
a	O
block	O
cipher	O
in	O
cipher	O
block	O
chaining	O
(	O
or	O
another	O
)	O
mode	O
,	O
it	O
is	O
common	O
to	O
introduce	O
an	O
initialization	B-Algorithm
vector	I-Algorithm
to	O
the	O
first	O
stage	O
of	O
the	O
encryption	O
process	O
.	O
</s>
<s>
When	O
computing	O
a	O
message	B-Algorithm
authentication	I-Algorithm
code	I-Algorithm
,	O
such	O
as	O
by	O
CBC-MAC	B-Algorithm
,	O
the	O
use	O
of	O
an	O
initialization	B-Algorithm
vector	I-Algorithm
is	O
a	O
possible	O
attack	O
vector	O
.	O
</s>
<s>
In	O
the	O
operation	O
of	O
a	O
ciphertext	O
block	O
chaining	O
cipher	O
,	O
the	O
first	O
block	O
of	O
plain	O
text	O
is	O
mixed	O
with	O
the	O
initialization	B-Algorithm
vector	I-Algorithm
using	O
an	O
exclusive	O
OR	O
(	O
)	O
.	O
</s>
<s>
However	O
,	O
when	O
performing	O
encryption	O
and	O
decryption	O
,	O
we	O
are	O
required	O
to	O
send	O
the	O
initialization	B-Algorithm
vector	I-Algorithm
in	O
plain	O
text	O
-	O
typically	O
as	O
the	O
block	O
immediately	O
preceding	O
the	O
first	O
block	O
of	O
cipher	O
text	O
-	O
such	O
that	O
the	O
first	O
block	O
of	O
plain	O
text	O
can	O
be	O
decrypted	O
and	O
recovered	O
successfully	O
.	O
</s>
<s>
If	O
computing	O
a	O
MAC	O
,	O
we	O
will	O
also	O
need	O
to	O
transmit	O
the	O
initialization	B-Algorithm
vector	I-Algorithm
to	O
the	O
other	O
party	O
in	O
plain	O
text	O
so	O
that	O
they	O
can	O
verify	O
the	O
tag	O
on	O
the	O
message	O
matches	O
the	O
value	O
they	O
have	O
computed	O
.	O
</s>
<s>
If	O
we	O
allow	O
the	O
initialization	B-Algorithm
vector	I-Algorithm
to	O
be	O
selected	O
arbitrarily	O
,	O
it	O
follows	O
that	O
the	O
first	O
block	O
of	O
plain	O
text	O
can	O
potentially	O
be	O
modified	O
(	O
transmitting	O
a	O
different	O
message	O
)	O
while	O
producing	O
the	O
same	O
message	O
tag	O
.	O
</s>
<s>
In	O
particular	O
,	O
when	O
computing	O
the	O
message	O
tag	O
for	O
CBC-MAC	B-Algorithm
,	O
suppose	O
we	O
choose	O
an	O
initialization	B-Algorithm
vector	I-Algorithm
such	O
that	O
computation	O
of	O
the	O
MAC	O
begins	O
with	O
.	O
</s>
<s>
For	O
each	O
bit	O
modified	O
in	O
,	O
flip	O
the	O
corresponding	O
bit	O
in	O
the	O
initialization	B-Algorithm
vector	I-Algorithm
to	O
produce	O
the	O
initialization	B-Algorithm
vector	I-Algorithm
.	O
</s>
<s>
As	O
bits	O
in	O
both	O
the	O
plain	O
text	O
and	O
initialization	B-Algorithm
vector	I-Algorithm
have	O
been	O
flipped	O
in	O
the	O
same	O
places	O
,	O
the	O
modification	O
is	O
cancelled	O
in	O
this	O
first	O
stage	O
,	O
meaning	O
the	O
input	O
to	O
the	O
block	O
cipher	O
is	O
identical	O
to	O
that	O
for	O
.	O
</s>
<s>
If	O
the	O
freedom	O
to	O
select	O
an	O
initialization	B-Algorithm
vector	I-Algorithm
is	O
removed	O
and	O
all	O
implementations	O
of	O
CBC-MAC	B-Algorithm
fix	O
themselves	O
on	O
a	O
particular	O
initialization	B-Algorithm
vector	I-Algorithm
(	O
often	O
the	O
vector	O
of	O
zeroes	O
,	O
but	O
in	O
theory	O
,	O
it	O
could	O
be	O
anything	O
provided	O
all	O
implementations	O
agree	O
)	O
,	O
this	O
attack	O
cannot	O
proceed	O
.	O
</s>
<s>
This	O
is	O
not	O
a	O
forgery	O
,	O
rather	O
the	O
intended	O
use	O
of	O
CBC-MAC	B-Algorithm
.	O
</s>
<s>
FIPS	B-Algorithm
PUB	I-Algorithm
113	I-Algorithm
Computer	O
Data	O
Authentication	O
is	O
a	O
(	O
now	O
obsolete	O
)	O
U.S.	O
government	O
standard	O
that	O
specified	O
the	O
CBC-MAC	B-Algorithm
algorithm	O
using	O
DES	B-Algorithm
as	O
the	O
block	O
cipher	O
.	O
</s>
<s>
The	O
CBC-MAC	B-Algorithm
algorithm	O
is	O
equivalent	O
to	O
ISO/IEC	B-Algorithm
9797-1	I-Algorithm
MAC	O
Algorithm	O
1	O
.	O
</s>
