diff options
| author | Gaetan Leplus <gaetan.leplus@airbus.com> | 2019-07-04 14:01:34 +0200 |
|---|---|---|
| committer | Gaetan Leplus <gaetan.leplus@airbus.com> | 2019-07-04 14:09:13 +0200 |
| commit | 7b4050583d09e3d0ecfd7e7c51b9c77792d4b098 (patch) | |
| tree | 91417728bad80e945029cd946949bd745af19e77 /src/add_vhdltbc/sbox.vhd | |
| parent | 6589f3ef20f8f93168be49135764764cd0c02a23 (diff) | |
| download | lilliput-ae-implem-7b4050583d09e3d0ecfd7e7c51b9c77792d4b098.tar.xz | |
Remplacement de la version vhdltbc par la version optimisée et corrigée
Diffstat (limited to 'src/add_vhdltbc/sbox.vhd')
| -rw-r--r-- | src/add_vhdltbc/sbox.vhd | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/add_vhdltbc/sbox.vhd b/src/add_vhdltbc/sbox.vhd new file mode 100644 index 0000000..bf6448c --- /dev/null +++ b/src/add_vhdltbc/sbox.vhd @@ -0,0 +1,70 @@ +-- Implementation of the Lilliput-TBC tweakable block cipher by the +-- Lilliput-AE team, hereby denoted as "the implementer". +-- +-- For more information, feedback or questions, refer to our website: +-- https://paclido.fr/lilliput-ae +-- +-- To the extent possible under law, the implementer has waived all copyright +-- and related or neighboring rights to the source code in this file. +-- http://creativecommons.org/publicdomain/zero/1.0/ + +library IEEE; +library work; +use IEEE.std_logic_1164.all; +use work.crypt_pack.all; + +entity sbox is + port( + sbox_i : in bit8; + sbox_o : out bit8 + ); +end sbox; + + + +architecture sbox_arch of sbox is + + signal a,b : std_logic_vector(3 downto 0); + + signal ax,ay,at,az : std_logic; + signal aa,ab : std_logic; + + signal bx,bz : std_logic; + signal bt,by : std_logic; + + signal cx,cy,ct : std_logic; + signal ca,cb,cz : std_logic; + +begin + + + aa <= sbox_i(3) xor sbox_i(1); + ab <= sbox_i(0) xor (sbox_i(2) and sbox_i(1)); + + az <= sbox_i(2) xor ab; + ax <= aa and (sbox_i(2) xor ab); + ay <= sbox_i(3) and ab; + at <= (az xor sbox_i(3)) and (sbox_i(2) xor aa); + + a <= ax & ay & az & at xor sbox_i(7 downto 4); + + bx <= a(0) xor (a(3) and by); + bz <= a(3) xor (bt and by); + by <= a(2) xor (a(0) and a(1)); + bt <= a(1) xor (a(3) and a(0)); + + b <= bx & by & bz & bt xor sbox_i(3 downto 0); + + ca <= b(3) xor b(1); + cb <= not (b(0) xor (b(2) and b(1))); + + cx <= ca and cz; + cz <= b(2) xor cb; + cy <= b(3) and cb; + ct <= (cz xor b(3)) and (b(2) xor ca); + + sbox_o (7 downto 4) <= cx & cy & cz & ct xor a; + sbox_o (3 downto 0) <= b; + +end sbox_arch; + |
