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

Subversion Repositories sha3

[/] [sha3/] [trunk/] [low_throughput_core/] [rtl/] [f_permutation.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
/* if "ack" is 1, then current input has been used. */
18
 
19
module f_permutation(clk, reset, in, in_ready, ack, out, out_ready);
20
    input               clk, reset;
21
    input      [575:0]  in;
22
    input               in_ready;
23
    output              ack;
24
    output reg [1599:0] out;
25
    output reg          out_ready;
26
 
27
    reg        [22:0]   i; /* select round constant */
28
    wire       [1599:0] round_in, round_out;
29
    wire       [63:0]   rc; /* round constant */
30
    wire                update;
31
    wire                accept;
32
    reg                 calc; /* == 1: calculating rounds */
33
 
34
    assign accept = in_ready & (~ calc); // in_ready & (i == 0)
35
 
36
    always @ (posedge clk)
37
      if (reset) i <= 0;
38
      else       i <= {i[21:0], accept};
39
 
40
    always @ (posedge clk)
41
      if (reset) calc <= 0;
42
      else       calc <= (calc & (~ i[22])) | accept;
43
 
44
    assign update = calc | accept;
45
 
46
    assign ack = accept;
47
 
48
    always @ (posedge clk)
49
      if (reset)
50
        out_ready <= 0;
51
      else if (accept)
52
        out_ready <= 0;
53
      else if (i[22]) // only change at the last round
54
        out_ready <= 1;
55
 
56
    assign round_in = accept ? {in ^ out[1599:1599-575], out[1599-576:0]} : out;
57
 
58
    rconst
59
      rconst_ ({i, accept}, rc);
60
 
61
    round
62
      round_ (round_in, rc, round_out);
63
 
64
    always @ (posedge clk)
65
      if (reset)
66
        out <= 0;
67
      else if (update)
68
        out <= round_out;
69
endmodule

powered by: WebSVN 2.1.0

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