| 1 |
2 |
subhasis25 |
----------------------------------------------------------------------
|
| 2 |
|
|
---- ----
|
| 3 |
5 |
subhasis25 |
---- Pipelined Aes IP Core ----
|
| 4 |
|
|
---- ----
|
| 5 |
|
|
---- This file is part of the Pipelined AES project ----
|
| 6 |
|
|
---- http://www.opencores.org/cores/aes_pipe/ ----
|
| 7 |
|
|
---- ----
|
| 8 |
|
|
---- Description ----
|
| 9 |
|
|
---- Implementation of AES IP core according to ----
|
| 10 |
|
|
---- FIPS PUB 197 specification document. ----
|
| 11 |
|
|
---- ----
|
| 12 |
|
|
---- To Do: ----
|
| 13 |
|
|
---- - ----
|
| 14 |
|
|
---- ----
|
| 15 |
|
|
---- Author: ----
|
| 16 |
|
|
---- - Subhasis Das, subhasis256@gmail.com ----
|
| 17 |
|
|
---- ----
|
| 18 |
|
|
----------------------------------------------------------------------
|
| 19 |
|
|
---- ----
|
| 20 |
|
|
---- Copyright (C) 2009 Authors and OPENCORES.ORG ----
|
| 21 |
|
|
---- ----
|
| 22 |
2 |
subhasis25 |
---- This source file may be used and distributed without ----
|
| 23 |
|
|
---- restriction provided that this copyright statement is not ----
|
| 24 |
5 |
subhasis25 |
---- removed from the file and that any derivative work contains ----
|
| 25 |
2 |
subhasis25 |
---- the original copyright notice and the associated disclaimer. ----
|
| 26 |
|
|
---- ----
|
| 27 |
|
|
---- This source file is free software; you can redistribute it ----
|
| 28 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
| 29 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
| 30 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
| 31 |
|
|
---- later version. ----
|
| 32 |
|
|
---- ----
|
| 33 |
|
|
---- This source is distributed in the hope that it will be ----
|
| 34 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
| 35 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
| 36 |
5 |
subhasis25 |
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
| 37 |
2 |
subhasis25 |
---- details. ----
|
| 38 |
|
|
---- ----
|
| 39 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
| 40 |
|
|
---- Public License along with this source; if not, download it ----
|
| 41 |
5 |
subhasis25 |
---- from http://www.opencores.org/lgpl.shtml ----
|
| 42 |
2 |
subhasis25 |
---- ----
|
| 43 |
|
|
----------------------------------------------------------------------
|
| 44 |
|
|
------------------------------------------------------
|
| 45 |
|
|
-- Project: AESFast
|
| 46 |
|
|
-- Author: Subhasis
|
| 47 |
9 |
subhasis25 |
-- Last Modified: 25/03/10
|
| 48 |
2 |
subhasis25 |
-- Email: subhasis256@gmail.com
|
| 49 |
|
|
------------------------------------------------------
|
| 50 |
|
|
--
|
| 51 |
|
|
-- Description: The Sbox and Shiftrows step
|
| 52 |
|
|
-- Ports:
|
| 53 |
|
|
-- clk: System Clock
|
| 54 |
|
|
-- blockin: Input state block
|
| 55 |
|
|
-- fc3: See keysched1 for explanation
|
| 56 |
|
|
-- c0: See keysched1 for explanation
|
| 57 |
|
|
-- c1: See keysched1 for explanation
|
| 58 |
|
|
-- c2: See keysched1 for explanation
|
| 59 |
|
|
-- c3: See keysched1 for explanation
|
| 60 |
|
|
-- nextkey: Roundkey for next round
|
| 61 |
|
|
-- blockout: output state block
|
| 62 |
|
|
------------------------------------------------------
|
| 63 |
|
|
|
| 64 |
|
|
library IEEE;
|
| 65 |
|
|
use IEEE.std_logic_1164.all;
|
| 66 |
|
|
use IEEE.std_logic_arith.all;
|
| 67 |
|
|
use IEEE.std_logic_unsigned.all;
|
| 68 |
|
|
|
| 69 |
|
|
library work;
|
| 70 |
|
|
use work.aes_pkg.all;
|
| 71 |
|
|
|
| 72 |
|
|
entity sboxshr is
|
| 73 |
|
|
port(
|
| 74 |
|
|
clk: in std_logic;
|
| 75 |
9 |
subhasis25 |
rst: in std_logic;
|
| 76 |
2 |
subhasis25 |
blockin: in datablock;
|
| 77 |
|
|
fc3: in blockcol;
|
| 78 |
|
|
c0: in blockcol;
|
| 79 |
|
|
c1: in blockcol;
|
| 80 |
|
|
c2: in blockcol;
|
| 81 |
|
|
c3: in blockcol;
|
| 82 |
|
|
nextkey: out datablock;
|
| 83 |
|
|
blockout: out datablock
|
| 84 |
|
|
);
|
| 85 |
|
|
end sboxshr;
|
| 86 |
|
|
|
| 87 |
|
|
architecture rtl of sboxshr is
|
| 88 |
|
|
component sbox is
|
| 89 |
|
|
port(
|
| 90 |
|
|
clk: in std_logic;
|
| 91 |
9 |
subhasis25 |
rst: in std_logic;
|
| 92 |
2 |
subhasis25 |
bytein: in std_logic_vector(7 downto 0);
|
| 93 |
|
|
byteout: out std_logic_vector(7 downto 0)
|
| 94 |
|
|
);
|
| 95 |
|
|
end component;
|
| 96 |
|
|
begin
|
| 97 |
|
|
-- The sbox, the output going to the appropriate state byte after shiftrows
|
| 98 |
|
|
g0: for i in 3 downto 0 generate
|
| 99 |
|
|
g1: for j in 3 downto 0 generate
|
| 100 |
|
|
sub: sbox port map(
|
| 101 |
|
|
clk => clk,
|
| 102 |
9 |
subhasis25 |
rst => rst,
|
| 103 |
2 |
subhasis25 |
bytein => blockin(i,j),
|
| 104 |
|
|
byteout => blockout(i,(j-i) mod 4)
|
| 105 |
|
|
);
|
| 106 |
|
|
end generate;
|
| 107 |
|
|
end generate;
|
| 108 |
9 |
subhasis25 |
process(clk,rst)
|
| 109 |
2 |
subhasis25 |
begin
|
| 110 |
9 |
subhasis25 |
if(rst = '1') then
|
| 111 |
|
|
nextkey <= zero_data;
|
| 112 |
|
|
elsif(rising_edge(clk)) then
|
| 113 |
2 |
subhasis25 |
-- col0 of nextkey = fc3 xor col0
|
| 114 |
|
|
-- col1 of nextkey = fc3 xor col0 xor col1
|
| 115 |
|
|
-- col2 of nextkey = fc3 xor col0 xor col1 xor col2
|
| 116 |
|
|
-- col3 of nextkey = fc3 xor col0 xor col1 xor col2 xor col3
|
| 117 |
|
|
genkey: for j in 3 downto 0 loop
|
| 118 |
|
|
nextkey(j, 0) <= fc3(j) xor c0(j);
|
| 119 |
|
|
nextkey(j, 1) <= fc3(j) xor c1(j);
|
| 120 |
|
|
nextkey(j, 2) <= fc3(j) xor c2(j);
|
| 121 |
|
|
nextkey(j, 3) <= fc3(j) xor c3(j);
|
| 122 |
|
|
end loop;
|
| 123 |
|
|
end if;
|
| 124 |
|
|
end process;
|
| 125 |
|
|
end rtl;
|