summaryrefslogtreecommitdiff
path: root/src/add_vhdltbc/sbox.vhd
diff options
context:
space:
mode:
authorGaetan Leplus <gaetan.leplus@airbus.com>2019-07-04 14:01:34 +0200
committerGaetan Leplus <gaetan.leplus@airbus.com>2019-07-04 14:09:13 +0200
commitd560b7c442c950a59cea691d90abdd42a35b9bf1 (patch)
tree91417728bad80e945029cd946949bd745af19e77 /src/add_vhdltbc/sbox.vhd
parent7e4b76b05d9a3945b916af09de0f9672abd2b22c (diff)
downloadlilliput-ae-implem-d560b7c442c950a59cea691d90abdd42a35b9bf1.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.vhd70
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;
+