OpenCores
URL https://opencores.org/ocsvn/gost28147-89/gost28147-89/trunk

Subversion Repositories gost28147-89

[/] [gost28147-89/] [trunk/] [rtl/] [gost89_cfb.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 fanatid
module gost89_cfb(
2
  input              clk,
3
  input              reset,
4
  input              mode,
5
  input              load_data,
6
  input      [511:0] sbox,
7
  input      [255:0] key,
8
  input      [63:0]  in,
9
  output reg [63:0]  out,
10
  output reg         busy
11
);
12
  reg  [63:0] gamma;
13
  reg  [63:0] in_value;
14
  wire [63:0] out_ecb;
15
  wire        reset_ecb, load_ecb, busy_ecb;
16
 
17
  assign load_ecb = !reset && load_data;
18
  assign reset_ecb = load_ecb;
19
 
20
  gost89_ecb_encrypt
21
    ecb_encrypt(clk, reset_ecb, load_ecb, sbox, key, gamma, out_ecb, busy_ecb);
22
 
23
  always @(posedge clk) begin
24
    if (reset && !load_data) begin
25
      gamma <= in;
26
      busy <= 0;
27
    end
28
 
29
    if (!reset & load_data) begin
30
      in_value <= in;
31
      busy <= 1;
32
    end
33
 
34
    if (!reset && !load_data && !busy_ecb && busy) begin
35
      if (mode) gamma <= in_value;
36
      else      gamma <= out_ecb ^ in_value;
37
      out   <= out_ecb ^ in_value;
38
      busy  <= 0;
39
    end
40
  end
41
endmodule
42
 
43
module gost89_cfb_encrypt(
44
  input              clk,
45
  input              reset,
46
  input              load_data,
47
  input      [511:0] sbox,
48
  input      [255:0] key,
49
  input      [63:0]  in,
50
  output reg [63:0]  out,
51
  output reg         busy
52
);
53
  reg  [63:0] gamma;
54
  reg  [63:0] in_value;
55
  wire [63:0] out_ecb;
56
  wire        load_ecb, busy_ecb;
57
 
58
  assign load_ecb = !reset && load_data;
59
  assign reset_ecb = load_ecb;
60
 
61
  gost89_ecb_encrypt
62
    ecb_encrypt(clk, reset_ecb, load_ecb, sbox, key, gamma, out_ecb, busy_ecb);
63
 
64
  always @(posedge clk) begin
65
    if (reset && !load_data) begin
66
      gamma <= in;
67
      busy <= 0;
68
    end
69
 
70
    if (!reset & load_data) begin
71
      in_value <= in;
72
      busy <= 1;
73
    end
74
 
75
    if (!reset && !load_data && !busy_ecb && busy) begin
76
      gamma <= out_ecb ^ in_value;
77
      out   <= out_ecb ^ in_value;
78
      busy  <= 0;
79
    end
80
  end
81
endmodule
82
 
83
module gost89_cfb_decrypt(
84
  input              clk,
85
  input              reset,
86
  input              load_data,
87
  input      [511:0] sbox,
88
  input      [255:0] key,
89
  input      [63:0]  in,
90
  output reg [63:0]  out,
91
  output reg         busy
92
);
93
  reg  [63:0] gamma;
94
  reg  [63:0] in_value;
95
  wire [63:0] out_ecb;
96
  wire        load_ecb, busy_ecb;
97
 
98
  assign load_ecb = !reset && load_data;
99
  assign reset_ecb = load_ecb;
100
 
101
  gost89_ecb_encrypt
102
    ecb_encrypt(clk, reset_ecb, load_ecb, sbox, key, gamma, out_ecb, busy_ecb);
103
 
104
  always @(posedge clk) begin
105
    if (reset && !load_data) begin
106
      gamma <= in;
107
      busy <= 0;
108
    end
109
 
110
    if (!reset & load_data) begin
111
      in_value <= in;
112
      busy <= 1;
113
    end
114
 
115
    if (!reset && !load_data && !busy_ecb && busy) begin
116
      gamma <= in_value;
117
      out   <= out_ecb ^ in_value;
118
      busy  <= 0;
119
    end
120
  end
121
endmodule

powered by: WebSVN 2.1.0

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