OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [hdl/] [sha1/] [sha1_round.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
///////////////////////////////////////////////////////////////
2
// sha1_round.v  version 0.1           
3
//
4
// Primitive SHA1 Round
5
//
6
// Described in Stalling, page 284
7
//
8
// Paul Hartke, phartke@stanford.edu,  Copyright (c)2002
9
//
10
// The information and description contained herein is the
11
// property of Paul Hartke.
12
//
13
// Permission is granted for any reuse of this information
14
// and description as long as this copyright notice is
15
// preserved.  Modifications may be made as long as this
16
// notice is preserved.
17
// This code is made available "as is".  There is no warranty,
18
// so use it at your own risk.
19
// Documentation? "Use the source, Luke!"
20
///////////////////////////////////////////////////////////////
21
 
22
module sha1_round (cv_in, w, round, cv_out);
23
 
24
   input [159:0] cv_in;
25
   input [31:0]  w;
26
   input [6:0]   round;
27
   output [159:0] cv_out;
28
 
29
   reg [31:0]     k;
30
   reg [31:0]     f;
31
   wire [31:0]    a_shift;
32
   wire [31:0]    b_shift;
33
   wire [31:0]    add_result;
34
 
35
   wire [31:0]    a = cv_in[159:128];
36
   wire [31:0]    b = cv_in[127:96];
37
   wire [31:0]    c = cv_in[95:64];
38
   wire [31:0]    d = cv_in[63:32];
39
   wire [31:0]    e = cv_in[31:0];
40
 
41
   // Perhaps this should be a case statement?
42
   // I want it to create 4 parallel comparators...
43
   always @(round)
44
     begin
45
        k = 32'd0;
46
        if ((round >= 7'd0) && (round <= 7'd19))
47
          k = 32'h5A827999;
48
        if ((round >= 7'd20) && (round <= 7'd39))
49
          k = 32'h6ED9EBA1;
50
        if ((round >= 7'd40) && (round <= 7'd59))
51
          k = 32'h8F1BBCDC;
52
        if ((round >= 7'd60) && (round <= 7'd79))
53
          k = 32'hCA62C1D6;
54
     end // always @ (round)
55
 
56
   // Perhaps this should be a case statement?
57
   // I want it to create 4 parallel comparators...
58
   always @(round or b or c or d)
59
     begin
60
        f = 32'd0;
61
        if ((round >= 7'd0) && (round <= 7'd19))
62
          f = ((b & c) | (~b & d));
63
        if ((round >= 7'd20) && (round <= 7'd39))
64
          f = (b ^ c ^ d);
65
        if ((round >= 7'd40) && (round <= 7'd59))
66
          f = ((b & c) | (b & d) | (c & d));
67
        if ((round >= 7'd60) && (round <= 7'd79))
68
          f = (b ^ c ^ d);
69
     end // always @ (round or b or c or d)
70
 
71
   assign a_shift = {a[26:0], a[31:27]};
72
   assign b_shift = {b[1:0], b[31:2]};
73
 
74
   // Attempt to group early signals early...
75
   // e and w come from register outputs
76
   // k is 6 bit comparator & mux delay
77
   // f is 6 bit comparator & mux delay & computation
78
   // a is shift 5 from previous round
79
   assign add_result = (a_shift + ((f + k) + (e + w)));
80
   assign cv_out = {add_result, a, b_shift, c, d};
81
 
82
endmodule // sha1_round
83
 

powered by: WebSVN 2.1.0

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