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

Subversion Repositories sha3

[/] [sha3/] [trunk/] [high_throughput_core/] [rtl/] [keccak.v] - Blame information for rev 8

Go to most recent revision | 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      [63:0]  in;
29
    input              in_ready, is_last;
30
    input      [2: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        [10:0]  i;         /* gen "out_ready" */
45
    genvar w, b;
46
 
47
    assign out1 = f_out[1599:1599-511];
48
 
49
    always @ (posedge clk)
50
      if (reset)
51
        i <= 0;
52
      else
53
        i <= {i[9:0], state & f_ack};
54
 
55
    always @ (posedge clk)
56
      if (reset)
57
        state <= 0;
58
      else if (is_last)
59
        state <= 1;
60
 
61
    /* reorder byte ~ ~ */
62
    generate
63
      for(w=0; w<8; w=w+1)
64
        begin : L0
65
          for(b=0; b<8; b=b+1)
66
            begin : L1
67
              assign out[`high_pos(w,b):`low_pos(w,b)] = out1[`high_pos2(w,b):`low_pos2(w,b)];
68
            end
69
        end
70
    endgenerate
71
 
72
    generate
73
      for(w=0; w<9; w=w+1)
74
        begin : L2
75
          for(b=0; b<8; b=b+1)
76
            begin : L3
77
              assign padder_out[`high_pos(w,b):`low_pos(w,b)] = padder_out_1[`high_pos2(w,b):`low_pos2(w,b)];
78
            end
79
        end
80
    endgenerate
81
 
82
    always @ (posedge clk)
83
      if (reset)
84
        out_ready <= 0;
85
      else if (i[10])
86
        out_ready <= 1;
87
 
88
    padder
89
      padder_ (clk, reset, in, in_ready, is_last, byte_num, buffer_full, padder_out_1, padder_out_ready, f_ack);
90
 
91
    f_permutation
92
      f_permutation_ (clk, reset, padder_out, padder_out_ready, f_ack, f_out, f_out_ready);
93
endmodule
94
 
95
`undef low_pos
96
`undef low_pos2
97
`undef high_pos
98
`undef high_pos2

powered by: WebSVN 2.1.0

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