summaryrefslogtreecommitdiffhomepage
path: root/Stars45/Sha1.h
blob: 8b042cbbec1d24fdade4c778225f08806b23f809 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
*    Sha1.h
*
*    Copyright (C) 1998
*    Paul E. Jones <paulej@acm.org>
*    All Rights Reserved.
*
*****************************************************************************
*    $Id: sha1.h,v 1.4 2001/03/20 06:25:06 paulej Exp $
*****************************************************************************
*
*    Description:
*         This class implements the Secure Hashing Standard as defined
*         in FIPS PUB 180-1 published April 17, 1995.
*
*        Many of the variable names in this class, especially the single
*        character names, were used because those were the names used
*        in the publication.
*
*         Please read the file sha1.cpp for more information.
*
*/

#ifndef _SHA1_H_
#define _SHA1_H_

class SHA1
{

public:

    SHA1();
    virtual ~SHA1();

    /*
        *    Re-initialize the class
        */
    void Reset();

    /*
        *    Returns the message digest
        */
    bool Result(unsigned *message_digest_array);

    /*
        *    Provide input to SHA1
        */
    void Input(    const unsigned char    *message_array,
    unsigned            length);
    void Input(    const char    *message_array,
    unsigned    length);
    void Input(unsigned char message_element);
    void Input(char message_element);
    SHA1& operator<<(const char *message_array);
    SHA1& operator<<(const unsigned char *message_array);
    SHA1& operator<<(const char message_element);
    SHA1& operator<<(const unsigned char message_element);

private:

    /*
        *    Process the next 512 bits of the message
        */
    void ProcessMessageBlock();

    /*
        *    Pads the current message block to 512 bits
        */
    void PadMessage();

    /*
        *    Performs a circular left shift operation
        */
    inline unsigned CircularShift(int bits, unsigned word);

    unsigned H[5];                        // Message digest buffers

    unsigned Length_Low;                // Message length in bits
    unsigned Length_High;                // Message length in bits

    unsigned char Message_Block[64];    // 512-bit message blocks
    int Message_Block_Index;            // Index into message block array

    bool Computed;                        // Is the digest computed?
    bool Corrupted;                        // Is the message digest corruped?
    
};

#endif