Altera_Forum
Honored Contributor
14 years agoHelp!:Error (10327)
Hello there everyone, i'm currently trying to implement XTEA in VHDL using the C code from http://en.wikipedia.org/wiki/xtea. The following is my VHDL code:
Library IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_unsigned.all;
USE IEEE.std_logic_arith.all;
use ieee.numeric_std.all;
entity XTEA is
Port (
clk:in std_logic;
input: in std_logic_vector(63 downto 0);
key : in std_logic_vector(127 downto 0);
Encoder_output,Decoder_output: out std_logic_vector(63 downto 0)
);
end entity;
architecture rtl of XTEA is
signal k: std_logic_vector(0 to 3);
signal n:integer:=0;
begin
process(clk,input)
variable z,z_up,z_mid,z_down,z_total,y,y_up,y_mid,y_down,y_total: std_logic_vector (31 downto 0);
variable sum: std_logic_vector (31 downto 0) := x"00000000";
variable delta: std_logic_vector (31 downto 0) := x"9e3779b9";
variable test: std_logic_vector (31 downto 0);
variable natvar : natural;
begin
--divide the key into 4 parts
k(0 downto 0)<=key(127 downto 96);
k(1 downto 1)<=key(95 downto 64);
k(2 downto 2)<=key(63 downto 32);
k(3 downto 3)<=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"3";
natvar := conv_integer(unsigned(test));
z_total:=(((z(27 downto 0)&"0000") XOR ("00000"&z(31 downto 5)))+z) XOR( sum + k( test downto test ) );
y:=y+z_total;
sum:=sum+delta;
y_total:=(((y(27 downto 0)&"0000") XOR ("00000"&y(31 downto 5)))+y) XOR (sum+ k( test downto test ) );
z:=z+y_total;
Encoder_output<=y&z;
--decode
elsif(n<64) then
if(n=32) then
sum:=delta*32;
end if;
y_total:=(((y(27 downto 0)&"0000") XOR ("00000"&y(31 downto 5)))+y) XOR (sum+ k(sum(31 downto 11) & 3));
z:=z-y_total;
sum:=sum-delta;
z_total:=(((z(27 downto 0)&"0000") XOR ("00000"&z(31 downto 5)))+z) XOR(sum + k(sum & 3));
y:=y+z_total;
Decoder_output<=y&z;
end if;
n<=n+1; --counter
end if;
end process;
end rtl;
The problems are bolded. What i'm trying to do is to randomly select one of the 4 parts of key: (the full length of key is 128 bits divided into four 32 bits key, k0,k1,k2,k3). Using the "sum & 3", we can randomly select k0, k1, k2 and k3...i'm a total beginner and i think i have totally violated the type from hexadecimal and natural conversion issue which is used in the std_logic_vector((sum & 3) downto (sum & 3)). is there anyway to solve this?i'm seeing the error: error (10327): vhdl error at xtea.vhd(48): can't determine definition of operator ""and"" -- found 0 possible definitions if i were to do k( (sum and 3) downto (sum and 3) ) instead of k( test downto test ) which is what i want...any experts please do help! Thanx for helping in advance!:)