lilliput-ae-reference-implementation

Implementations of Lilliput-AE submitted to the NIST LWC standardization process
git clone https://git.kevinlegouguec.net/lilliput-ae-reference-implementation
Log | Files | Refs | README

machine_etat_chiffrement.vhd (3209B)


      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 		invert_o          : out std_logic;
     26 		data_out_valid_o  : out std_logic;
     27 		permutation_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, firstround, loopround, lastround);
     36 
     37 	signal present, futur : state;
     38 	signal compteur       : integer range 0 to ROUND;
     39 
     40 begin
     41 
     42 	invert_o   <= '0';
     43 	compteur_o <= std_logic_vector(to_unsigned(compteur,8));
     44 
     45 	process_0 : process(clock_i,reset_i,compteur)
     46 	begin
     47 		if reset_i = '0' then
     48 			compteur <= 0;
     49 			present  <= etat_initial;
     50 		elsif clock_i'event and clock_i='1' then
     51 			present <= futur;
     52 			if (present = initroundkey or present = firstround or present =loopround) then
     53 				compteur <= compteur+1;
     54 			else
     55 				compteur <= 0;
     56 			end if;
     57 		end if;
     58 	end process process_0;
     59 
     60 
     61 	process_1 : process(present, start_i, compteur)
     62 	begin
     63 		case present is
     64 			when etat_initial =>
     65 				if start_i = '1' then
     66 					futur <= initroundkey;
     67 				else
     68 					futur <= present;
     69 				end if;
     70 
     71 			when initroundkey =>
     72 				futur <= firstround;
     73 
     74 			when firstround =>
     75 				futur <= loopround;
     76 
     77 			when loopround =>
     78 				if compteur = ROUND-1 then
     79 					futur <= lastround;
     80 				else
     81 					futur <= present;
     82 				end if;
     83 
     84 			when lastround =>
     85 				futur <= etat_initial;
     86 
     87 		end case;
     88 	end process process_1;
     89 
     90 	process_2 : process(present)
     91 	begin
     92 		case present is
     93 			when etat_initial =>
     94 				liliput_on_out    <= '0';
     95 				data_out_valid_o  <= '0';
     96 				permutation_o     <= '0';
     97 				mux_keyschdule_o  <= '1';
     98 				mux_chiffrement_o <= '1';
     99 
    100 			when initroundkey =>
    101 				liliput_on_out    <= '0';
    102 				data_out_valid_o  <= '0';
    103 				permutation_o     <= '0';
    104 				mux_keyschdule_o  <= '1';
    105 				mux_chiffrement_o <= '1';
    106 
    107 			when firstround =>
    108 				liliput_on_out    <= '1';
    109 				data_out_valid_o  <= '0';
    110 				permutation_o     <= '1';
    111 				mux_keyschdule_o  <= '0';
    112 				mux_chiffrement_o <= '0';
    113 
    114 			when loopround =>
    115 				liliput_on_out    <= '1';
    116 				data_out_valid_o  <= '0';
    117 				permutation_o     <= '1';
    118 				mux_keyschdule_o  <= '0';
    119 				mux_chiffrement_o <= '0';
    120 
    121 			when lastround =>
    122 				liliput_on_out    <= '1';
    123 				data_out_valid_o  <= '1';
    124 				permutation_o     <= '0';
    125 				mux_keyschdule_o  <= '0';
    126 				mux_chiffrement_o <= '0';
    127 		end case;
    128 	end process process_2;
    129 
    130 end architecture fsm_chiffrement_arch;