chiffrement.vhd (6098B)
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 chiffrement is 18 port ( 19 chiffrement_i : in type_state; 20 permutation_i : in std_logic; 21 round_key_i : in type_key; 22 chiffrement_o : out type_state; 23 decrypt_i : in std_logic 24 ); 25 26 end chiffrement; 27 28 architecture chiffrement_arch of chiffrement is 29 30 signal non_linear_s : type_half_state; 31 signal non_linear_s1 : type_half_state; 32 signal linear_s : type_half_state; 33 signal linear_tmp_s : type_half_state; 34 signal linear : bit8; 35 36 component sbox 37 port ( 38 sbox_i : in bit8; 39 sbox_o : out bit8 40 ); 41 end component; 42 43 44 begin 45 46 47 non_linear_s(0)(0) <= chiffrement_i(1)(3) xor round_key_i(1)(3); 48 non_linear_s(0)(1) <= chiffrement_i(1)(2) xor round_key_i(1)(2); 49 non_linear_s(0)(2) <= chiffrement_i(1)(1) xor round_key_i(1)(1); 50 non_linear_s(0)(3) <= chiffrement_i(1)(0) xor round_key_i(1)(0); 51 non_linear_s(1)(0) <= chiffrement_i(0)(3) xor round_key_i(0)(3); 52 non_linear_s(1)(1) <= chiffrement_i(0)(2) xor round_key_i(0)(2); 53 non_linear_s(1)(2) <= chiffrement_i(0)(1) xor round_key_i(0)(1); 54 non_linear_s(1)(3) <= chiffrement_i(0)(0) xor round_key_i(0)(0); 55 56 57 boucle_ligne : for i in 0 to 1 generate 58 boucle_colonne : for j in 0 to 3 generate 59 sboxx : sbox port map( 60 sbox_i => non_linear_s(i)(j), 61 sbox_o => non_linear_s1(i)(j) 62 ); 63 end generate; 64 end generate; 65 66 linear_tmp_s(0)(0) <= chiffrement_i(2)(0); 67 linear_tmp_s(0)(1) <= chiffrement_i(2)(1) xor chiffrement_i(1)(3); 68 linear_tmp_s(0)(2) <= chiffrement_i(2)(2) xor chiffrement_i(1)(3); 69 linear_tmp_s(0)(3) <= chiffrement_i(2)(3) xor chiffrement_i(1)(3); 70 linear_tmp_s(1)(0) <= chiffrement_i(3)(0) xor chiffrement_i(1)(3); 71 linear_tmp_s(1)(1) <= chiffrement_i(3)(1) xor chiffrement_i(1)(3); 72 linear_tmp_s(1)(2) <= chiffrement_i(3)(2) xor chiffrement_i(1)(3); 73 linear_tmp_s(1)(3) <= chiffrement_i(3)(3) xor chiffrement_i(1)(0) xor chiffrement_i(1)(1) xor chiffrement_i(1)(2); 74 linear <= chiffrement_i(0)(3) xor chiffrement_i(0)(1) xor chiffrement_i(0)(2) xor chiffrement_i(1)(3); 75 76 linear_s(0)(0) <= non_linear_s1(0)(0) xor linear_tmp_s(0)(0); 77 linear_s(0)(1) <= non_linear_s1(0)(1) xor linear_tmp_s(0)(1); 78 linear_s(0)(2) <= non_linear_s1(0)(2) xor linear_tmp_s(0)(2); 79 linear_s(0)(3) <= non_linear_s1(0)(3) xor linear_tmp_s(0)(3); 80 linear_s(1)(0) <= non_linear_s1(1)(0) xor linear_tmp_s(1)(0); 81 linear_s(1)(1) <= non_linear_s1(1)(1) xor linear_tmp_s(1)(1); 82 linear_s(1)(2) <= non_linear_s1(1)(2) xor linear_tmp_s(1)(2); 83 linear_s(1)(3) <= non_linear_s1(1)(3) xor linear xor linear_tmp_s(1)(3); 84 85 chiffrement_o(0)(0) <= linear_s(1)(2) when permutation_i='1' and decrypt_i='0' else 86 linear_s(1)(1) when permutation_i ='1' and decrypt_i='1' else chiffrement_i(0)(0); 87 chiffrement_o(0)(1) <= linear_s(0)(3) when permutation_i='1' and decrypt_i='0' else 88 linear_s(0)(1) when permutation_i ='1' and decrypt_i='1' else chiffrement_i(0)(1); 89 chiffrement_o(0)(2) <= linear_s(1)(0) when permutation_i='1' and decrypt_i='0' else 90 linear_s(1)(2) when permutation_i ='1' and decrypt_i='1' else chiffrement_i(0)(2); 91 chiffrement_o(0)(3) <= linear_s(0)(2) when permutation_i='1' and decrypt_i='0' else 92 linear_s(0)(0) when permutation_i ='1' and decrypt_i='1' else chiffrement_i(0)(3); 93 chiffrement_o(1)(0) <= linear_s(0)(0) when permutation_i='1' and decrypt_i='0' else 94 linear_s(0)(2) when permutation_i ='1' and decrypt_i='1' else chiffrement_i(1)(0); 95 chiffrement_o(1)(1) <= linear_s(0)(1) when permutation_i='1' and decrypt_i='0' else 96 linear_s(0)(3) when permutation_i ='1' and decrypt_i='1' else chiffrement_i(1)(1); 97 chiffrement_o(1)(2) <= linear_s(1)(1) when permutation_i='1' and decrypt_i='0' else 98 linear_s(1)(0) when permutation_i ='1' and decrypt_i='1' else chiffrement_i(1)(2); 99 chiffrement_o(1)(3) <= linear_s(1)(3) when permutation_i='1' and decrypt_i='0' else 100 linear_s(1)(3) when permutation_i ='1' and decrypt_i='1' else chiffrement_i(1)(3); 101 chiffrement_o(2)(0) <= chiffrement_i(0)(3) when permutation_i='1' and decrypt_i='0' else 102 chiffrement_i(1)(0) when permutation_i ='1' and decrypt_i='1' else linear_s(0)(0); 103 chiffrement_o(2)(1) <= chiffrement_i(0)(1) when permutation_i='1' and decrypt_i='0' else 104 chiffrement_i(1)(1) when permutation_i ='1' and decrypt_i='1' else linear_s(0)(1); 105 chiffrement_o(2)(2) <= chiffrement_i(1)(0) when permutation_i='1' and decrypt_i='0' else 106 chiffrement_i(0)(3) when permutation_i ='1' and decrypt_i='1' else linear_s(0)(2); 107 chiffrement_o(2)(3) <= chiffrement_i(1)(1) when permutation_i='1' and decrypt_i='0' else 108 chiffrement_i(0)(1) when permutation_i ='1' and decrypt_i='1' else linear_s(0)(3); 109 chiffrement_o(3)(0) <= chiffrement_i(1)(2) when permutation_i='1' and decrypt_i='0' else 110 chiffrement_i(0)(2) when permutation_i ='1' and decrypt_i='1' else linear_s(1)(0); 111 chiffrement_o(3)(1) <= chiffrement_i(0)(0) when permutation_i='1' and decrypt_i='0' else 112 chiffrement_i(1)(2) when permutation_i ='1' and decrypt_i='1' else linear_s(1)(1); 113 chiffrement_o(3)(2) <= chiffrement_i(0)(2) when permutation_i='1' and decrypt_i='0' else 114 chiffrement_i(0)(0) when permutation_i ='1' and decrypt_i='1' else linear_s(1)(2); 115 chiffrement_o(3)(3) <= chiffrement_i(1)(3) when permutation_i='1' and decrypt_i='0' else 116 chiffrement_i(1)(3) when permutation_i ='1' and decrypt_i='1' else linear_s(1)(3); 117 118 end chiffrement_arch; 119 120 configuration chiffrement_conf of chiffrement is 121 for chiffrement_arch 122 for boucle_ligne 123 for boucle_colonne 124 for all : sbox 125 use entity work.sbox( sbox_arch ); 126 end for; 127 end for; 128 end for; 129 end for; 130 end configuration chiffrement_conf ;