<s>
In	O
cryptography	O
,	O
an	O
SP-network	B-Algorithm
,	O
or	O
substitution	B-Algorithm
–	I-Algorithm
permutation	I-Algorithm
network	I-Algorithm
(	O
SPN	O
)	O
,	O
is	O
a	O
series	O
of	O
linked	O
mathematical	O
operations	O
used	O
in	O
block	O
cipher	O
algorithms	O
such	O
as	O
AES	B-Algorithm
(	O
Rijndael	B-Algorithm
)	O
,	O
3-Way	B-Algorithm
,	O
Kalyna	B-Algorithm
,	O
Kuznyechik	B-Algorithm
,	O
PRESENT	B-Algorithm
,	O
SAFER	B-Algorithm
,	O
SHARK	B-Algorithm
,	O
and	O
Square	B-Algorithm
.	O
</s>
<s>
Such	O
a	O
network	O
takes	O
a	O
block	O
of	O
the	O
plaintext	O
and	O
the	O
key	O
as	O
inputs	O
,	O
and	O
applies	O
several	O
alternating	O
rounds	O
or	O
layers	O
of	O
substitution	B-Algorithm
boxes	I-Algorithm
(	O
S-boxes	B-Algorithm
)	O
and	O
permutation	B-Algorithm
boxes	I-Algorithm
(	O
P-boxes	O
)	O
to	O
produce	O
the	O
ciphertext	O
block	O
.	O
</s>
<s>
The	O
S-boxes	B-Algorithm
and	O
P-boxes	O
transform	O
of	O
input	O
bits	O
into	O
output	O
bits	O
.	O
</s>
<s>
It	O
is	O
common	O
for	O
these	O
transformations	O
to	O
be	O
operations	O
that	O
are	O
efficient	O
to	O
perform	O
in	O
hardware	O
,	O
such	O
as	O
exclusive	O
or	O
(	O
XOR	B-Application
)	O
and	O
bitwise	O
rotation	O
.	O
</s>
<s>
(	O
In	O
some	O
designs	O
,	O
the	O
S-boxes	B-Algorithm
themselves	O
depend	O
on	O
the	O
key	O
.	O
)	O
</s>
<s>
Decryption	O
is	O
done	O
by	O
simply	O
reversing	O
the	O
process	O
(	O
using	O
the	O
inverses	O
of	O
the	O
S-boxes	B-Algorithm
and	O
P-boxes	O
and	O
applying	O
the	O
round	O
keys	O
in	O
reversed	O
order	O
)	O
.	O
</s>
<s>
An	O
S-box	B-Algorithm
substitutes	O
a	O
small	O
block	O
of	O
bits	O
(	O
the	O
input	O
of	O
the	O
S-box	B-Algorithm
)	O
by	O
another	O
block	O
of	O
bits	O
(	O
the	O
output	O
of	O
the	O
S-box	B-Algorithm
)	O
.	O
</s>
<s>
This	O
substitution	O
should	O
be	O
one-to-one	B-Algorithm
,	O
to	O
ensure	O
invertibility	O
(	O
hence	O
decryption	O
)	O
.	O
</s>
<s>
In	O
particular	O
,	O
the	O
length	O
of	O
the	O
output	O
should	O
be	O
the	O
same	O
as	O
the	O
length	O
of	O
the	O
input	O
(	O
the	O
picture	O
on	O
the	O
right	O
has	O
S-boxes	B-Algorithm
with	O
4	O
input	O
and	O
4	O
output	O
bits	O
)	O
,	O
which	O
is	O
different	O
from	O
S-boxes	B-Algorithm
in	O
general	O
that	O
could	O
also	O
change	O
the	O
length	O
,	O
as	O
in	O
Data	B-Algorithm
Encryption	I-Algorithm
Standard	I-Algorithm
(	O
DES	B-Algorithm
)	O
,	O
for	O
example	O
.	O
</s>
<s>
An	O
S-box	B-Algorithm
is	O
usually	O
not	O
simply	O
a	O
permutation	B-Algorithm
of	O
the	O
bits	O
.	O
</s>
<s>
Rather	O
,	O
a	O
good	O
S-box	B-Algorithm
will	O
have	O
the	O
property	O
that	O
changing	O
one	O
input	O
bit	O
will	O
change	O
about	O
half	O
of	O
the	O
output	O
bits	O
(	O
or	O
an	O
avalanche	O
effect	O
)	O
.	O
</s>
<s>
A	O
P-box	O
is	O
a	O
permutation	B-Algorithm
of	O
all	O
the	O
bits	O
:	O
it	O
takes	O
the	O
outputs	O
of	O
all	O
the	O
S-boxes	B-Algorithm
of	O
one	O
round	O
,	O
permutes	O
the	O
bits	O
,	O
and	O
feeds	O
them	O
into	O
the	O
S-boxes	B-Algorithm
of	O
the	O
next	O
round	O
.	O
</s>
<s>
A	O
good	O
P-box	O
has	O
the	O
property	O
that	O
the	O
output	O
bits	O
of	O
any	O
S-box	B-Algorithm
are	O
distributed	O
to	O
as	O
many	O
S-box	B-Algorithm
inputs	O
as	O
possible	O
.	O
</s>
<s>
At	O
each	O
round	O
,	O
the	O
round	O
key	O
(	O
obtained	O
from	O
the	O
key	O
with	O
some	O
simple	O
operations	O
,	O
for	O
instance	O
,	O
using	O
S-boxes	B-Algorithm
and	O
P-boxes	O
)	O
is	O
combined	O
using	O
some	O
group	O
operation	O
,	O
typically	O
XOR	B-Application
.	O
</s>
<s>
A	O
single	O
typical	O
S-box	B-Algorithm
or	O
a	O
single	O
P-box	O
alone	O
does	O
not	O
have	O
much	O
cryptographic	O
strength	O
:	O
an	O
S-box	B-Algorithm
could	O
be	O
thought	O
of	O
as	O
a	O
substitution	O
cipher	O
,	O
while	O
a	O
P-box	O
could	O
be	O
thought	O
of	O
as	O
a	O
transposition	B-Algorithm
cipher	I-Algorithm
.	O
</s>
<s>
The	O
reason	O
for	O
diffusion	O
is	O
the	O
following	O
:	O
If	O
one	O
changes	O
one	O
bit	O
of	O
the	O
plaintext	O
,	O
then	O
it	O
is	O
fed	O
into	O
an	O
S-box	B-Algorithm
,	O
whose	O
output	O
will	O
change	O
at	O
several	O
bits	O
,	O
then	O
all	O
these	O
changes	O
are	O
distributed	O
by	O
the	O
P-box	O
among	O
several	O
S-boxes	B-Algorithm
,	O
hence	O
the	O
outputs	O
of	O
all	O
of	O
these	O
S-boxes	B-Algorithm
are	O
again	O
changed	O
at	O
several	O
bits	O
,	O
and	O
so	O
on	O
.	O
</s>
<s>
Doing	O
several	O
rounds	O
,	O
each	O
bit	O
changes	O
several	O
times	O
back	O
and	O
forth	O
,	O
therefore	O
,	O
by	O
the	O
end	O
,	O
the	O
ciphertext	O
has	O
changed	O
completely	O
,	O
in	O
a	O
pseudorandom	B-Error_Name
manner	O
.	O
</s>
<s>
Although	O
a	O
Feistel	B-Algorithm
network	I-Algorithm
that	O
uses	O
S-boxes	B-Algorithm
(	O
such	O
as	O
DES	B-Algorithm
)	O
is	O
quite	O
similar	O
to	O
SP	O
networks	O
,	O
there	O
are	O
some	O
differences	O
that	O
make	O
either	O
this	O
or	O
that	O
more	O
applicable	O
in	O
certain	O
situations	O
.	O
</s>
<s>
For	O
a	O
given	O
amount	O
of	O
confusion	O
and	O
diffusion	O
,	O
an	O
SP	O
network	O
has	O
more	O
"	O
inherent	O
parallelism	O
"	O
and	O
so	O
—	O
given	O
a	O
CPU	O
with	O
many	O
execution	B-General_Concept
units	I-General_Concept
—	O
can	O
be	O
computed	O
faster	O
than	O
a	O
Feistel	B-Algorithm
network	I-Algorithm
.	O
</s>
<s>
CPUs	O
with	O
few	O
execution	B-General_Concept
units	I-General_Concept
—	O
such	O
as	O
most	O
smart	O
cards	O
—	O
cannot	O
take	O
advantage	O
of	O
this	O
inherent	O
parallelism	O
.	O
</s>
<s>
Also	O
SP	O
ciphers	O
require	O
S-boxes	B-Algorithm
to	O
be	O
invertible	O
(	O
to	O
perform	O
decryption	O
)	O
;	O
Feistel	O
inner	O
functions	O
have	O
no	O
such	O
restriction	O
and	O
can	O
be	O
constructed	O
as	O
one-way	O
functions	O
.	O
</s>
