OpenCores
URL https://opencores.org/ocsvn/sha3/sha3/trunk

Subversion Repositories sha3

[/] [sha3/] [trunk/] [low_throughput_core/] [rtl/] [keccak.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 homer.hsin
/*
2
 * Copyright 2013, Homer Hsing <homer.hsing@gmail.com>
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
/* "is_last" == 0 means byte number is 8, no matter what value "byte_num" is. */
18
/* if "in_ready" == 0, then "is_last" should be 0. */
19
/* the user switch to next "in" only if "ack" == 1. */
20
 
21
`define low_pos(w,b)      ((w)*64 + (b)*8)
22
`define low_pos2(w,b)     `low_pos(w,7-b)
23
`define high_pos(w,b)     (`low_pos(w,b) + 7)
24
`define high_pos2(w,b)    (`low_pos2(w,b) + 7)
25
 
26
module keccak(clk, reset, in, in_ready, is_last, byte_num, buffer_full, out, out_ready);
27
    input              clk, reset;
28
    input      [31:0]  in;
29
    input              in_ready, is_last;
30
    input      [1:0]   byte_num;
31
    output             buffer_full; /* to "user" module */
32
    output     [511:0] out;
33
    output reg         out_ready;
34
 
35
    reg                state;     /* state == 0: user will send more input data
36
                                   * state == 1: user will not send any data */
37
    wire       [575:0] padder_out,
38
                       padder_out_1; /* before reorder byte */
39
    wire               padder_out_ready;
40
    wire               f_ack;
41
    wire      [1599:0] f_out;
42
    wire               f_out_ready;
43
    wire       [511:0] out1;      /* before reorder byte */
44
    reg        [22:0]  i;         /* gen "out_ready" */
45
 
46
    genvar w, b;
47
 
48
    assign out1 = f_out[1599:1599-511];
49
 
50
    always @ (posedge clk)
51
      if (reset)
52
        i <= 0;
53
      else
54
        i <= {i[21:0], state & f_ack};
55
 
56
    always @ (posedge clk)
57
      if (reset)
58
        state <= 0;
59
      else if (is_last)
60
        state <= 1;
61
 
62
    /* reorder byte ~ ~ */
63
    generate
64
      for(w=0; w<8; w=w+1)
65
        begin : L0
66
          for(b=0; b<8; b=b+1)
67
            begin : L1
68
              assign out[`high_pos(w,b):`low_pos(w,b)] = out1[`high_pos2(w,b):`low_pos2(w,b)];
69
            end
70
        end
71
    endgenerate
72
 
73
    /* reorder byte ~ ~ */
74
    generate
75
      for(w=0; w<9; w=w+1)
76
        begin : L2
77
          for(b=0; b<8; b=b+1)
78
            begin : L3
79
              assign padder_out[`high_pos(w,b):`low_pos(w,b)] = padder_out_1[`high_pos2(w,b):`low_pos2(w,b)];
80
            end
81
        end
82
    endgenerate
83
 
84
    always @ (posedge clk)
85
      if (reset)
86
        out_ready <= 0;
87
      else if (i[22])
88
        out_ready <= 1;
89
 
90
    padder
91
      padder_ (clk, reset, in, in_ready, is_last, byte_num, buffer_full, padder_out_1, padder_out_ready, f_ack);
92
 
93
    f_permutation
94
      f_permutation_ (clk, reset, padder_out, padder_out_ready, f_ack, f_out, f_out_ready);
95
endmodule
96
 
97
`undef low_pos
98
`undef low_pos2
99
`undef high_pos
100
`undef high_pos2

powered by: WebSVN 2.1.0

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