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

Subversion Repositories sha3

[/] [sha3/] [trunk/] [low_throughput_core/] [rtl/] [padder.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 4, 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
module padder(clk, reset, in, in_ready, is_last, byte_num, buffer_full, out, out_ready, f_ack);
22
    input              clk, reset;
23
    input      [31:0]  in;
24
    input              in_ready, is_last;
25
    input      [1:0]   byte_num;
26
    output             buffer_full; /* to "user" module */
27
    output reg [575:0] out;         /* to "f_permutation" module */
28
    output             out_ready;   /* to "f_permutation" module */
29
    input              f_ack;       /* from "f_permutation" module */
30
 
31
    reg                state;       /* state == 0: user will send more input data
32
                                     * state == 1: user will not send any data */
33
    reg                done;        /* == 1: out_ready should be 0 */
34
    reg        [17:0]  i;           /* length of "out" buffer */
35
    wire       [31:0]  v0;          /* output of module "padder1" */
36
    reg        [31:0]  v1;          /* to be shifted into register "out" */
37
    wire               accept,      /* accept user input? */
38
                       update;
39
 
40
    assign buffer_full = i[17];
41
    assign out_ready = buffer_full;
42
    assign accept = (~ state) & in_ready & (~ buffer_full); // if state == 1, do not eat input
43
    assign update = (accept | (state & (~ buffer_full))) & (~ done); // don't fill buffer if done
44
 
45
    always @ (posedge clk)
46
      if (reset)
47
        out <= 0;
48
      else if (update)
49
        out <= {out[575-32:0], v1};
50
 
51
    always @ (posedge clk)
52
      if (reset)
53
        i <= 0;
54
      else if (f_ack | update)
55
        i <= {i[16:0], 1'b1} & {18{~ f_ack}};
56
/*    if (f_ack)  i <= 0; */
57
/*    if (update) i <= {i[16:0], 1'b1}; // increase length */
58
 
59
    always @ (posedge clk)
60
      if (reset)
61
        state <= 0;
62
      else if (is_last)
63
        state <= 1;
64
 
65
    always @ (posedge clk)
66
      if (reset)
67
        done <= 0;
68
      else if (state & out_ready)
69
        done <= 1;
70
 
71
    padder1 p0 (in, byte_num, v0);
72
 
73
    always @ (*)
74
      begin
75
        if (state)
76
          begin
77
            v1 = 0;
78
            v1[7] = v1[7] | i[16]; // "v1[7]" is the MSB of the last byte of "v1"
79
          end
80
        else if (is_last == 0)
81
          v1 = in;
82
        else
83
          begin
84
            v1 = v0;
85
            v1[7] = v1[7] | i[16];
86
          end
87
      end
88
endmodule

powered by: WebSVN 2.1.0

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