<s>
In	O
cryptography	O
,	O
format-preserving	B-Algorithm
encryption	I-Algorithm
(	O
FPE	O
)	O
,	O
refers	O
to	O
encrypting	O
in	O
such	O
a	O
way	O
that	O
the	O
output	O
(	O
the	O
ciphertext	O
)	O
is	O
in	O
the	O
same	O
format	O
as	O
the	O
input	O
(	O
the	O
plaintext	O
)	O
.	O
</s>
<s>
For	O
example	O
,	O
output	O
from	O
a	O
typical	O
block	O
cipher	O
would	O
turn	O
credit	O
card	O
number	O
into	O
a	O
hexadecimal	O
(	O
e.g.0x96a45cbcf9c2a9425cde9e274948cb67	O
,	O
34	O
bytes	O
,	O
hexadecimal	O
digits	O
)	O
or	O
Base64	B-Protocol
value	O
(	O
e.g.	O
</s>
<s>
Apart	O
from	O
simple	O
formatting	O
problems	O
,	O
using	O
AES-128-CBC	O
,	O
this	O
credit	O
card	O
number	O
might	O
get	O
encrypted	O
to	O
the	O
hexadecimal	O
value	O
0xde015724b081ea7003de4593d792fd8b695b39e095c98f3a220ff43522a2df02	O
.	O
</s>
<s>
This	O
happens	O
because	O
the	O
random	B-Algorithm
seed	I-Algorithm
value	I-Algorithm
that	O
is	O
used	O
to	O
initialize	O
the	O
encryption	O
algorithm	O
and	O
is	O
included	O
as	O
part	O
of	O
the	O
encrypted	O
value	O
is	O
different	O
for	O
each	O
encryption	O
operation	O
.	O
</s>
<s>
Because	O
of	O
this	O
,	O
it	O
is	O
impossible	O
to	O
use	O
data	O
that	O
has	O
been	O
encrypted	O
with	O
the	O
CBC	O
mode	O
as	O
a	O
unique	B-Application
key	I-Application
to	O
identify	O
a	O
row	O
in	O
a	O
database	O
.	O
</s>
<s>
If	O
an	O
FPE	O
is	O
needed	O
on	O
one	O
of	O
these	O
standard	O
sized	O
sets	O
(	O
for	O
example	O
,	O
n	O
=	O
64	O
for	O
DES	B-Algorithm
and	O
n	O
=	O
128	O
for	O
AES	B-Algorithm
)	O
a	O
block	O
cipher	O
of	O
the	O
right	O
size	O
can	O
be	O
used	O
.	O
</s>
<s>
However	O
,	O
in	O
typical	O
usage	O
,	O
a	O
block	O
cipher	O
is	O
used	O
in	O
a	O
mode	B-Algorithm
of	I-Algorithm
operation	I-Algorithm
that	O
allows	O
it	O
to	O
encrypt	O
arbitrarily	O
long	O
messages	O
,	O
and	O
with	O
an	O
initialization	B-Algorithm
vector	I-Algorithm
as	O
discussed	O
above	O
.	O
</s>
<s>
In	O
most	O
of	O
the	O
approaches	O
listed	O
here	O
,	O
a	O
well-understood	O
block	O
cipher	O
(	O
such	O
as	O
AES	B-Algorithm
)	O
is	O
used	O
as	O
a	O
primitive	O
to	O
take	O
the	O
place	O
of	O
an	O
ideal	O
random	O
function	O
.	O
</s>
<s>
Where	O
AES	B-Algorithm
is	O
mentioned	O
in	O
the	O
following	O
discussion	O
,	O
any	O
other	O
good	O
block	O
cipher	O
would	O
work	O
as	O
well	O
.	O
</s>
<s>
This	O
means	O
that	O
if	O
the	O
AES	B-Algorithm
algorithm	O
is	O
used	O
to	O
create	O
an	O
FPE	O
algorithm	O
,	O
then	O
the	O
resulting	O
FPE	O
algorithm	O
is	O
as	O
secure	O
as	O
AES	B-Algorithm
because	O
an	O
adversary	O
capable	O
of	O
defeating	O
the	O
FPE	O
algorithm	O
can	O
also	O
defeat	O
the	O
AES	B-Algorithm
algorithm	O
.	O
</s>
<s>
Therefore	O
,	O
if	O
AES	B-Algorithm
is	O
secure	O
,	O
then	O
the	O
FPE	O
algorithms	O
constructed	O
from	O
it	O
are	O
also	O
secure	O
.	O
</s>
<s>
In	O
all	O
of	O
the	O
following	O
,	O
E	O
denotes	O
the	O
AES	B-Algorithm
encryption	I-Algorithm
operation	O
that	O
is	O
used	O
to	O
construct	O
an	O
FPE	O
algorithm	O
and	O
F	O
denotes	O
the	O
FPE	O
encryption	O
operation	O
.	O
</s>
<s>
Thus	O
,	O
to	O
create	O
a	O
FPE	O
on	O
the	O
domain	O
{0,1,2,3},	O
given	O
a	O
key	O
K	O
apply	O
AES(K )	O
to	O
each	O
integer	O
,	O
giving	O
,	O
for	O
example	O
,	O
</s>
<s>
If	O
there	O
is	O
a	O
set	O
M	O
of	O
allowed	O
values	O
within	O
the	O
domain	O
of	O
a	O
pseudorandom	O
permutation	O
P	O
(	O
for	O
example	O
P	O
can	O
be	O
a	O
block	O
cipher	O
like	O
AES	B-Algorithm
)	O
,	O
an	O
FPE	O
algorithm	O
can	O
be	O
created	O
from	O
the	O
block	O
cipher	O
by	O
repeatedly	O
applying	O
the	O
block	O
cipher	O
until	O
the	O
result	O
is	O
one	O
of	O
the	O
allowed	O
values	O
(	O
within	O
M	O
)	O
.	O
</s>
<s>
If	O
P	O
is	O
a	O
block	O
cipher	O
of	O
a	O
fixed	O
size	O
,	O
such	O
as	O
AES	B-Algorithm
,	O
this	O
is	O
a	O
severe	O
restriction	O
on	O
the	O
sizes	O
of	O
M	O
for	O
which	O
this	O
method	O
is	O
efficient	O
.	O
</s>
<s>
For	O
example	O
,	O
an	O
application	O
may	O
want	O
to	O
encrypt	O
100-bit	O
values	O
with	O
AES	B-Algorithm
in	O
a	O
way	O
that	O
creates	O
another	O
100-bit	O
value	O
.	O
</s>
<s>
With	O
this	O
technique	O
,	O
AES-128-ECB	O
encryption	O
can	O
be	O
applied	O
until	O
it	O
reaches	O
a	O
value	O
which	O
has	O
all	O
of	O
its	O
28	O
highest	O
bits	O
set	O
to	O
0	O
,	O
which	O
will	O
take	O
an	O
average	O
of	O
228	O
iterations	O
to	O
happen	O
.	O
</s>
<s>
It	O
is	O
also	O
possible	O
to	O
make	O
a	O
FPE	O
algorithm	O
using	O
a	O
Feistel	B-Algorithm
network	I-Algorithm
.	O
</s>
<s>
A	O
Feistel	B-Algorithm
network	I-Algorithm
needs	O
a	O
source	O
of	O
pseudo-random	O
values	O
for	O
the	O
sub-keys	O
for	O
each	O
round	O
,	O
and	O
the	O
output	O
of	O
the	O
AES	B-Algorithm
algorithm	O
can	O
be	O
used	O
as	O
these	O
pseudo-random	O
values	O
.	O
</s>
<s>
One	O
way	O
to	O
implement	O
an	O
FPE	O
algorithm	O
using	O
AES	B-Algorithm
and	O
a	O
Feistel	B-Algorithm
network	I-Algorithm
is	O
to	O
use	O
as	O
many	O
bits	O
of	O
AES	B-Algorithm
output	O
as	O
are	O
needed	O
to	O
equal	O
the	O
length	O
of	O
the	O
left	O
or	O
right	O
halves	O
of	O
the	O
Feistel	B-Algorithm
network	I-Algorithm
.	O
</s>
<s>
If	O
a	O
24-bit	O
value	O
is	O
needed	O
as	O
a	O
sub-key	O
,	O
for	O
example	O
,	O
it	O
is	O
possible	O
to	O
use	O
the	O
lowest	O
24	O
bits	O
of	O
the	O
output	O
of	O
AES	B-Algorithm
for	O
this	O
value	O
.	O
</s>
<s>
This	O
may	O
not	O
result	O
in	O
the	O
output	O
of	O
the	O
Feistel	B-Algorithm
network	I-Algorithm
preserving	O
the	O
format	O
of	O
the	O
input	O
,	O
but	O
it	O
is	O
possible	O
to	O
iterate	O
the	O
Feistel	B-Algorithm
network	I-Algorithm
in	O
the	O
same	O
way	O
that	O
the	O
cycle-walking	O
technique	O
does	O
to	O
ensure	O
that	O
format	O
can	O
be	O
preserved	O
.	O
</s>
<s>
Because	O
it	O
is	O
possible	O
to	O
adjust	O
the	O
size	O
of	O
the	O
inputs	O
to	O
a	O
Feistel	B-Algorithm
network	I-Algorithm
,	O
it	O
is	O
possible	O
to	O
make	O
it	O
very	O
likely	O
that	O
this	O
iteration	O
ends	O
very	O
quickly	O
on	O
average	O
.	O
</s>
<s>
In	O
the	O
case	O
of	O
credit	O
card	O
numbers	O
,	O
for	O
example	O
,	O
there	O
are	O
1015	O
possible	O
16-digit	O
credit	O
card	O
numbers	O
(	O
accounting	O
for	O
the	O
redundant	O
check	B-Algorithm
digit	I-Algorithm
)	O
,	O
and	O
because	O
the	O
1015	O
≈	O
249.8	O
,	O
using	O
a	O
50-bit	O
wide	O
Feistel	B-Algorithm
network	I-Algorithm
along	O
with	O
cycle	O
walking	O
will	O
create	O
an	O
FPE	O
algorithm	O
that	O
encrypts	O
fairly	O
quickly	O
on	O
average	O
.	O
</s>
<s>
It	O
is	O
easier	O
to	O
prove	O
security	O
for	O
unbalanced	B-Algorithm
Feistel	I-Algorithm
ciphers	I-Algorithm
than	O
for	O
balanced	O
ones	O
.	O
</s>
<s>
The	O
Hasty	B-Algorithm
Pudding	I-Algorithm
Cipher	I-Algorithm
uses	O
custom	O
constructions	O
(	O
not	O
depending	O
on	O
existing	O
block	O
ciphers	O
as	O
primitives	O
)	O
to	O
encrypt	O
arbitrary	O
finite	O
small	O
domains	O
.	O
</s>
<s>
The	O
FFSEM	O
mode	O
of	O
AES	B-Algorithm
(	O
specification	O
)	O
that	O
has	O
been	O
accepted	O
for	O
consideration	O
by	O
NIST	O
uses	O
the	O
Feistel	B-Algorithm
network	I-Algorithm
construction	O
of	O
Black	O
and	O
Rogaway	O
described	O
above	O
,	O
with	O
AES	B-Algorithm
for	O
the	O
round	O
function	O
,	O
with	O
one	O
slight	O
modification	O
:	O
a	O
single	O
key	O
is	O
used	O
and	O
is	O
tweaked	O
slightly	O
for	O
each	O
round	O
.	O
</s>
<s>
Two	O
mechanisms	O
for	O
format-preserving	B-Algorithm
encryption	I-Algorithm
of	O
JPEG	O
2000	O
were	O
given	O
in	O
the	O
paper	O
"	O
Efficient	O
and	O
Secure	O
Encryption	O
Schemes	O
for	O
JPEG2000	O
"	O
by	O
Hongjun	O
Wu	O
and	O
Di	O
Ma	O
.	O
</s>
<s>
To	O
perform	O
format-preserving	B-Algorithm
encryption	I-Algorithm
of	O
JPEG	O
2000	O
,	O
the	O
technique	O
is	O
to	O
exclude	O
the	O
byte	O
"	O
0xFF	O
"	O
in	O
the	O
encryption	O
and	O
decryption	O
.	O
</s>
<s>
Section	O
8	O
of	O
the	O
FIPS	O
74	O
,	O
Federal	O
Information	O
Processing	O
Standards	O
Publication	O
1981	O
Guidelines	O
for	O
Implementing	O
and	O
Using	O
the	O
NBS	O
Data	B-Algorithm
Encryption	I-Algorithm
Standard	I-Algorithm
,	O
describes	O
a	O
way	O
to	O
use	O
the	O
DES	B-Algorithm
encryption	O
algorithm	O
in	O
a	O
manner	O
that	O
preserves	O
the	O
format	O
of	O
the	O
data	O
via	O
modulo-n	O
addition	O
followed	O
by	O
an	O
unbiasing	O
operation	O
.	O
</s>
<s>
Another	O
early	O
mechanism	O
for	O
format-preserving	B-Algorithm
encryption	I-Algorithm
was	O
Peter	O
Gutmann	O
's	O
"	O
Encrypting	O
data	O
with	O
a	O
restricted	O
range	O
of	O
values	O
"	O
which	O
again	O
performs	O
modulo-n	O
addition	O
on	O
any	O
cipher	O
with	O
some	O
adjustments	O
to	O
make	O
the	O
result	O
uniform	O
,	O
with	O
the	O
resulting	O
encryption	O
being	O
as	O
strong	O
as	O
the	O
underlying	O
encryption	O
algorithm	O
on	O
which	O
it	O
is	O
based	O
.	O
</s>
<s>
The	O
paper	O
"	O
Using	O
Datatype-Preserving	B-Algorithm
Encryption	I-Algorithm
to	O
Enhance	O
Data	O
Warehouse	O
Security	O
"	O
by	O
Michael	O
Brightwell	O
and	O
Harry	O
Smith	O
describes	O
a	O
way	O
to	O
use	O
the	O
DES	B-Algorithm
encryption	O
algorithm	O
in	O
a	O
way	O
that	O
preserves	O
the	O
format	O
of	O
the	O
plaintext	O
.	O
</s>
<s>
The	O
paper	O
"	O
Format-Preserving	B-Algorithm
Encryption	I-Algorithm
"	O
by	O
Mihir	O
Bellare	O
and	O
Thomas	O
Ristenpart	O
describes	O
using	O
"	O
nearly	O
balanced	O
"	O
Feistel	B-Algorithm
networks	I-Algorithm
to	O
create	O
secure	O
FPE	O
algorithms	O
.	O
</s>
<s>
NIST	O
Special	O
Publication	O
800-38G	O
,	O
"	O
Recommendation	O
for	O
Block	B-Algorithm
Cipher	I-Algorithm
Modes	I-Algorithm
of	I-Algorithm
Operation	I-Algorithm
:	O
Methods	O
for	O
Format-Preserving	B-Algorithm
Encryption	I-Algorithm
"	O
specifies	O
two	O
methods	O
:	O
FF1	O
and	O
FF3	O
.	O
</s>
<s>
Details	O
on	O
the	O
proposals	O
submitted	O
for	O
each	O
can	O
be	O
found	O
at	O
the	O
NIST	O
Block	B-Algorithm
Cipher	I-Algorithm
Modes	I-Algorithm
Development	O
site	O
,	O
including	O
patent	O
and	O
test	O
vector	O
information	O
.	O
</s>
<s>
FF1	O
is	O
FFX[Radix]	O
"	O
Format-preserving	O
Feistel-based	O
Encryption	B-Algorithm
Mode	I-Algorithm
"	O
which	O
is	O
also	O
in	O
standards	O
processes	O
under	O
ANSI	O
X9	O
as	O
X9.119	O
and	O
X9.124	O
.	O
</s>
<s>
FF2	O
is	O
VAES3	O
scheme	O
for	O
FFX	O
:	O
An	O
addendum	O
to	O
"	O
The	O
FFX	O
Mode	B-Algorithm
of	I-Algorithm
Operation	I-Algorithm
for	O
Preserving	O
Encryption	O
"	O
:	O
A	O
parameter	O
collection	O
for	O
encipher	O
strings	O
of	O
arbitrary	O
radix	O
with	O
subkey	O
operation	O
to	O
lengthen	O
life	O
of	O
the	O
enciphering	O
key	O
.	O
</s>
