|
|
@ -32,15 +32,15 @@ entity des is |
|
|
|
); |
|
|
|
port ( |
|
|
|
reset_i : in std_logic; -- async reset |
|
|
|
clk_i : IN std_logic; -- clock |
|
|
|
mode_i : IN std_logic; -- des-modus: 0 = encrypt, 1 = decrypt |
|
|
|
key_i : IN std_logic_vector(0 TO 63); -- key input |
|
|
|
data_i : IN std_logic_vector(0 TO 63); -- data input |
|
|
|
valid_i : IN std_logic; -- input key/data valid |
|
|
|
accept_o : out std_logic; -- input data accepted |
|
|
|
data_o : OUT std_logic_vector(0 TO 63); -- data output |
|
|
|
valid_o : OUT std_logic; -- output data valid flag |
|
|
|
accept_i : in std_logic |
|
|
|
clk_i : in std_logic; -- clock |
|
|
|
mode_i : in std_logic; -- des-modus: 0 = encrypt, 1 = decrypt |
|
|
|
key_i : in std_logic_vector(0 to 63); -- key input |
|
|
|
data_i : in std_logic_vector(0 to 63); -- data input |
|
|
|
valid_i : in std_logic; -- input key/data valid |
|
|
|
accept_o : out std_logic; -- input accept |
|
|
|
data_o : out std_logic_vector(0 to 63); -- data output |
|
|
|
valid_o : out std_logic; -- output data valid flag |
|
|
|
accept_i : in std_logic -- output accept |
|
|
|
); |
|
|
|
end entity des; |
|
|
|
|
|
|
@ -56,294 +56,294 @@ begin |
|
|
|
|
|
|
|
begin |
|
|
|
|
|
|
|
crypt : PROCESS (clk_i, reset_i) IS |
|
|
|
crypt : process (clk_i, reset_i) is |
|
|
|
-- variables for key calculation |
|
|
|
VARIABLE c0 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c1 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c2 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c3 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c4 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c5 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c6 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c7 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c8 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c9 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c10 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c11 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c12 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c13 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c14 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c15 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE c16 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d0 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d1 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d2 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d3 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d4 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d5 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d6 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d7 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d8 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d9 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d10 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d11 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d12 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d13 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d14 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d15 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
VARIABLE d16 : std_logic_vector(0 TO 27) := (others => '0'); |
|
|
|
variable c0 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c1 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c2 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c3 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c4 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c5 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c6 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c7 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c8 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c9 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c10 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c11 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c12 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c13 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c14 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c15 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable c16 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d0 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d1 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d2 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d3 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d4 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d5 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d6 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d7 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d8 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d9 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d10 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d11 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d12 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d13 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d14 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d15 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
variable d16 : std_logic_vector(0 to 27) := (others => '0'); |
|
|
|
-- key variables |
|
|
|
VARIABLE key1 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key2 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key3 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key4 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key5 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key6 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key7 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key8 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key9 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key10 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key11 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key12 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key13 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key14 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key15 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
VARIABLE key16 : std_logic_vector(0 TO 47) := (others => '0'); |
|
|
|
variable key1 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key2 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key3 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key4 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key5 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key6 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key7 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key8 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key9 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key10 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key11 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key12 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key13 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key14 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key15 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
variable key16 : std_logic_vector(0 to 47) := (others => '0'); |
|
|
|
-- variables for left & right data blocks |
|
|
|
VARIABLE l0 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l1 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l2 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l3 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l4 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l5 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l6 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l7 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l8 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l9 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l10 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l11 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l12 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l13 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l14 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l15 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE l16 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r0 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r1 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r2 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r3 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r4 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r5 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r6 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r7 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r8 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r9 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r10 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r11 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r12 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r13 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r14 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r15 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
VARIABLE r16 : std_logic_vector( 0 TO 31) := (others => '0'); |
|
|
|
variable l0 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l1 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l2 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l3 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l4 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l5 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l6 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l7 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l8 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l9 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l10 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l11 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l12 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l13 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l14 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l15 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable l16 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r0 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r1 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r2 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r3 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r4 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r5 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r6 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r7 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r8 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r9 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r10 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r11 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r12 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r13 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r14 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r15 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
variable r16 : std_logic_vector( 0 to 31) := (others => '0'); |
|
|
|
-- variables for mode & valid shift registers |
|
|
|
VARIABLE mode : std_logic_vector(0 TO 16) := (others => '0'); |
|
|
|
VARIABLE valid : std_logic_vector(0 TO 17) := (others => '0'); |
|
|
|
BEGIN |
|
|
|
variable mode : std_logic_vector(0 to 16) := (others => '0'); |
|
|
|
variable valid : std_logic_vector(0 to 17) := (others => '0'); |
|
|
|
begin |
|
|
|
if(reset_i = '0') then |
|
|
|
data_o <= (others => '0'); |
|
|
|
valid_o <= '0'; |
|
|
|
elsif rising_edge( clk_i ) THEN |
|
|
|
elsif rising_edge( clk_i ) then |
|
|
|
-- shift registers |
|
|
|
valid(1 TO 17) := valid(0 TO 16); |
|
|
|
valid(1 to 17) := valid(0 to 16); |
|
|
|
valid(0) := valid_i; |
|
|
|
mode(1 TO 16) := mode(0 TO 15); |
|
|
|
mode(1 to 16) := mode(0 to 15); |
|
|
|
mode(0) := mode_i; |
|
|
|
-- output stage |
|
|
|
accept_o <= '1'; |
|
|
|
valid_o <= valid(17); |
|
|
|
data_o <= ipn( ( r16 & l16 ) ); |
|
|
|
-- 16. stage |
|
|
|
IF mode(16) = '0' THEN |
|
|
|
c16 := c15(1 TO 27) & c15(0); |
|
|
|
d16 := d15(1 TO 27) & d15(0); |
|
|
|
ELSE |
|
|
|
c16 := c15(27) & c15(0 TO 26); |
|
|
|
d16 := d15(27) & d15(0 TO 26); |
|
|
|
END IF; |
|
|
|
if mode(16) = '0' then |
|
|
|
c16 := c15(1 to 27) & c15(0); |
|
|
|
d16 := d15(1 to 27) & d15(0); |
|
|
|
else |
|
|
|
c16 := c15(27) & c15(0 to 26); |
|
|
|
d16 := d15(27) & d15(0 to 26); |
|
|
|
end if; |
|
|
|
key16 := pc2( ( c16 & d16 ) ); |
|
|
|
l16 := r15; |
|
|
|
r16 := l15 xor ( f( r15, key16 ) ); |
|
|
|
-- 15. stage |
|
|
|
IF mode(15) = '0' THEN |
|
|
|
c15 := c14(2 TO 27) & c14(0 TO 1); |
|
|
|
d15 := d14(2 TO 27) & d14(0 TO 1); |
|
|
|
ELSE |
|
|
|
c15 := c14(26 TO 27) & c14(0 TO 25); |
|
|
|
d15 := d14(26 TO 27) & d14(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(15) = '0' then |
|
|
|
c15 := c14(2 to 27) & c14(0 to 1); |
|
|
|
d15 := d14(2 to 27) & d14(0 to 1); |
|
|
|
else |
|
|
|
c15 := c14(26 to 27) & c14(0 to 25); |
|
|
|
d15 := d14(26 to 27) & d14(0 to 25); |
|
|
|
end if; |
|
|
|
key15 := pc2( ( c15 & d15 ) ); |
|
|
|
l15 := r14; |
|
|
|
r15 := l14 xor ( f( r14, key15 ) ); |
|
|
|
-- 14. stage |
|
|
|
IF mode(14) = '0' THEN |
|
|
|
c14 := c13(2 TO 27) & c13(0 TO 1); |
|
|
|
d14 := d13(2 TO 27) & d13(0 TO 1); |
|
|
|
ELSE |
|
|
|
c14 := c13(26 TO 27) & c13(0 TO 25); |
|
|
|
d14 := d13(26 TO 27) & d13(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(14) = '0' then |
|
|
|
c14 := c13(2 to 27) & c13(0 to 1); |
|
|
|
d14 := d13(2 to 27) & d13(0 to 1); |
|
|
|
else |
|
|
|
c14 := c13(26 to 27) & c13(0 to 25); |
|
|
|
d14 := d13(26 to 27) & d13(0 to 25); |
|
|
|
end if; |
|
|
|
key14 := pc2( ( c14 & d14 ) ); |
|
|
|
l14 := r13; |
|
|
|
r14 := l13 xor ( f( r13, key14 ) ); |
|
|
|
-- 13. stage |
|
|
|
IF mode(13) = '0' THEN |
|
|
|
c13 := c12(2 TO 27) & c12(0 TO 1); |
|
|
|
d13 := d12(2 TO 27) & d12(0 TO 1); |
|
|
|
ELSE |
|
|
|
c13 := c12(26 TO 27) & c12(0 TO 25); |
|
|
|
d13 := d12(26 TO 27) & d12(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(13) = '0' then |
|
|
|
c13 := c12(2 to 27) & c12(0 to 1); |
|
|
|
d13 := d12(2 to 27) & d12(0 to 1); |
|
|
|
else |
|
|
|
c13 := c12(26 to 27) & c12(0 to 25); |
|
|
|
d13 := d12(26 to 27) & d12(0 to 25); |
|
|
|
end if; |
|
|
|
key13 := pc2( ( c13 & d13 ) ); |
|
|
|
l13 := r12; |
|
|
|
r13 := l12 xor ( f( r12, key13 ) ); |
|
|
|
-- 12. stage |
|
|
|
IF mode(12) = '0' THEN |
|
|
|
c12 := c11(2 TO 27) & c11(0 TO 1); |
|
|
|
d12 := d11(2 TO 27) & d11(0 TO 1); |
|
|
|
ELSE |
|
|
|
c12 := c11(26 TO 27) & c11(0 TO 25); |
|
|
|
d12 := d11(26 TO 27) & d11(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(12) = '0' then |
|
|
|
c12 := c11(2 to 27) & c11(0 to 1); |
|
|
|
d12 := d11(2 to 27) & d11(0 to 1); |
|
|
|
else |
|
|
|
c12 := c11(26 to 27) & c11(0 to 25); |
|
|
|
d12 := d11(26 to 27) & d11(0 to 25); |
|
|
|
end if; |
|
|
|
key12 := pc2( ( c12 & d12 ) ); |
|
|
|
l12 := r11; |
|
|
|
r12 := l11 xor ( f( r11, key12 ) ); |
|
|
|
-- 11. stage |
|
|
|
IF mode(11) = '0' THEN |
|
|
|
c11 := c10(2 TO 27) & c10(0 TO 1); |
|
|
|
d11 := d10(2 TO 27) & d10(0 TO 1); |
|
|
|
ELSE |
|
|
|
c11 := c10(26 TO 27) & c10(0 TO 25); |
|
|
|
d11 := d10(26 TO 27) & d10(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(11) = '0' then |
|
|
|
c11 := c10(2 to 27) & c10(0 to 1); |
|
|
|
d11 := d10(2 to 27) & d10(0 to 1); |
|
|
|
else |
|
|
|
c11 := c10(26 to 27) & c10(0 to 25); |
|
|
|
d11 := d10(26 to 27) & d10(0 to 25); |
|
|
|
end if; |
|
|
|
key11 := pc2( ( c11 & d11 ) ); |
|
|
|
l11 := r10; |
|
|
|
r11 := l10 xor ( f( r10, key11 ) ); |
|
|
|
-- 10. stage |
|
|
|
IF mode(10) = '0' THEN |
|
|
|
c10 := c9(2 TO 27) & c9(0 TO 1); |
|
|
|
d10 := d9(2 TO 27) & d9(0 TO 1); |
|
|
|
ELSE |
|
|
|
c10 := c9(26 TO 27) & c9(0 TO 25); |
|
|
|
d10 := d9(26 TO 27) & d9(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(10) = '0' then |
|
|
|
c10 := c9(2 to 27) & c9(0 to 1); |
|
|
|
d10 := d9(2 to 27) & d9(0 to 1); |
|
|
|
else |
|
|
|
c10 := c9(26 to 27) & c9(0 to 25); |
|
|
|
d10 := d9(26 to 27) & d9(0 to 25); |
|
|
|
end if; |
|
|
|
key10 := pc2( ( c10 & d10 ) ); |
|
|
|
l10 := r9; |
|
|
|
r10 := l9 xor ( f( r9, key10 ) ); |
|
|
|
-- 9. stage |
|
|
|
IF mode(9) = '0' THEN |
|
|
|
c9 := c8(1 TO 27) & c8(0); |
|
|
|
d9 := d8(1 TO 27) & d8(0); |
|
|
|
ELSE |
|
|
|
c9 := c8(27) & c8(0 TO 26); |
|
|
|
d9 := d8(27) & d8(0 TO 26); |
|
|
|
END IF; |
|
|
|
if mode(9) = '0' then |
|
|
|
c9 := c8(1 to 27) & c8(0); |
|
|
|
d9 := d8(1 to 27) & d8(0); |
|
|
|
else |
|
|
|
c9 := c8(27) & c8(0 to 26); |
|
|
|
d9 := d8(27) & d8(0 to 26); |
|
|
|
end if; |
|
|
|
key9 := pc2( ( c9 & d9 ) ); |
|
|
|
l9 := r8; |
|
|
|
r9 := l8 xor ( f( r8, key9 ) ); |
|
|
|
-- 8. stage |
|
|
|
IF mode(8) = '0' THEN |
|
|
|
c8 := c7(2 TO 27) & c7(0 TO 1); |
|
|
|
d8 := d7(2 TO 27) & d7(0 TO 1); |
|
|
|
ELSE |
|
|
|
c8 := c7(26 TO 27) & c7(0 TO 25); |
|
|
|
d8 := d7(26 TO 27) & d7(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(8) = '0' then |
|
|
|
c8 := c7(2 to 27) & c7(0 to 1); |
|
|
|
d8 := d7(2 to 27) & d7(0 to 1); |
|
|
|
else |
|
|
|
c8 := c7(26 to 27) & c7(0 to 25); |
|
|
|
d8 := d7(26 to 27) & d7(0 to 25); |
|
|
|
end if; |
|
|
|
key8 := pc2( ( c8 & d8 ) ); |
|
|
|
l8 := r7; |
|
|
|
r8 := l7 xor ( f( r7, key8 ) ); |
|
|
|
-- 7. stage |
|
|
|
IF mode(7) = '0' THEN |
|
|
|
c7 := c6(2 TO 27) & c6(0 TO 1); |
|
|
|
d7 := d6(2 TO 27) & d6(0 TO 1); |
|
|
|
ELSE |
|
|
|
c7 := c6(26 TO 27) & c6(0 TO 25); |
|
|
|
d7 := d6(26 TO 27) & d6(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(7) = '0' then |
|
|
|
c7 := c6(2 to 27) & c6(0 to 1); |
|
|
|
d7 := d6(2 to 27) & d6(0 to 1); |
|
|
|
else |
|
|
|
c7 := c6(26 to 27) & c6(0 to 25); |
|
|
|
d7 := d6(26 to 27) & d6(0 to 25); |
|
|
|
end if; |
|
|
|
key7 := pc2( ( c7 & d7 ) ); |
|
|
|
l7 := r6; |
|
|
|
r7 := l6 xor ( f( r6, key7 ) ); |
|
|
|
-- 6. stage |
|
|
|
IF mode(6) = '0' THEN |
|
|
|
c6 := c5(2 TO 27) & c5(0 TO 1); |
|
|
|
d6 := d5(2 TO 27) & d5(0 TO 1); |
|
|
|
ELSE |
|
|
|
c6 := c5(26 TO 27) & c5(0 TO 25); |
|
|
|
d6 := d5(26 TO 27) & d5(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(6) = '0' then |
|
|
|
c6 := c5(2 to 27) & c5(0 to 1); |
|
|
|
d6 := d5(2 to 27) & d5(0 to 1); |
|
|
|
else |
|
|
|
c6 := c5(26 to 27) & c5(0 to 25); |
|
|
|
d6 := d5(26 to 27) & d5(0 to 25); |
|
|
|
end if; |
|
|
|
key6 := pc2( ( c6 & d6 ) ); |
|
|
|
l6 := r5; |
|
|
|
r6 := l5 xor ( f( r5, key6 ) ); |
|
|
|
-- 5. stage |
|
|
|
IF mode(5) = '0' THEN |
|
|
|
c5 := c4(2 TO 27) & c4(0 TO 1); |
|
|
|
d5 := d4(2 TO 27) & d4(0 TO 1); |
|
|
|
ELSE |
|
|
|
c5 := c4(26 TO 27) & c4(0 TO 25); |
|
|
|
d5 := d4(26 TO 27) & d4(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(5) = '0' then |
|
|
|
c5 := c4(2 to 27) & c4(0 to 1); |
|
|
|
d5 := d4(2 to 27) & d4(0 to 1); |
|
|
|
else |
|
|
|
c5 := c4(26 to 27) & c4(0 to 25); |
|
|
|
d5 := d4(26 to 27) & d4(0 to 25); |
|
|
|
end if; |
|
|
|
key5 := pc2( ( c5 & d5 ) ); |
|
|
|
l5 := r4; |
|
|
|
r5 := l4 xor ( f( r4, key5 ) ); |
|
|
|
-- 4. stage |
|
|
|
IF mode(4) = '0' THEN |
|
|
|
c4 := c3(2 TO 27) & c3(0 TO 1); |
|
|
|
d4 := d3(2 TO 27) & d3(0 TO 1); |
|
|
|
ELSE |
|
|
|
c4 := c3(26 TO 27) & c3(0 TO 25); |
|
|
|
d4 := d3(26 TO 27) & d3(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(4) = '0' then |
|
|
|
c4 := c3(2 to 27) & c3(0 to 1); |
|
|
|
d4 := d3(2 to 27) & d3(0 to 1); |
|
|
|
else |
|
|
|
c4 := c3(26 to 27) & c3(0 to 25); |
|
|
|
d4 := d3(26 to 27) & d3(0 to 25); |
|
|
|
end if; |
|
|
|
key4 := pc2( ( c4 & d4 ) ); |
|
|
|
l4 := r3; |
|
|
|
r4 := l3 xor ( f( r3, key4 ) ); |
|
|
|
-- 3. stage |
|
|
|
IF mode(3) = '0' THEN |
|
|
|
c3 := c2(2 TO 27) & c2(0 TO 1); |
|
|
|
d3 := d2(2 TO 27) & d2(0 TO 1); |
|
|
|
ELSE |
|
|
|
c3 := c2(26 TO 27) & c2(0 TO 25); |
|
|
|
d3 := d2(26 TO 27) & d2(0 TO 25); |
|
|
|
END IF; |
|
|
|
if mode(3) = '0' then |
|
|
|
c3 := c2(2 to 27) & c2(0 to 1); |
|
|
|
d3 := d2(2 to 27) & d2(0 to 1); |
|
|
|
else |
|
|
|
c3 := c2(26 to 27) & c2(0 to 25); |
|
|
|
d3 := d2(26 to 27) & d2(0 to 25); |
|
|
|
end if; |
|
|
|
key3 := pc2( ( c3 & d3 ) ); |
|
|
|
l3 := r2; |
|
|
|
r3 := l2 xor ( f( r2, key3 ) ); |
|
|
|
-- 2. stage |
|
|
|
IF mode(2) = '0' THEN |
|
|
|
c2 := c1(1 TO 27) & c1(0); |
|
|
|
d2 := d1(1 TO 27) & d1(0); |
|
|
|
ELSE |
|
|
|
c2 := c1(27) & c1(0 TO 26); |
|
|
|
d2 := d1(27) & d1(0 TO 26); |
|
|
|
END IF; |
|
|
|
if mode(2) = '0' then |
|
|
|
c2 := c1(1 to 27) & c1(0); |
|
|
|
d2 := d1(1 to 27) & d1(0); |
|
|
|
else |
|
|
|
c2 := c1(27) & c1(0 to 26); |
|
|
|
d2 := d1(27) & d1(0 to 26); |
|
|
|
end if; |
|
|
|
key2 := pc2( ( c2 & d2 ) ); |
|
|
|
l2 := r1; |
|
|
|
r2 := l1 xor ( f( r1, key2 ) ); |
|
|
|
-- 1. stage |
|
|
|
IF mode(1) = '0' THEN |
|
|
|
c1 := c0(1 TO 27) & c0(0); |
|
|
|
d1 := d0(1 TO 27) & d0(0); |
|
|
|
ELSE |
|
|
|
if mode(1) = '0' then |
|
|
|
c1 := c0(1 to 27) & c0(0); |
|
|
|
d1 := d0(1 to 27) & d0(0); |
|
|
|
else |
|
|
|
c1 := c0; |
|
|
|
d1 := d0; |
|
|
|
END IF; |
|
|
|
end if; |
|
|
|
key1 := pc2( ( c1 & d1 ) ); |
|
|
|
l1 := r0; |
|
|
|
r1 := l0 xor ( f( r0, key1 ) ); |
|
|
|
-- input stage |
|
|
|
l0 := ip( data_i )(0 TO 31); |
|
|
|
r0 := ip( data_i )(32 TO 63); |
|
|
|
l0 := ip( data_i )(0 to 31); |
|
|
|
r0 := ip( data_i )(32 to 63); |
|
|
|
c0 := pc1_c( key_i ); |
|
|
|
d0 := pc1_d( key_i ); |
|
|
|
END IF; |
|
|
|
END PROCESS crypt; |
|
|
|
end if; |
|
|
|
end process crypt; |
|
|
|
|
|
|
|
end generate PipeG; |
|
|
|
|
|
|
@ -358,7 +358,6 @@ begin |
|
|
|
|
|
|
|
begin |
|
|
|
|
|
|
|
|
|
|
|
cryptP : process (clk_i, reset_i) is |
|
|
|
variable v_c : std_logic_vector(0 to 27); |
|
|
|
variable v_d : std_logic_vector(0 to 27); |
|
|
@ -624,5 +623,4 @@ begin |
|
|
|
end generate AreaG; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
END ARCHITECTURE rtl; |
|
|
|
end architecture rtl; |