machine_etat_chiffrement.vhd (5097B)
1 -- Implementation of the Lilliput-TBC tweakable block cipher by the 2 -- Lilliput-AE team, hereby denoted as "the implementer". 3 -- 4 -- For more information, feedback or questions, refer to our website: 5 -- https://paclido.fr/lilliput-ae 6 -- 7 -- To the extent possible under law, the implementer has waived all copyright 8 -- and related or neighboring rights to the source code in this file. 9 -- http://creativecommons.org/publicdomain/zero/1.0/ 10 11 library IEEE; 12 library work; 13 use IEEE.numeric_std.all; 14 use IEEE.std_logic_1164.all; 15 use work.crypt_pack.all; 16 17 entity fsm_chiffrement is 18 port ( 19 start_i : in std_logic; 20 clock_i : in std_logic; 21 reset_i : in std_logic; 22 decrypt_i : in std_logic; 23 compteur_o : out std_logic_vector(7 downto 0) ; 24 liliput_on_out : out std_logic; 25 data_out_valid_o : out std_logic; 26 permutation_o : out std_logic; 27 invert_o : out std_logic; 28 mux_keyschdule_o : out std_logic; 29 mux_chiffrement_o : out std_logic 30 ); 31 end fsm_chiffrement; 32 33 architecture fsm_chiffrement_arch of fsm_chiffrement is 34 35 type state is (etat_initial,initroundkey, e_firstround, e_loopround, d_initfirst,d_initloop,d_initlast,d_firstround, d_loopround, lastround); 36 37 signal present, futur : state; 38 signal compteur : integer range 0 to ROUND+1; 39 40 begin 41 42 compteur_o <= std_logic_vector(to_unsigned(compteur,8)); 43 44 process_0 : process(clock_i,reset_i) 45 begin 46 if reset_i = '0' then 47 present <= etat_initial; 48 compteur <= 0; 49 50 elsif clock_i'event and clock_i ='1' then 51 present <= futur; 52 if( present =d_loopround or present =d_firstround or present =d_initlast) then 53 compteur <= compteur -1; 54 elsif (present = initroundkey or present =d_initloop or present =d_initfirst or present = e_firstround or present =e_loopround ) then 55 compteur <= compteur+1; 56 else 57 compteur <= 0; 58 end if; 59 end if; 60 end process process_0; 61 62 process_1 : process(present, start_i,decrypt_i,compteur) 63 begin 64 65 case present is 66 when etat_initial => 67 if start_i = '1' then 68 futur <= initroundkey; 69 else 70 futur <= present; 71 end if; 72 73 when initroundkey => 74 if decrypt_i = '0' then 75 futur <= e_loopround; 76 elsif decrypt_i = '1' then 77 futur <= d_initloop; 78 end if; 79 80 when e_firstround => 81 futur <= e_loopround; 82 83 when e_loopround => 84 if compteur = ROUND-1 then 85 futur <= lastround; 86 else 87 futur <= present; 88 end if; 89 90 when d_initfirst => 91 futur <= d_initloop; 92 93 when d_initloop => 94 if compteur = ROUND-2 then 95 futur <= d_initlast; 96 else 97 futur <= present; 98 end if; 99 100 when d_initlast => 101 futur <= d_firstround; 102 103 when d_firstround => 104 futur <= d_loopround; 105 106 when d_loopround => 107 if compteur = 0 then 108 futur <= lastround; 109 else 110 futur <= present; 111 end if; 112 113 when lastround => 114 futur <= etat_initial; 115 116 end case; 117 end process process_1; 118 119 process_2 : process(present) 120 121 begin 122 case present is 123 when etat_initial => 124 liliput_on_out <= '0'; 125 data_out_valid_o <= '0'; 126 permutation_o <= '0'; 127 mux_keyschdule_o <= '1'; 128 mux_chiffrement_o <= '1'; 129 invert_o <= '0'; 130 131 when initroundkey => 132 liliput_on_out <= '0'; 133 data_out_valid_o <= '0'; 134 permutation_o <= '0'; 135 mux_keyschdule_o <= '1'; 136 mux_chiffrement_o <= '1'; 137 invert_o <= '0'; 138 139 when e_firstround => 140 liliput_on_out <= '1'; 141 data_out_valid_o <= '0'; 142 permutation_o <= '1'; 143 mux_keyschdule_o <= '0'; 144 mux_chiffrement_o <= '0'; 145 invert_o <= '0'; 146 147 when e_loopround => 148 liliput_on_out <= '1'; 149 data_out_valid_o <= '0'; 150 permutation_o <= '1'; 151 mux_keyschdule_o <= '0'; 152 mux_chiffrement_o <= '0'; 153 invert_o <= '0'; 154 155 when d_initfirst => 156 liliput_on_out <= '0'; 157 data_out_valid_o <= '0'; 158 permutation_o <= '0'; 159 mux_keyschdule_o <= '0'; 160 mux_chiffrement_o <= '1'; 161 invert_o <= '0'; 162 163 when d_initloop => 164 liliput_on_out <= '0'; 165 data_out_valid_o <= '0'; 166 permutation_o <= '0'; 167 mux_keyschdule_o <= '0'; 168 mux_chiffrement_o <= '1'; 169 invert_o <= '0'; 170 171 when d_initlast => 172 liliput_on_out <= '0'; 173 data_out_valid_o <= '0'; 174 permutation_o <= '0'; 175 mux_keyschdule_o <= '0'; 176 mux_chiffrement_o <= '1'; 177 invert_o <= '1'; 178 179 when d_firstround => 180 liliput_on_out <= '1'; 181 data_out_valid_o <= '0'; 182 permutation_o <= '1'; 183 mux_keyschdule_o <= '0'; 184 mux_chiffrement_o <= '0'; 185 invert_o <= '1'; 186 187 when d_loopround => 188 liliput_on_out <= '1'; 189 data_out_valid_o <= '0'; 190 permutation_o <= '1'; 191 mux_keyschdule_o <= '0'; 192 mux_chiffrement_o <= '0'; 193 invert_o <= '1'; 194 195 when lastround => 196 liliput_on_out <= '1'; 197 data_out_valid_o <= '1'; 198 permutation_o <= '0'; 199 mux_keyschdule_o <= '0'; 200 mux_chiffrement_o <= '0'; 201 invert_o <= '0'; 202 203 end case; 204 end process process_2; 205 206 end architecture fsm_chiffrement_arch;