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

Subversion Repositories fully_pipelined_128_aes_algorithm

[/] [fully_pipelined_128_aes_algorithm/] [trunk/] [rtl/] [AES_Encrypt.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 muhammedko
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: MUHAMMED KOCAOGLU
4
-- 
5
-- Create Date: 12/29/2021 12:01:25 AM
6
-- Design Name: 
7
-- Module Name: AES_Encrypt - Behavioral
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool Versions: 
11
-- Description: 
12
-- 
13
-- Dependencies: 
14
-- 
15
-- Revision:
16
-- Revision 0.01 - File Created
17
-- Additional Comments:
18
-- 
19
----------------------------------------------------------------------------------
20
LIBRARY IEEE;
21
USE IEEE.STD_LOGIC_1164.ALL;
22
USE work.AES_pkg.ALL;
23
 
24
-- Uncomment the following library declaration if using
25
-- arithmetic functions with Signed or Unsigned values
26
--use IEEE.NUMERIC_STD.ALL;
27
 
28
-- Uncomment the following library declaration if instantiating
29
-- any Xilinx leaf cells in this code.
30
--library UNISIM;
31
--use UNISIM.VComponents.all;
32
 
33
ENTITY AES_Encrypt IS
34
    PORT (
35
        CLK         : IN STD_LOGIC;
36
        aes_enable  : IN STD_LOGIC;
37
        aes_stop    : IN STD_LOGIC;
38
        aes_key     : IN STD_LOGIC_VECTOR(16 * 8 - 1 DOWNTO 0);
39
        aes_message : IN STD_LOGIC_VECTOR(16 * 8 - 1 DOWNTO 0);
40
        aes_out     : OUT STD_LOGIC_VECTOR(16 * 8 - 1 DOWNTO 0);
41
        aes_done    : OUT STD_LOGIC;
42
        aes_valid   : OUT STD_LOGIC
43
    );
44
END AES_Encrypt;
45
 
46
ARCHITECTURE Behavioral OF AES_Encrypt IS
47
    SIGNAL aes_matrix : array3D8;
48
 
49
    TYPE subkeyArray IS ARRAY (NATURAL RANGE 0 TO 9) OF array3D8;
50
    SIGNAL subkeys          : subkeyArray;
51
    SIGNAL cipheredMessages : subkeyArray;
52
 
53
    SIGNAL cntr      : INTEGER RANGE 0 TO 15 := 0;
54
    SIGNAL cntrValid : INTEGER RANGE 0 TO 15 := 0;
55
 
56
    SIGNAL aes_stop_Reg : STD_LOGIC := '0';
57
    TYPE states IS (
58
        S_IDLE,
59
        S_CIPHER
60
    );
61
    SIGNAL state : states := S_IDLE;
62
 
63
BEGIN
64
    P_MAIN : PROCESS (CLK)
65
    BEGIN
66
        IF rising_edge(CLK) THEN
67
            aes_done <= '0';
68
            CASE state IS
69
                WHEN S_IDLE =>
70
                    aes_stop_Reg <= '0';
71
                    aes_valid    <= '0';
72
                    IF aes_enable = '1' THEN
73
                        state <= S_CIPHER;
74
                    END IF;
75
 
76
                WHEN S_CIPHER =>
77
                    IF aes_stop = '1' THEN
78
                        aes_stop_Reg <= '1';
79
                    END IF;
80
 
81
                    IF aes_stop_Reg = '1' THEN
82
                        IF cntr < 9 THEN
83
                            cntr <= cntr + 1;
84
                        ELSE
85
                            aes_valid    <= '0';
86
                            cntr         <= 0;
87
                            cntrValid    <= 0;
88
                            aes_done     <= '1';
89
                            aes_stop_Reg <= '0';
90
                            state        <= S_IDLE;
91
                        END IF;
92
                    END IF;
93
 
94
                    IF cntrValid = 10 THEN
95
                        aes_valid <= '1';
96
                    ELSE
97
                        cntrValid <= cntrValid + 1;
98
                    END IF;
99
 
100
                    subkeys(0)          <= generateSubKey(aes_key, 0);
101
                    cipheredMessages(0) <= encryptMessage(aes_message, aes_key);
102
                    FOR i IN 0 TO 8 LOOP
103
                        subkeys(i + 1)          <= generateSubKey(subkeys(i), i + 1);
104
                        cipheredMessages(i + 1) <= encryptMessage(cipheredMessages(i), subkeys(i));
105
                    END LOOP;
106
                    aes_out <= encyrptFinal(cipheredMessages(9), subkeys(9));
107
 
108
            END CASE;
109
 
110
        END IF;
111
    END PROCESS;
112
END Behavioral;

powered by: WebSVN 2.1.0

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