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

Subversion Repositories aes_decry_ip_128bit

[/] [aes_decry_ip_128bit/] [trunk/] [rtl/] [key_schd/] [key_scheduler.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 ghegde
--************************************************************
2
--Copyright 2015, Ganesh Hegde < ghegde@opencores.org >      
3
--                                                           
4
--This source file may be used and distributed without  
5
--restriction provided that this copyright statement is not 
6
--removed from the file and that any derivative work contains
7
--the original copyright notice and the associated disclaimer.
8
--
9
--This source is distributed in the hope that it will be
10
--useful, but WITHOUT ANY WARRANTY; without even the implied
11
--warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
--PURPOSE.  See the GNU Lesser General Public License for more
13
--details.
14
--
15
--You should have received a copy of the GNU Lesser General
16
--Public License along with this source; if not, download it
17
--from http://www.opencores.org/lgpl.shtml
18
--
19
--*************************************************************
20
 
21
--*************************************************************
22
--Top level entity for key scheduling.
23
--Note that module does not support reconfigurable key.To change
24
-- the key the module has to undergo a reset.
25
--Logic type : Sequential (11 cycle latency for the key to be ready)
26
--*************************************************************
27
 
28
library ieee;
29
use ieee.std_logic_1164.all;
30
use ieee.numeric_std.all;
31
 
32
entity key_scheduler is
33
port(
34
     key_in  : in std_logic_vector(127 downto 0);--Decryption Key
35
         key_out : out std_logic_vector(127 downto 0);--Output key(one cycle delay)
36
         valid_in : in std_logic;--Should be high when input key is valid
37
         key_ready : out std_logic;--Asserted high when key_scheduler generated all the keys
38
         round: in std_logic_vector(3 downto 0);--Which round key to access
39
         clk,reset: in std_logic
40
    );
41
end key_scheduler;
42
 
43
architecture beh_key_scheduler of key_scheduler is
44
   --Single port RAM module 16x128
45
   component singleport_RAM
46
      port(
47
           datain : in std_logic_vector(127 downto 0);
48
                addr : in std_logic_vector(3 downto 0);
49
                we,clk   : in std_logic;
50
                dataout: out std_logic_vector(127 downto 0)
51
      );
52
   end component;
53
 
54
   component one_round_key
55
   port(
56
         in_key: in std_logic_vector(127 downto 0);
57
         out_key: out std_logic_vector(127 downto 0);
58
         rcon: in std_logic_vector(7 downto 0)
59
        );
60
   end component;
61
 
62
   type state is (IDLE,ROUNDKEY,READY);
63
   signal state_n,state_reg: state;
64
   --RAM signals
65
   signal we :std_logic;
66
   signal ram_data_in,ram_data_out:std_logic_vector(127 downto 0);
67
   signal ram_addr:std_logic_vector(3 downto 0);
68
 
69
   --one_round_key signals
70
   signal rcon_in : std_logic_vector(7 downto 0);
71
   signal out_key : std_logic_vector(127 downto 0);
72
 
73
   signal count_reg,count_n:unsigned(3 downto 0);
74
 
75
begin
76
--Instantiate single port RAM
77
   singleport_RAM_inst:singleport_RAM
78
   port map(datain=>ram_data_in,dataout=>ram_data_out,addr=>ram_addr,clk=>clk,we=>we);
79
 
80
--Instantiate round key calculator
81
   one_round_key_inst:one_round_key
82
   port map(in_key=>ram_data_out,out_key=>out_key,rcon=>rcon_in);
83
 
84
--State register 
85
   process(clk,reset)
86
   begin
87
      if(reset='1') then --Active High reset
88
             state_reg<=IDLE;
89
                 count_reg<="1010";--10
90
          elsif(clk'event and clk='1') then
91
         state_reg <= state_n;
92
         count_reg <= count_n;
93
          end if;
94
   end process;
95
 
96
--Next state logic
97
  process(state_reg,valid_in,count_reg)
98
  begin
99
  case state_reg is
100
      when IDLE =>
101
             if(valid_in='1') then
102
                    count_n<=count_reg-1;
103
                        state_n<=ROUNDKEY;
104
                  else
105
                    state_n<=state_reg;
106
                        count_n<=count_reg;
107
         end if;
108
      when ROUNDKEY =>
109
         if(count_reg = "0000") then
110
            state_n<=READY;
111
                                count_n<=count_reg;
112
         else
113
                        count_n<=count_reg-1;
114
                        state_n<=state_reg;
115
                 end if;
116
          when READY=>
117
             state_n<=state_reg;
118
                  count_n<=count_reg;
119
                 --No error case handle
120
                 end case;
121
  end process;
122
 
123
 --Output logic
124
   with state_reg select
125
         ram_data_in <= key_in when IDLE,
126
                                out_key when others;
127
 
128
    we <= '1' when (state_reg=IDLE or state_reg = ROUNDKEY) else
129
          '0';
130
 
131
        with state_reg select
132
              ram_addr <= std_logic_vector(count_reg) when IDLE,
133
                              std_logic_vector(count_reg) when ROUNDKEY,
134
                                          round when others;
135
 
136
        key_out <=      ram_data_out;--Output is valid after one cycle.
137
        key_ready<= '1' when state_reg = READY else
138
            '0';
139
 
140
        with count_reg select
141
              rcon_in <= x"01" when "1001",
142
                     x"02" when "1000",
143
                     x"04" when "0111",
144
                     x"08" when "0110",
145
                     x"10" when "0101",
146
                     x"20" when "0100",
147
                     x"40" when "0011",
148
                     x"80" when "0010",
149
                     x"1B" when "0001",
150
                     x"36" when others;
151
end beh_key_scheduler;

powered by: WebSVN 2.1.0

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