-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 😎 Decrypt & Decrypt Round * 💄 Code Styling --------- Co-authored-by: AhmedSobhy01 <[email protected]>
- Loading branch information
1 parent
f51c247
commit 2e02d9f
Showing
4 changed files
with
102 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module AESDecrypt #(parameter Nk = 4,parameter Nr = 10) (data, key, out, clk); | ||
input [127:0] data; | ||
input [Nk * 32 - 1:0] key; | ||
input clk; | ||
output [127:0] out; | ||
|
||
reg [127:0] state; | ||
reg [127:0] keyReg; | ||
reg [3:0] roundCount = 0; | ||
wire [127:0] stateAfterLastRound; | ||
wire [127:0] stateAfterKey; | ||
wire [127:0] stateAfterRound; | ||
|
||
wire [(11 * 128) - 1:0] allKeys; | ||
|
||
KeyExpansion keysGetter( key , allKeys); | ||
AddRoundKey a(state, keyReg , stateAfterKey); | ||
DecryptRound round(state , keyReg , stateAfterRound); | ||
LastDecryptRound lastRound (state , keyReg , stateAfterLastRound); | ||
|
||
assign out = state; | ||
|
||
always @(posedge clk) begin | ||
if (roundCount == 0)begin | ||
keyReg = allKeys [((11 * 128) - 1) -: 128 ] ; | ||
state = data; | ||
end | ||
else if (roundCount == 1) | ||
state <= stateAfterKey; | ||
else if (roundCount < Nr +1) | ||
state <= stateAfterRound; | ||
else if (roundCount == Nr +1) | ||
state <= stateAfterLastRound; | ||
|
||
if (roundCount > 0 && roundCount < Nr + 1) | ||
keyReg <= allKeys [((11 * 128) - roundCount * 128 - 1) -: 128 ]; | ||
|
||
if (roundCount < Nr + 2) | ||
roundCount <= roundCount + 1; | ||
end | ||
endmodule | ||
|
||
module AESDecrypt_DUT(); | ||
reg [127:0] data; | ||
reg [127:0] key; | ||
wire [127:0] out; | ||
reg clk; | ||
|
||
AESDecrypt aes(data,key,out,clk); | ||
|
||
initial begin | ||
key = 128'h000102030405060708090a0b0c0d0e0f; | ||
data = 128'h69c4e0d86a7b0430d8cdb78070b4c55a; | ||
clk = 0; | ||
forever #10 clk = ~clk; | ||
end | ||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module DecryptRound(stateIn, key, stateOut); | ||
input [127:0] stateIn; | ||
input [127:0] key; | ||
output [127:0] stateOut; | ||
|
||
wire [127:0] subByteWire; | ||
wire [127:0] shiftRowsWire; | ||
wire [127:0] afterRoundKey; | ||
|
||
InvShiftRows shft(stateIn, shiftRowsWire); | ||
InvSubBytes sub(shiftRowsWire, subByteWire); | ||
AddRoundKey addkey(subByteWire, key, afterRoundKey); | ||
InvMixColumns mix(afterRoundKey, stateOut); | ||
endmodule | ||
|
||
module LastDecryptRound(stateIn, key, stateOut); | ||
input [127:0] stateIn; | ||
input [127:0] key; | ||
output [127:0] stateOut; | ||
|
||
wire [127:0] subByteWire; | ||
wire [127:0] shiftRowsWire; | ||
|
||
InvShiftRows shft(stateIn, shiftRowsWire); | ||
InvSubBytes sub(shiftRowsWire, subByteWire); | ||
AddRoundKey addkey(subByteWire, key, stateOut); | ||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters