OpenCores
URL https://opencores.org/ocsvn/aes_all_keylength/aes_all_keylength/trunk

Subversion Repositories aes_all_keylength

[/] [aes_all_keylength/] [trunk/] [keyExpansion.vhd] - Diff between revs 3 and 6

Show entire file | Details | Blame | View Log

Rev 3 Rev 6
Line 19... Line 19...
   signal temp, rotW0, subIn, subRotW0 : std_logic_vector(31 downto 0);
   signal temp, rotW0, subIn, subRotW0 : std_logic_vector(31 downto 0);
   type wT is array(0 to 7) of std_logic_vector(31 downto 0);
   type wT is array(0 to 7) of std_logic_vector(31 downto 0);
   signal w : wT;
   signal w : wT;
   type RconT is array(0 to 10) of std_logic_vector(7 downto 0);
   type RconT is array(0 to 10) of std_logic_vector(7 downto 0);
   constant Rcon : RconT := (x"01",x"02",x"04",x"08",x"10",x"20",x"40",x"80",x"1b",x"36",x"ee");
   constant Rcon : RconT := (x"01",x"02",x"04",x"08",x"10",x"20",x"40",x"80",x"1b",x"36",x"ee");
   signal iModNk, Nk, RconCnt : std_logic_vector(3 downto 0);
        signal iModNk, Nk : integer range 0 to 7;
 
        signal RconCnt : integer range 0 to 10;
   signal roundCounter : std_Logic_vector(5 downto 0);
   signal roundCounter : std_Logic_vector(5 downto 0);
begin
begin
 
 
keyExpansionFSM: process(clock)
keyExpansionFSM: process(clock)
begin
begin
   if rising_edge(clock) then
   if rising_edge(clock) then
      if reset = '1' then
      if reset = '1' then
         Nk <= x"0";
         Nk <= 0;
         iModNk <= x"0";
         iModNk <= 0;
         RoundCounter <= "000000";
         RoundCounter <= "000000";
         RconCnt <= x"0";
         RconCnt <= 0;
      elsif loadKey = '1' then
      elsif loadKey = '1' then
         Nk <= Nk + '1';
         Nk <= Nk + 1;
      elsif not keyExpansionReady = '1' then
      elsif keyExpansionReady = '0' then
         roundCounter <= roundCounter + '1';
         roundCounter <= roundCounter + '1';
         if iModNk = Nk then
         if iModNk = Nk then
            iModNk <= x"0";
            iModNk <= 0;
            RconCnt <= RconCnt + '1';
            if RconCnt < 10 then
 
                                        RconCnt <= RconCnt + 1;
 
                                end if;
         else
         else
            iModNk <= iModNk + '1';
            iModNk <= iModNk + 1;
         end if;
         end if;
      end if;
      end if;
   end if;
   end if;
end process;
end process;
--begin keyExpansionFSM asynchron circuitry
--begin keyExpansionFSM asynchron circuitry
keyExpansionReady <= '1' when Nk = x"3" and roundCounter = "101000" else --44=32+8+4
keyExpansionReady <= '1' when Nk = 3 and roundCounter = "101000" else --44=32+8+4
                     '1' when Nk = x"5" and roundCounter = "110000" else --52=32+16+4
                     '1' when Nk = 5 and roundCounter = "110000" else --52=32+16+4
                     '1' when Nk = x"7" and roundCounter = "111000" else --60=32+16+8+4
                     '1' when Nk = 7 and roundCounter = "111000" else --60=32+16+8+4
                     '0';
                     '0';
numberOfRounds <= Nk + x"7";
numberOfRounds <= x"a" when Nk = 3 else
                  --x"9" when Nk = x"3" else
                  x"c" when Nk = 5 else
                  --x"b" when Nk = x"5" else
                  x"e" when Nk = 7 else x"0";
                  --x"d" when Nk = x"7" else x"0";
 
--end keyExpansionFSM asynchron circuitry
--end keyExpansionFSM asynchron circuitry
 
 
keyExpansionPipe: process(clock)
keyExpansionPipe: process(clock)
begin
begin
   if rising_edge(clock) then
   if rising_edge(clock) then
      if loadKey = '1' then
      if loadKey = '1' then
         w <= key & w(0 to 6);
         w <= key & w(0 to 6);
      elsif keyExpansionReady = '0' then
      elsif keyExpansionReady = '0' then
         w <= w(1 to conv_integer(Nk)) & (w(0) xor temp);
                        case Nk is
 
                                when 3 =>
 
                                        w(0 to 3) <= w(1 to 3) & (w(0) xor temp);
 
                                when 5 =>
 
                                        w(0 to 5) <= w(1 to 5) & (w(0) xor temp);
 
                                when others =>
 
                                        w(0 to 7) <= w(1 to 7) & (w(0) xor temp);
 
                                end case;
      end if;
      end if;
   end if;
   end if;
end process;
end process;
--begin keyExpansionPipe asynchron circuitry
--begin keyExpansionPipe asynchron circuitry
rotW0 <= w(conv_integer(Nk))(23 downto 0) & w(conv_integer(Nk))(31 downto 24);
rotW0 <= w(Nk)(23 downto 0) & w(Nk)(31 downto 24);
subIn <= rotW0 when iModNk = x"0" else
subIn <= rotW0 when iModNk = 0 else
         w(conv_integer(Nk)) when Nk = x"7" and iModNk = x"4" else x"00000000";
         w(Nk) when Nk = 7 and iModNk = 4 else x"00000000";
subBytesGen: for i in 0 to 3 generate
subBytesFor: for i in 0 to 3 generate
   type subT is array(0 to 255) of std_logic_vector(7 downto 0);
   type subT is array(0 to 255) of std_logic_vector(7 downto 0);
   constant sub : subT :=
   constant sub : subT :=
     (x"63", x"7c", x"77", x"7b", x"f2", x"6b", x"6f", x"c5", x"30", x"01", x"67", x"2b", x"fe", x"d7", x"ab", x"76",
     (x"63", x"7c", x"77", x"7b", x"f2", x"6b", x"6f", x"c5", x"30", x"01", x"67", x"2b", x"fe", x"d7", x"ab", x"76",
      x"ca", x"82", x"c9", x"7d", x"fa", x"59", x"47", x"f0", x"ad", x"d4", x"a2", x"af", x"9c", x"a4", x"72", x"c0",
      x"ca", x"82", x"c9", x"7d", x"fa", x"59", x"47", x"f0", x"ad", x"d4", x"a2", x"af", x"9c", x"a4", x"72", x"c0",
      x"b7", x"fd", x"93", x"26", x"36", x"3f", x"f7", x"cc", x"34", x"a5", x"e5", x"f1", x"71", x"d8", x"31", x"15",
      x"b7", x"fd", x"93", x"26", x"36", x"3f", x"f7", x"cc", x"34", x"a5", x"e5", x"f1", x"71", x"d8", x"31", x"15",
Line 91... Line 100...
      x"e1", x"f8", x"98", x"11", x"69", x"d9", x"8e", x"94", x"9b", x"1e", x"87", x"e9", x"ce", x"55", x"28", x"df",
      x"e1", x"f8", x"98", x"11", x"69", x"d9", x"8e", x"94", x"9b", x"1e", x"87", x"e9", x"ce", x"55", x"28", x"df",
      x"8c", x"a1", x"89", x"0d", x"bf", x"e6", x"42", x"68", x"41", x"99", x"2d", x"0f", x"b0", x"54", x"bb", x"16");
      x"8c", x"a1", x"89", x"0d", x"bf", x"e6", x"42", x"68", x"41", x"99", x"2d", x"0f", x"b0", x"54", x"bb", x"16");
begin
begin
   subRotW0(8*(i+1)-1 downto 8*i) <= sub(conv_integer(subIn(8*(i+1)-1 downto 8*i)));
   subRotW0(8*(i+1)-1 downto 8*i) <= sub(conv_integer(subIn(8*(i+1)-1 downto 8*i)));
end generate;
end generate;
temp <=  subRotW0 xor (Rcon(conv_integer(RconCnt)) & x"000000") when iModNk = x"0" else
temp <=  subRotW0 xor (Rcon(RconCnt) & x"000000") when iModNk = 0 else
         subRotW0 when Nk = x"7" and iModNk = x"4" else
         subRotW0 when Nk = 7 and iModNk = 4 else
         w(conv_integer(Nk));
         w(Nk);
--end keyExpansionPipe asynchron circuitry
--end keyExpansionPipe asynchron circuitry
 
 
subKey <= w(0) & w(1) & w(2) & w(3);
subKey <= w(0) & w(1) & w(2) & w(3);
subKeyAddress <= roundCounter(5 downto 2);
subKeyAddress <= roundCounter(5 downto 2);
subKeyEnable <= '1' when roundCounter(1 downto 0) = "00" else '0';
subKeyEnable <= '1' when roundCounter(1 downto 0) = "00" else '0';

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.