-
Notifications
You must be signed in to change notification settings - Fork 2
/
lockbox.v
38 lines (35 loc) 路 1.14 KB
/
lockbox.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
module lockbox #(
parameter WIDTH = 128
) (input clk, input resetn, input en, input op, input [WIDTH-1:0] secret, input [WIDTH-1:0] password, output [WIDTH-1:0] out);
reg [WIDTH-1:0] stored_secret;
reg [WIDTH-1:0] stored_password;
reg [WIDTH-1:0] returned_secret;
always @(posedge clk) begin
if (!resetn) begin
returned_secret <= 0;
end else if (en) begin
if (op) begin
// store
stored_secret <= secret;
stored_password <= password;
returned_secret <= 0;
end else begin
// get
if (password == stored_password) begin
returned_secret <= stored_secret;
end else begin
returned_secret <= 0;
end
stored_secret <= 0;
// it's secure even if we don't clear the password!
// just requires being a bit clever with the refinement relation
// (there's no longer an abstraction function that works)
//
// stored_password <= 0;
end
end else begin
returned_secret <= 0;
end
end
assign out = returned_secret;
endmodule