📄 key_expansion.vhdl
字号:
--------------------------------------------------------------------------------
-- Organization: www.opendsp.pl
-- Engineer: Jerzy Gbur
--
-- Create Date: 2006-05-13
-- Design Name: aes
-- Module Name: key_expansion
-- Project Name: aes
-- Target Device:
-- Tool versions:
-- Description:
-- KEY_SIZE: 0 - 128
-- 1 - 192
-- 2 - 256
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
--------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
library WORK;
use WORK.aes_pkg.ALL;
entity key_expansion is
generic (
KEY_SIZE : in integer range 0 to 2 := 2
);
port
(
KEY_I : in std_logic_vector(7 downto 0);
VALID_KEY_I : in std_logic;
CLK_I : in std_logic;
RESET_I : in std_logic;
CE_I : in std_logic;
DONE_O : out std_logic;
GET_KEY_I : in std_logic;
KEY_NUMB_I : in std_logic_vector(5 downto 0);
KEY_EXP_O : out std_logic_vector(31 downto 0)
);
end key_expansion;
architecture Behavioral of key_expansion is
type type_ROUND_TABLE is array (0 to 63) of std_logic_vector(31 downto 0);
signal KEY_EXPAN0 : type_ROUND_TABLE;
signal t_FORWARD_TABLE : type_SBOX;
signal v_KEY32_IN : std_logic_vector(31 downto 0);
signal i_ROUND : integer range 0 to 13;
signal i_BYTE_CNTR4 : integer range 0 to 3;
signal FF_VALID_KEY : std_logic;
signal v_KEY_COL_IN0 : std_logic_vector(31 downto 0);
signal v_KEY_COL_OUT0 : std_logic_vector(31 downto 0);
signal v_TEMP_VECTOR : std_logic_vector(31 downto 0);
signal i_FRW_ADD_RD0 : integer range 0 to 255;
signal v_SUB_WORD : std_logic_vector(7 downto 0);
signal SRAM_WREN0 : std_logic;
signal i_SRAM_ADDR_WR0 : integer range 0 to 63;
signal i_SRAM_ADDR_RD0 : integer range 0 to 63;
signal i_EXTERN_ADDRESS : integer range 0 to 63;
signal i_INTERN_ADDR_RD0 : integer range 0 to 63;
signal v_CALCULATION_CNTR : std_logic_vector(7 downto 0);
signal START_CALCULATION : std_logic;
signal CALCULATION : std_logic;
signal FF_GET_KEY : std_logic;
begin
t_FORWARD_TABLE <= c_SBOX_FRV;
--****************************************************************************--
--* Packetization for 32bit words from input *--
--****************************************************************************--
P0000:
process(CLK_I)
begin
if rising_edge(CLK_I) then
if CE_I = '1' then
FF_VALID_KEY <= VALID_KEY_I;
if VALID_KEY_I = '0' then
i_BYTE_CNTR4 <= 0;
elsif VALID_KEY_I = '1' then
if i_BYTE_CNTR4 = 0 then
v_KEY32_IN(7 downto 0) <= KEY_I;
elsif i_BYTE_CNTR4 = 1 then
v_KEY32_IN(15 downto 8) <= KEY_I;
elsif i_BYTE_CNTR4 = 2 then
v_KEY32_IN(23 downto 16) <= KEY_I;
elsif i_BYTE_CNTR4 = 3 then
v_KEY32_IN(31 downto 24) <= KEY_I;
end if;
if i_BYTE_CNTR4 = 3 then
i_BYTE_CNTR4 <= 0;
else
i_BYTE_CNTR4 <= i_BYTE_CNTR4 + 1;
end if;
end if;
end if;
end if;
end process;
--****************************************************************************--
--* RAM for Key Expansion *--
--****************************************************************************--
SRAM0:
process(CLK_I)
begin
if rising_edge(CLK_I) then
if RESET_I = '1' then
SRAM_WREN0 <= '0';
elsif CE_I = '1' then
if VALID_KEY_I = '1' and i_BYTE_CNTR4 = 3 then
SRAM_WREN0 <= '1';
elsif v_CALCULATION_CNTR = x"08" then
SRAM_WREN0 <= '1';
elsif v_CALCULATION_CNTR = x"09" then
SRAM_WREN0 <= '1';
elsif v_CALCULATION_CNTR = x"0A" then
SRAM_WREN0 <= '1';
elsif v_CALCULATION_CNTR = x"0B" then
SRAM_WREN0 <= '1';
elsif KEY_SIZE = 1 then
if v_CALCULATION_CNTR = x"0C" then
SRAM_WREN0 <= '1';
elsif v_CALCULATION_CNTR = x"0D" then
SRAM_WREN0 <= '1';
else
SRAM_WREN0 <= '0';
end if;
elsif KEY_SIZE = 2 then
if v_CALCULATION_CNTR = x"11" then
SRAM_WREN0 <= '1';
elsif v_CALCULATION_CNTR = x"12" then
SRAM_WREN0 <= '1';
elsif v_CALCULATION_CNTR = x"13" then
SRAM_WREN0 <= '1';
elsif v_CALCULATION_CNTR = x"14" then
SRAM_WREN0 <= '1';
else
SRAM_WREN0 <= '0';
end if;
else
SRAM_WREN0 <= '0';
end if;
end if;
-- RAM
if CE_I = '1' then
if SRAM_WREN0 = '1' then
KEY_EXPAN0(i_SRAM_ADDR_WR0) <= v_KEY_COL_IN0;
end if;
v_KEY_COL_OUT0 <= KEY_EXPAN0(i_SRAM_ADDR_RD0);
end if;
-- Write address
if RESET_I = '1' then
i_SRAM_ADDR_WR0 <= 0;
elsif CE_I = '1' then
if FF_VALID_KEY = '0' and VALID_KEY_I = '1' then
i_SRAM_ADDR_WR0 <= 0;
elsif SRAM_WREN0 = '1' then
i_SRAM_ADDR_WR0 <= i_SRAM_ADDR_WR0 + 1;
end if;
end if;
-- Read address
if RESET_I = '1' then
i_INTERN_ADDR_RD0 <= 0;
elsif CE_I = '1' then
if FF_VALID_KEY = '0' and VALID_KEY_I = '1' then
i_INTERN_ADDR_RD0 <= 0;
elsif v_CALCULATION_CNTR = x"07" then
i_INTERN_ADDR_RD0 <= i_INTERN_ADDR_RD0 + 1;
elsif v_CALCULATION_CNTR = x"08" then
i_INTERN_ADDR_RD0 <= i_INTERN_ADDR_RD0 + 1;
elsif v_CALCULATION_CNTR = x"09" then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -