OpenCores
URL https://opencores.org/ocsvn/aes-128_pipelined_encryption/aes-128_pipelined_encryption/trunk

Subversion Repositories aes-128_pipelined_encryption

[/] [aes-128_pipelined_encryption/] [tags/] [R0/] [rtl/] [Top_PipelinedCipher.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Amr_Salah
/*
2
Project        : AES
3
Standard doc.  : FIPS 197
4
Module name    : Top_AES_PipelinedCipher
5
Dependancy     :
6
Design doc.    :
7
References     :
8
Description    : this is the top module of the design which forms
9
                 rounds and connects KeyExpantion using pipelined
10
                                 architecture
11
Owner          : Amr Salah
12
*/
13
 
14
 
15
`timescale 1 ns/1 ps
16
 
17
module Top_PipelinedCipher
18
#
19
(
20
parameter DATA_W = 128,      //data width
21
parameter KEY_L = 128,       //key length
22
parameter NO_ROUNDS = 10     //number of rounds
23
)
24
 
25
(
26
input clk,                       //system clock
27
input reset,                     //asynch reset
28
input data_valid_in,             //data valid signal
29
input cipherkey_valid_in,        //cipher key valid signal
30
input [KEY_L-1:0] cipher_key,    //cipher key
31
input [DATA_W-1:0] plain_text,   //plain text
32
output valid_out,                //output valid signal
33
output [DATA_W-1:0] cipher_text  //cipher text
34
);
35
 
36
wire [NO_ROUNDS-1:0] valid_round_key;            //all round keys valid signals KeyExpantion output
37
wire [NO_ROUNDS-1:0] valid_round_data;           //all rounds ouput data valid signals
38
wire [DATA_W-1:0] data_round [0:NO_ROUNDS-1];    //all rounds data
39
wire valid_sub2shift;                            //for final round connection
40
wire valid_shift2key;                            //
41
wire [DATA_W-1:0]data_sub2shift;                 //
42
wire [DATA_W-1:0]data_shift2key;                 //
43
wire [(NO_ROUNDS*DATA_W)-1:0] W;                 //all round keys
44
 
45
reg[DATA_W-1:0] data_shift2key_delayed;           //for delay register
46
reg valid_shift2key_delayed;
47
 
48
//instantiate Key Expantion which will feed every round with round key
49
KeyExpantion #(DATA_W,KEY_L,NO_ROUNDS) U_KEYEXP(clk,reset,cipherkey_valid_in,cipher_key,W,valid_round_key);
50
 
51
//due to algorithm,first cipher key will be xored witht plain text
52
AddRoundKey #(DATA_W)U0_ARK(clk,reset,data_valid_in,cipherkey_valid_in,plain_text,cipher_key,valid_round_data[0],data_round[0]);
53
 
54
//instantiate all rounds , connect them with key expantion
55
genvar i;
56
generate
57
for(i=0;i<NO_ROUNDS-1;i=i+1) begin : ROUND
58
 Round #(DATA_W)U_ROUND(clk,reset,valid_round_data[i],valid_round_key[i],data_round[i],W[(NO_ROUNDS-i)*DATA_W-1:(NO_ROUNDS-i-1)*DATA_W],valid_round_data[i+1],data_round[i+1]);
59
end
60
endgenerate
61
 
62
//this is the final round it doesn't contain mixcolumns as declared in fips197 standard document
63
SubBytes #(DATA_W) U_SUB (clk,reset,valid_round_data[NO_ROUNDS-1],data_round[NO_ROUNDS-1],valid_sub2shift,data_sub2shift);
64
ShiftRows #(DATA_W) U_SH (clk,reset,valid_sub2shift,data_sub2shift,valid_shift2key,data_shift2key);
65
AddRoundKey #(DATA_W) U_KEY (clk,reset,valid_shift2key_delayed,valid_round_key[NO_ROUNDS-1],data_shift2key_delayed,W[DATA_W-1:0],valid_out,cipher_text);
66
 
67
/*as the final round has only three stages a delay register should be introduced
68
  to be balanced with key  expantion*/
69
always @(posedge clk or negedge reset)
70
 
71
if(!reset)begin
72
    valid_shift2key_delayed <= 1'b0;
73
    data_shift2key_delayed <= 'b0;
74
end else begin
75
 
76
 if(valid_shift2key)begin
77
   data_shift2key_delayed <= data_shift2key;
78
 end
79
   valid_shift2key_delayed <= valid_shift2key;
80
end
81
 
82
endmodule

powered by: WebSVN 2.1.0

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