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

Subversion Repositories tiny_aes

[/] [tiny_aes/] [trunk/] [rtl/] [aes_128.v] - Blame information for rev 13

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 homer.hsin
/*
2
 * Copyright 2012, Homer Hsing <homer.hsing@gmail.com>
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
module aes_128(clk, state, key, out);
18
    input          clk;
19
    input  [127:0] state, key;
20
    output [127:0] out;
21
    reg    [127:0] s0, k0;
22 6 homer.hsin
    wire   [127:0] s1, s2, s3, s4, s5, s6, s7, s8, s9,
23
                   k1, k2, k3, k4, k5, k6, k7, k8, k9,
24
                   k0b, k1b, k2b, k3b, k4b, k5b, k6b, k7b, k8b, k9b;
25 4 homer.hsin
 
26
    always @ (posedge clk)
27
      begin
28
        s0 <= state ^ key;
29
        k0 <= key;
30
      end
31 6 homer.hsin
 
32
    expand_key_128
33
        a1 (clk, k0, k1, k0b, 8'h1),
34
        a2 (clk, k1, k2, k1b, 8'h2),
35
        a3 (clk, k2, k3, k2b, 8'h4),
36
        a4 (clk, k3, k4, k3b, 8'h8),
37
        a5 (clk, k4, k5, k4b, 8'h10),
38
        a6 (clk, k5, k6, k5b, 8'h20),
39
        a7 (clk, k6, k7, k6b, 8'h40),
40
        a8 (clk, k7, k8, k7b, 8'h80),
41
        a9 (clk, k8, k9, k8b, 8'h1b),
42
       a10 (clk, k9,   , k9b, 8'h36);
43
 
44
    one_round
45
        r1 (clk, s0, k0b, s1),
46
        r2 (clk, s1, k1b, s2),
47
        r3 (clk, s2, k2b, s3),
48
        r4 (clk, s3, k3b, s4),
49
        r5 (clk, s4, k4b, s5),
50
        r6 (clk, s5, k5b, s6),
51
        r7 (clk, s6, k6b, s7),
52
        r8 (clk, s7, k7b, s8),
53
        r9 (clk, s8, k8b, s9);
54
 
55
    final_round
56
        rf (clk, s9, k9b, out);
57 4 homer.hsin
endmodule
58
 
59 6 homer.hsin
module expand_key_128(clk, in, out_1, out_2, rcon);
60 4 homer.hsin
    input              clk;
61 6 homer.hsin
    input      [127:0] in;
62 4 homer.hsin
    input      [7:0]   rcon;
63 6 homer.hsin
    output reg [127:0] out_1;
64
    output     [127:0] out_2;
65
    wire       [31:0]  k0, k1, k2, k3,
66
                       v0, v1, v2, v3;
67
    reg        [31:0]  k0a, k1a, k2a, k3a;
68
    wire       [31:0]  k0b, k1b, k2b, k3b, k4a;
69
 
70
    assign {k0, k1, k2, k3} = in;
71 4 homer.hsin
 
72
    assign v0 = {k0[31:24] ^ rcon, k0[23:0]};
73
    assign v1 = v0 ^ k1;
74
    assign v2 = v1 ^ k2;
75
    assign v3 = v2 ^ k3;
76 6 homer.hsin
 
77 4 homer.hsin
    always @ (posedge clk)
78
        {k0a, k1a, k2a, k3a} <= {v0, v1, v2, v3};
79 6 homer.hsin
 
80 4 homer.hsin
    S4
81
        S4_0 (clk, {k3[23:0], k3[31:24]}, k4a);
82 6 homer.hsin
 
83 4 homer.hsin
    assign k0b = k0a ^ k4a;
84
    assign k1b = k1a ^ k4a;
85
    assign k2b = k2a ^ k4a;
86
    assign k3b = k3a ^ k4a;
87 6 homer.hsin
 
88 4 homer.hsin
    always @ (posedge clk)
89 6 homer.hsin
        out_1 <= {k0b, k1b, k2b, k3b};
90
 
91
    assign out_2 = {k0b, k1b, k2b, k3b};
92 4 homer.hsin
endmodule
93
 

powered by: WebSVN 2.1.0

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