📄 dec.vhd.bak
字号:
LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY rc5_dnc IS PORT ( clk,clr : IN STD_LOGIC; din : IN STD_LOGIC_VECTOR(63 DOWNTO 0); dout : OUT STD_LOGIC_VECTOR(63 DOWNTO 0); di_vld: IN STD_LOGIC; do_rdy: OUT STD_LOGIC );END rc5_dnc;ARCHITECTURE do OF rc5_dnc IS SIGNAL i_cnt : STD_LOGIC_VECTOR(3 DOWNTO 0); -- round counter SIGNAL a_rot : STD_LOGIC_VECTOR(31 DOWNTO 0);-- right rotate by b SIGNAL a : STD_LOGIC_VECTOR(31 DOWNTO 0);-- the input a SIGNAL a_reg : STD_LOGIC_VECTOR(31 DOWNTO 0); -- register a SIGNAL a_pre : STD_LOGIC_VECTOR(31 DOWNTO 0); -- register a pre SIGNAL b_rot : STD_LOGIC_VECTOR(31 DOWNTO 0);-- right rotate by a SIGNAL b : STD_LOGIC_VECTOR(31 DOWNTO 0);--the input b SIGNAL b_reg : STD_LOGIC_VECTOR(31 DOWNTO 0); -- register a SIGNAL b_pre : STD_LOGIC_VECTOR(31 DOWNTO 0); -- register b pre SIGNAL b_temp : STD_LOGIC_VECTOR(31 DOWNTO 0); SIGNAL a_temp : STD_LOGIC_VECTOR(31 DOWNTO 0); TYPE rom IS ARRAY (0 TO 25) OF STD_LOGIC_VECTOR(31 DOWNTO 0); CONSTANT skey : rom:=rom'(X"9BBBD8C8", X"1A37F7FB", X"46F8E8C5",X"460C6085",X"70F83B8A",X"284B8303",X"513E1454",X"F621ED22",X"3125065D",X"11A83A5D",X"D427686B",X"713AD82D",X"4B792F99",X"2799A4DD",X"A7901C49",X"DEDE871A",X"36C03196",X"A7EFC249",X"61A78BB8",X"3B0A1D2B",X"4DBFCA76",X"AE162167",X"30D76B0A",X"43192304",X"F6CC1431",X"65046380"); -- assign the values for S[0]~ S[25] although we only need to use s[2]~S[12] --states TYPE StateType IS (ST_IDLE, ST_PRE_ROUND, ST_ROUND_OP, ST_READY ); SIGNAL state : StateType;BEGIN -- B= ((B-S[2*i]>>>A)) XOR A b_temp<= b_reg-skey(CONV_INTEGER(i_cnt & '1')); WITH a_reg(4 DOWNTO 0) SELECT b_rot<=b_temp(0) & b_temp(31 DOWNTO 1) WHEN "00001", b_temp(1 DOWNTO 0) & b_temp(31 DOWNTO 2) WHEN "00010", b_temp(2 DOWNTO 0) & b_temp(31 DOWNTO 3) WHEN "00011", b_temp(3 DOWNTO 0) & b_temp(31 DOWNTO 4) WHEN "00100", b_temp(4 DOWNTO 0) & b_temp(31 DOWNTO 5) WHEN "00101", b_temp(5 DOWNTO 0) & b_temp(31 DOWNTO 6) WHEN "00110", b_temp(6 DOWNTO 0) & b_temp(31 DOWNTO 7) WHEN "00111", b_temp(7 DOWNTO 0) & b_temp(31 DOWNTO 8) WHEN "01000", b_temp(8 DOWNTO 0) & b_temp(31 DOWNTO 9) WHEN "01001", b_temp(9 DOWNTO 0) & b_temp(31 DOWNTO 10) WHEN "01010", b_temp(10 DOWNTO 0) & b_temp(31 DOWNTO 11) WHEN "01011", b_temp(11 DOWNTO 0) & b_temp(31 DOWNTO 12) WHEN "01100", b_temp(12 DOWNTO 0) & b_temp(31 DOWNTO 13) WHEN "01101", b_temp(13 DOWNTO 0) & b_temp(31 DOWNTO 14) WHEN "01110", b_temp(14 DOWNTO 0) & b_temp(31 DOWNTO 15) WHEN "01111", b_temp(15 DOWNTO 0) & b_temp(31 DOWNTO 16) WHEN "10000", b_temp(16 DOWNTO 0) & b_temp(31 DOWNTO 17) WHEN "10001", b_temp(17 DOWNTO 0) & b_temp(31 DOWNTO 18) WHEN "10010", b_temp(18 DOWNTO 0) & b_temp(31 DOWNTO 19) WHEN "10011", b_temp(19 DOWNTO 0) & b_temp(31 DOWNTO 20) WHEN "10100", b_temp(20 DOWNTO 0) & b_temp(31 DOWNTO 21) WHEN "10101", b_temp(21 DOWNTO 0) & b_temp(31 DOWNTO 22) WHEN "10110", b_temp(22 DOWNTO 0) & b_temp(31 DOWNTO 23) WHEN "10111", b_temp(23 DOWNTO 0) & b_temp(31 DOWNTO 24) WHEN "11000", b_temp(24 DOWNTO 0) & b_temp(31 DOWNTO 25) WHEN "11001", b_temp(25 DOWNTO 0) & b_temp(31 DOWNTO 26) WHEN "11010", b_temp(26 DOWNTO 0) & b_temp(31 DOWNTO 27) WHEN "11011", b_temp(27 DOWNTO 0) & b_temp(31 DOWNTO 28) WHEN "11100", b_temp(28 DOWNTO 0) & b_temp(31 DOWNTO 29) WHEN "11101", b_temp(29 DOWNTO 0) & b_temp(31 DOWNTO 30) WHEN "11110", b_temp(30 DOWNTO 0) & b_temp(31) WHEN "11111", b_temp WHEN OTHERS; b <= b_rot XOR a_reg; b_pre<=b-skey(1); -- A = ((A - S[2譱]) >>> B) xor B; a_temp<= a_reg-skey(CONV_INTEGER(i_cnt & '0')); WITH b(4 DOWNTO 0) SELECT a_rot<=a_temp(0) & a_temp(31 DOWNTO 1) WHEN "00001", a_temp(1 DOWNTO 0) & a_temp(31 DOWNTO 2) WHEN "00010", a_temp(2 DOWNTO 0) & a_temp(31 DOWNTO 3) WHEN "00011", a_temp(3 DOWNTO 0) & a_temp(31 DOWNTO 4) WHEN "00100", a_temp(4 DOWNTO 0) & a_temp(31 DOWNTO 5) WHEN "00101", a_temp(5 DOWNTO 0) & a_temp(31 DOWNTO 6) WHEN "00110", a_temp(6 DOWNTO 0) & a_temp(31 DOWNTO 7) WHEN "00111", a_temp(7 DOWNTO 0) & a_temp(31 DOWNTO 8) WHEN "01000", a_temp(8 DOWNTO 0) & a_temp(31 DOWNTO 9) WHEN "01001", a_temp(9 DOWNTO 0) & a_temp(31 DOWNTO 10) WHEN "01010", a_temp(10 DOWNTO 0) & a_temp(31 DOWNTO 11) WHEN "01011", a_temp(11 DOWNTO 0) & a_temp(31 DOWNTO 12) WHEN "01100", a_temp(12 DOWNTO 0) & a_temp(31 DOWNTO 13) WHEN "01101", a_temp(13 DOWNTO 0) & a_temp(31 DOWNTO 14) WHEN "01110", a_temp(14 DOWNTO 0) & a_temp(31 DOWNTO 15) WHEN "01111", a_temp(15 DOWNTO 0) & a_temp(31 DOWNTO 16) WHEN "10000", a_temp(16 DOWNTO 0) & a_temp(31 DOWNTO 17) WHEN "10001", a_temp(17 DOWNTO 0) & a_temp(31 DOWNTO 18) WHEN "10010", a_temp(18 DOWNTO 0) & a_temp(31 DOWNTO 19) WHEN "10011", a_temp(19 DOWNTO 0) & a_temp(31 DOWNTO 20) WHEN "10100", a_temp(20 DOWNTO 0) & a_temp(31 DOWNTO 21) WHEN "10101", a_temp(21 DOWNTO 0) & a_temp(31 DOWNTO 22) WHEN "10110", a_temp(22 DOWNTO 0) & a_temp(31 DOWNTO 23) WHEN "10111", a_temp(23 DOWNTO 0) & a_temp(31 DOWNTO 24) WHEN "11000", a_temp(24 DOWNTO 0) & a_temp(31 DOWNTO 25) WHEN "11001", a_temp(25 DOWNTO 0) & a_temp(31 DOWNTO 26) WHEN "11010", a_temp(26 DOWNTO 0) & a_temp(31 DOWNTO 27) WHEN "11011", a_temp(27 DOWNTO 0) & a_temp(31 DOWNTO 28) WHEN "11100", a_temp(28 DOWNTO 0) & a_temp(31 DOWNTO 29) WHEN "11101", a_temp(29 DOWNTO 0) & a_temp(31 DOWNTO 30) WHEN "11110", a_temp(30 DOWNTO 0) & a_temp(31) WHEN "11111", a_temp WHEN OTHERS; a <= a_rot XOR b; a_pre<= a-skey(0); -- B register PROCESS(clr, clk) BEGIN IF(clr='0') THEN b_reg<= din(31 downto 0); ELSIF(clk'EVENT AND clk='1') THEN IF(state=ST_PRE_ROUND) THEN b_reg<=b_pre; ELSIF(state=ST_ROUND_OP) THEN b_reg<=b; END IF; END IF; END PROCESS; -- A register PROCESS(clr, clk) BEGIN IF(clr='0') THEN a_reg<=din(63 downto 32); ELSIF(clk'EVENT AND clk='1') THEN IF(state=ST_PRE_ROUND) THEN a_reg<=a_pre; ELSIF(state=ST_ROUND_OP) THEN a_reg<=a; END IF; END IF; END PROCESS; -- round counter PROCESS(clr, clk) BEGIN IF(clr='0') THEN i_cnt<="1100"; ELSIF(clk'EVENT AND clk='1') THEN IF(state= ST_ROUND_OP) THEN IF(i_cnt="0001") THEN i_cnt<="1100"; ELSE i_cnt<=i_cnt-'1'; END IF; END IF; END IF; END PROCESS;PROCESS(clr, clk)BEGIN IF(clr='0') THEN state<=ST_IDLE; ELSIF(clk'EVENT AND clk='1') THEN CASE state IS WHEN ST_IDLE=> IF(di_vld='1') THEN state<=ST_ROUND_OP; END IF; WHEN ST_ROUND_OP=>IF(i_cnt="0010") THEN state<=ST_PRE_ROUND; END IF; WHEN ST_PRE_ROUND=>state<=ST_READY; WHEN ST_READY=>state<=ST_IDLE; END CASE; END IF; END PROCESS; dout<=a_reg&b_reg; WITH state SELECT do_rdy<= '1' WHEN ST_READY, '0' WHEN OTHERS;END do;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -