-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecryption_regfile.v
159 lines (122 loc) · 2.89 KB
/
decryption_regfile.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 20:13:49 11/23/2020
// Design Name:
// Module Name: decryption_regfile
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
`define selectAddr 0
`define caesarAddr 'h10
`define scytaleAddr 'h12
`define zigzagAddr 'h14
`define RESET 0
`define IDLE 10
`define READ 20
`define WRITE 30
module decryption_regfile #(
parameter addr_witdth = 8,
parameter reg_width = 16
)(
// Clock and reset interface
input clk,
input rst_n,
// Register access interface
input[addr_witdth - 1:0] addr,
input read,
input write,
input [reg_width -1 : 0] wdata,
output reg [reg_width -1 : 0] rdata,
output reg done,
output reg error,
// Output wires
output reg[reg_width - 1 : 0] select,
output reg[reg_width - 1 : 0] caesar_key,
output reg[reg_width - 1 : 0] scytale_key,
output reg[reg_width - 1 : 0] zigzag_key
);
reg[reg_width - 1 : 0] wdata_reg;
reg[addr_witdth - 1 : 0] addr_reg;
reg[7 : 0] state = 0, nextState = 0;
always @(posedge clk) begin
state <= nextState;
wdata_reg = wdata;
addr_reg = addr;
if (~rst_n) begin
state <= `RESET;
end
end
always @(*) begin
case(state)
`RESET: begin
select = 0;
caesar_key = 0;
scytale_key = 'hFFFF;
zigzag_key = 'h02;
rdata = 0;
done = 0;
error = 0;
nextState = `IDLE;
end
`IDLE: begin
// Resetare flag-uri eroare si done
done = 0;
error = 0;
// Selectare stari de citire/scriere
if(read) begin
nextState = `READ;
end
if(write) begin
nextState = `WRITE;
end
end
`READ: begin
case(addr_reg)
`selectAddr:
rdata = select;
`caesarAddr:
rdata = caesar_key;
`scytaleAddr:
rdata = scytale_key;
`zigzagAddr:
rdata = zigzag_key;
// Cazul adresei invalide
default:
error = 1;
endcase
done = 1;
nextState = `IDLE;
end
`WRITE: begin
case(addr_reg)
`selectAddr:
// Copiem doar ultimii 2 biti
select[1:0] = wdata_reg[1:0];
`caesarAddr:
caesar_key = wdata_reg;
`scytaleAddr:
scytale_key = wdata_reg;
`zigzagAddr:
zigzag_key = wdata_reg;
// Cazul adresei invalide
default:
error = 1;
endcase
done = 1;
nextState = `IDLE;
end
endcase
end
endmodule