Forum Discussion
Altera_Forum
Honored Contributor
14 years agohi again kaz, thanx for your previous reply...i tried to pipeline the bottleneck using the following code, but it doesn't give me the correct results even after i perform pipeline balancing:
Library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity TEA_en is
port(
clock: in std_logic; --clock input
input_data: in std_logic_vector (63 downto 0); --input data
key : in std_logic_vector (127 downto 0); --secret key 127 downto 0--
encrypted_data: out std_logic_vector (63 downto 0) --output/encrypted data
);
end entity TEA_en;
architecture behave of TEA_en is
--declare signals
signal Key0, Key1, Key2, Key3 : std_logic_vector (31 downto 0);
signal Z, Y : std_logic_vector (31 downto 0);
signal count :integer range 0 to 32:=0; --constrained counter (counts from 0 to 32) improves throughput by 1 ns!
signal pipeline_0,pipeline_1,pipeline_2,pipeline_3,pipeline_4,pipeline_5,pipeline_6,pipeline_7:std_logic_vector(31 downto 0);
begin
--separate key into four parts
Key0<=key(127 downto 96);
Key1<=key(95 downto 64);
Key2<=key(63 downto 32);
Key3<=key(31 downto 0);
Process(Input_data, clock)
--declare and initialize variable
Variable delta: std_logic_vector (31 downto 0):=x"9e3779b9";
Variable sum: std_logic_vector (31 downto 0):=x"00000000";
Variable Zeq,Yeq,Z,Y: std_logic_vector (31 downto 0);
Begin
If(rising_edge(clock)) then
If (count<1) then --separate input data into two parts
Z:=input_data(63 downto 32); --part 1 (32bits)
Y:=input_data(31 downto 0); --part 2 (32bits)
Else --null;
End if;
If (count<32) then
--Encryption routine algorithms
sum:=sum+delta;
for i in 1 to 8 loop
case i is
when 1=> pipeline_0 <=( (Z(27 downto 0) & "0000")+Key0);
when 2=> pipeline_1 <=(Z+ sum) ;
when 3=> pipeline_2 <=(("00000" & Z(31 downto 5))+Key1);
when 4=> pipeline_3 <=( (Y(27 downto 0) & "0000")+Key2) ;
when 5=> pipeline_4 <=(Y+ sum) ;
when 6=> pipeline_5 <=(("00000" & Y(31 downto 5))+Key3) ;
when 7=> pipeline_6 <=pipeline_0 xor pipeline_1 xor pipeline_2;
when 8=> pipeline_7 <=pipeline_3 xor pipeline_4 xor pipeline_5;
when others=> null;
end case;
end loop;
Y:=Y+pipeline_6;
Z:=Z+pipeline_7;
--Output encrypted data
Encrypted_data<=Y&Z;
else null;
end if;
count<=count+1; --increase value of count
End if;
End process;
end architecture behave;
anything i did wrong in the process? many thanx again for the help!^^