Forum Discussion
Altera_Forum
Honored Contributor
14 years agohi dave, thank you so much for the informative reply! actually i'm trying to implement XTEA:http://en.wikipedia.org/wiki/xtea
The following is the VHDL code i'm working on:
Library IEEE;
USE IEEE.std_logic_1164.all;
use ieee.numeric_std.all;
entity XTEA is
Port (
clk:in std_logic;
input: in unsigned(63 downto 0);
key : in unsigned(127 downto 0);
Encoder_output,Decoder_output: out unsigned(63 downto 0)
);
end entity;
architecture rtl of XTEA is
signal k0,k1,k2,k3: unsigned(31 downto 0);
signal n:integer:=0;
signal key_array: unsigned (3 downto 0);
type key_t is array (0 to 3) of unsigned(31 downto 0);
signal k : key_t;
begin
process(clk,input)
variable z,z_up,z_mid,z_down,z_total,y,y_up,y_mid,y_down,y_total: unsigned (31 downto 0);
variable sum: unsigned (31 downto 0) := x"00000000";
variable delta: unsigned (31 downto 0) := x"9e3779b9";
variable test,test1,test2,test3 : unsigned (31 downto 0);
variable natvar,natvar1,natvar2,natvar3 : integer;
begin
--divide the key into 4 parts
k(3)<=key(127 downto 96);
k(2)<=key(95 downto 64);
k(1)<=key(63 downto 32);
k(0)<=key(31 downto 0);
if(rising_edge(clk)) then
if (n=0) then
--divide input into y and z
y:= input(63 downto 32);
z:= input (31 downto 0);
--sum:=x"00000000"; -- try take this out later
elsif (n=32) then
--for decode:delta is delta*2^5 for 32=(2^5) round
sum:=delta(26 downto 0)&"00000";
end if;
--encode
if (n <32) then
test:=sum and x"00000003";
test1:="00000000000" & sum(31 downto 11); --shift by 11 bits to the right
natvar:=to_integer(test);
natvar1:=to_integer(test1);
z_total:=(((z(27 downto 0)&"0000") XOR ("00000"&z(31 downto 5)))+z) XOR( sum + k( natvar downto natvar ) );
y:=y+z_total;
sum:=sum+delta;
y_total:=(((y(27 downto 0)&"0000") XOR ("00000"&y(31 downto 5)))+y) XOR (sum+ k(natvar1 downto natvar1 ) );
z:=z+y_total;
Encoder_output<=y&z;
--decode
elsif(n<64) then
if(n=32) then
sum:=delta*32;
end if;
test2:=sum and x"00000003";
test3:="00000000000" & sum(31 downto 11); --shift by 11 bits to the right
natvar2:=to_integer(test2);
natvar3:=to_integer(test3);
test1:=sum and x"00000003";
natvar1:=to_integer(test1);
y_total:=(((y(27 downto 0)&"0000") XOR ("00000"&y(31 downto 5)))+y) XOR (sum+ k(natvar3 downto natvar3));
z:=z-y_total;
sum:=sum-delta;
z_total:=(((z(27 downto 0)&"0000") XOR ("00000"&z(31 downto 5)))+z) XOR(sum + k(natvar2 downto natvar2));
y:=y+z_total;
Decoder_output<=y&z;
end if;
n<=n+1; --counter
end if;
end process;
end rtl;
Using the method you suggested, i encountered some problems: Error (10327): VHDL error at XTEA.vhd(59): can't determine definition of operator ""+"" -- found 0 possible definitions The problem lines are bolded...apparently my array (named k(0 to 3)) has the type of key_t but other operations are done in unsigned type. i tried converting k() to unsigned using "unsigned(k())" but to no avail. is there anyway to go about this? Than a lot for the great help again! have a nice day ahead!:)