The Pedigree Project  0.1
system/include/pedigree/kernel/utilities/sha1/sha1.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /*
21  * sha1.h
22  *
23  * Copyright (C) 1998, 2009
24  * Paul E. Jones <paulej@packetizer.com>
25  * All Rights Reserved.
26  *
27  *****************************************************************************
28  * $Id: sha1.h 12 2009-06-22 19:34:25Z paulej $
29  *****************************************************************************
30  *
31  * Description:
32  * This class implements the Secure Hashing Standard as defined
33  * in FIPS PUB 180-1 published April 17, 1995.
34  *
35  * Many of the variable names in this class, especially the single
36  * character names, were used because those were the names used
37  * in the publication.
38  *
39  * Please read the file sha1.cpp for more information.
40  *
41  */
42 
43 #ifndef _SHA1_H_
44 #define _SHA1_H_
45 
46 #include "pedigree/kernel/processor/types.h"
47 
48 class SHA1
49 {
50  public:
51  SHA1();
52  virtual ~SHA1();
53 
54  /*
55  * Re-initialize the class
56  */
57  void Reset();
58 
59  /*
60  * Returns the message digest
61  */
62  bool Result(unsigned *message_digest_array);
63 
64  /*
65  * Provide input to SHA1
66  */
67  void Input(const unsigned char *message_array, unsigned length);
68  void Input(const char *message_array, unsigned length);
69  void Input(unsigned char message_element);
70  void Input(char message_element);
71  SHA1 &operator<<(const char *message_array);
72  SHA1 &operator<<(const unsigned char *message_array);
73  SHA1 &operator<<(const char message_element);
74  SHA1 &operator<<(const unsigned char message_element);
75 
76  private:
77  /*
78  * Process the next 512 bits of the message
79  */
80  void ProcessMessageBlock();
81 
82  /*
83  * Pads the current message block to 512 bits
84  */
85  void PadMessage();
86 
87  /*
88  * Performs a circular left shift operation
89  */
90  inline unsigned CircularShift(int bits, unsigned word);
91 
92  uint32_t H[5]; // Message digest buffers
93 
94  size_t Length_Low; // Message length in bits
95  size_t Length_High; // Message length in bits
96 
97  unsigned char Message_Block[64]; // 512-bit message blocks
98  int Message_Block_Index; // Index into message block array
99 
100  bool Computed; // Is the digest computed?
101  bool Corrupted; // Is the message digest corruped?
102 };
103 
104 #endif
Definition: Input.h:26
Definition: Result.h:36