<s>
In	O
cryptography	O
,	O
a	O
padding	B-Application
oracle	I-Application
attack	I-Application
is	O
an	O
attack	O
which	O
uses	O
the	O
padding	B-Algorithm
validation	O
of	O
a	O
cryptographic	O
message	O
to	O
decrypt	O
the	O
ciphertext	O
.	O
</s>
<s>
The	O
attack	O
relies	O
on	O
having	O
a	O
"	O
padding	B-Application
oracle	I-Application
"	O
who	O
freely	O
responds	O
to	O
queries	O
about	O
whether	O
a	O
message	O
is	O
correctly	O
padded	O
or	O
not	O
.	O
</s>
<s>
Padding	B-Application
oracle	I-Application
attacks	I-Application
are	O
mostly	O
associated	O
with	O
CBC	O
mode	O
decryption	O
used	O
within	O
block	O
ciphers	O
.	O
</s>
<s>
Padding	B-Algorithm
modes	O
for	O
asymmetric	O
algorithms	O
such	O
as	O
OAEP	B-Algorithm
may	O
also	O
be	O
vulnerable	O
to	O
padding	B-Application
oracle	I-Application
attacks	I-Application
.	O
</s>
<s>
In	O
symmetric	O
cryptography	O
,	O
the	O
padding	B-Application
oracle	I-Application
attack	I-Application
can	O
be	O
applied	O
to	O
the	O
CBC	O
mode	O
of	O
operation	O
,	O
where	O
the	O
"	O
oracle	B-Application
"	O
(	O
usually	O
a	O
server	O
)	O
leaks	O
data	O
about	O
whether	O
the	O
padding	B-Algorithm
of	O
an	O
encrypted	O
message	O
is	O
correct	O
or	O
not	O
.	O
</s>
<s>
Such	O
data	O
can	O
allow	O
attackers	O
to	O
decrypt	O
(	O
and	O
sometimes	O
encrypt	O
)	O
messages	O
through	O
the	O
oracle	B-Application
using	O
the	O
oracle	B-Application
's	O
key	O
,	O
without	O
knowing	O
the	O
encryption	O
key	O
.	O
</s>
<s>
The	O
standard	O
implementation	O
of	O
CBC	O
decryption	O
in	O
block	O
ciphers	O
is	O
to	O
decrypt	O
all	O
ciphertext	O
blocks	O
,	O
validate	O
the	O
padding	B-Algorithm
,	O
remove	O
the	O
PKCS7	O
padding	B-Algorithm
,	O
and	O
return	O
the	O
message	O
's	O
plaintext	O
.	O
</s>
<s>
If	O
the	O
server	O
returns	O
an	O
"	O
invalid	O
padding	B-Algorithm
"	O
error	O
instead	O
of	O
a	O
generic	O
"	O
decryption	O
failed	O
"	O
error	O
,	O
the	O
attacker	O
can	O
use	O
the	O
server	O
as	O
a	O
padding	B-Application
oracle	I-Application
to	O
decrypt	O
(	O
and	O
sometimes	O
encrypt	O
)	O
messages	O
.	O
</s>
<s>
The	O
server	O
then	O
returns	O
whether	O
or	O
not	O
the	O
padding	B-Algorithm
of	O
the	O
last	O
decrypted	O
block	O
(	O
)	O
is	O
correct	O
(	O
a	O
valid	O
PKCS	O
#7	O
padding	B-Algorithm
)	O
.	O
</s>
<s>
If	O
the	O
padding	B-Algorithm
is	O
correct	O
,	O
the	O
attacker	O
now	O
knows	O
that	O
the	O
last	O
byte	O
of	O
is	O
,	O
the	O
last	O
two	O
bytes	O
are	O
0x02	O
,	O
the	O
last	O
three	O
bytes	O
are	O
0x03	O
,	O
…,	O
or	O
the	O
last	O
eight	O
bytes	O
are	O
0x08	O
.	O
</s>
<s>
(	O
Alternatively	O
,	O
the	O
attacker	O
can	O
flip	O
earlier	O
bytes	O
and	O
binary	O
search	O
for	O
the	O
position	O
to	O
identify	O
the	O
padding	B-Algorithm
.	O
</s>
<s>
If	O
the	O
padding	B-Algorithm
is	O
incorrect	O
,	O
the	O
attacker	O
can	O
change	O
the	O
last	O
byte	O
of	O
to	O
the	O
next	O
possible	O
value	O
.	O
</s>
<s>
At	O
most	O
,	O
the	O
attacker	O
will	O
need	O
to	O
make	O
256	O
attempts	O
to	O
find	O
the	O
last	O
byte	O
of	O
,	O
255	O
attempts	O
for	O
every	O
possible	O
byte	O
(	O
256	O
possible	O
,	O
minus	O
one	O
by	O
pigeonhole	O
principle	O
)	O
,	O
plus	O
one	O
additional	O
attempt	O
to	O
eliminate	O
an	O
ambiguous	O
padding	B-Algorithm
.	O
</s>
<s>
The	O
attacker	O
then	O
uses	O
the	O
same	O
approach	O
described	O
above	O
,	O
this	O
time	O
modifying	O
the	O
second-to-last	O
byte	O
until	O
the	O
padding	B-Algorithm
is	O
correct	O
(	O
0x02	O
,	O
0x02	O
)	O
.	O
</s>
<s>
If	O
a	O
block	O
consists	O
of	O
128	O
bits	O
(	O
AES	B-Algorithm
,	O
for	O
example	O
)	O
,	O
which	O
is	O
16	O
bytes	O
,	O
the	O
attacker	O
will	O
obtain	O
plaintext	O
in	O
no	O
more	O
than	O
256⋅16	O
=	O
4096	O
attempts	O
.	O
</s>
<s>
CBC-R	O
turns	O
a	O
decryption	O
oracle	B-Application
into	O
an	O
encryption	O
oracle	B-Application
,	O
and	O
is	O
primarily	O
demonstrated	O
against	O
padding	B-Application
oracles	I-Application
.	O
</s>
<s>
Using	O
padding	B-Application
oracle	I-Application
attack	I-Application
CBC-R	O
can	O
craft	O
an	O
initialization	O
vector	O
and	O
ciphertext	O
block	O
for	O
any	O
plaintext	O
:	O
</s>
<s>
To	O
generate	O
a	O
ciphertext	O
that	O
is	O
N	O
blocks	O
long	O
,	O
attacker	O
must	O
perform	O
N	O
numbers	O
of	O
padding	B-Application
oracle	I-Application
attacks	I-Application
.	O
</s>
<s>
In	O
each	O
step	O
,	O
padding	B-Application
oracle	I-Application
attack	I-Application
is	O
used	O
to	O
construct	O
the	O
IV	O
to	O
the	O
previous	O
chosen	O
ciphertext	O
.	O
</s>
<s>
The	O
CBC-R	O
attack	O
will	O
not	O
work	O
against	O
an	O
encryption	O
scheme	O
that	O
authenticates	O
ciphertext	O
(	O
using	O
a	O
message	B-Algorithm
authentication	I-Algorithm
code	I-Algorithm
or	O
similar	O
)	O
before	O
decrypting	O
.	O
</s>
<s>
It	O
was	O
also	O
applied	O
to	O
several	O
web	B-Application
frameworks	I-Application
,	O
including	O
JavaServer	B-Language
Faces	I-Language
,	O
Ruby	B-Application
on	I-Application
Rails	I-Application
and	O
ASP.NET	B-Application
as	O
well	O
as	O
other	O
software	O
,	O
such	O
as	O
the	O
Steam	B-Application
gaming	O
client	O
.	O
</s>
<s>
While	O
these	O
earlier	O
attacks	O
were	O
fixed	O
by	O
most	O
TLS	B-Protocol
implementors	O
following	O
its	O
public	O
announcement	O
,	O
a	O
new	O
variant	O
,	O
the	O
Lucky	B-Protocol
Thirteen	I-Protocol
attack	I-Protocol
,	O
published	O
in	O
2013	O
,	O
used	O
a	O
timing	O
side-channel	O
to	O
re-open	O
the	O
vulnerability	O
even	O
in	O
implementations	O
that	O
had	O
previously	O
been	O
fixed	O
.	O
</s>
<s>
,	O
the	O
most	O
active	O
area	O
of	O
development	O
for	O
attacks	O
upon	O
cryptographic	O
protocols	O
used	O
to	O
secure	O
Internet	O
traffic	O
are	O
downgrade	B-Protocol
attack	I-Protocol
,	O
such	O
as	O
Logjam	O
and	O
Export	O
RSA/FREAK	O
attacks	O
,	O
which	O
trick	O
clients	O
into	O
using	O
less-secure	O
cryptographic	O
operations	O
provided	O
for	O
compatibility	O
with	O
legacy	O
clients	O
when	O
more	O
secure	O
ones	O
are	O
available	O
.	O
</s>
<s>
An	O
attack	O
called	O
POODLE	B-Protocol
(	O
late	O
2014	O
)	O
combines	O
both	O
a	O
downgrade	B-Protocol
attack	I-Protocol
(	O
to	O
SSL	O
3.0	O
)	O
with	O
a	O
padding	B-Application
oracle	I-Application
attack	I-Application
on	O
the	O
older	O
,	O
insecure	O
protocol	O
to	O
enable	O
compromise	O
of	O
the	O
transmitted	O
data	O
.	O
</s>
<s>
In	O
May	O
2016	O
it	O
has	O
been	O
revealed	O
in	O
that	O
the	O
fix	O
against	O
Lucky	O
Thirteen	O
in	O
OpenSSL	O
introduced	O
another	O
padding	B-Application
oracle	I-Application
.	O
</s>
