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
48class SHA1 {
49 public:
50 SHA1();
51 virtual ~SHA1();
52
53 /*
54 * Re-initialize the class
55 */
56 void Reset();
57
58 /*
59 * Returns the message digest
60 */
61 bool Result(unsigned* message_digest_array);
62
63 /*
64 * Provide input to SHA1
65 */
66 void Input(const unsigned char* message_array, unsigned length);
67 void Input(const char* message_array, unsigned length);
68 void Input(unsigned char message_element);
69 void Input(char message_element);
70 SHA1& operator<<(const char* message_array);
71 SHA1& operator<<(const unsigned char* message_array);
72 SHA1& operator<<(const char message_element);
73 SHA1& operator<<(const unsigned char message_element);
74
75 private:
76 /*
77 * Process the next 512 bits of the message
78 */
79 void ProcessMessageBlock();
80
81 /*
82 * Pads the current message block to 512 bits
83 */
84 void PadMessage();
85
86 /*
87 * Performs a circular left shift operation
88 */
89 inline unsigned CircularShift(int bits, unsigned word);
90
91 uint32_t H[5]; // Message digest buffers
92
93 size_t Length_Low; // Message length in bits
94 size_t Length_High; // Message length in bits
95
96 unsigned char Message_Block[64]; // 512-bit message blocks
97 int Message_Block_Index; // Index into message block array
98
99 bool Computed; // Is the digest computed?
100 bool Corrupted; // Is the message digest corruped?
101};
102
103#endif