annotate Resources/sha1/sha1.h @ 344:cd6749e53a03

anonymization from orthanc explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Jan 2013 13:23:26 +0100
parents 81b6f3013738
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
177
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /*
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * sha1.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Copyright (C) 1998, 2009
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Paul E. Jones <paulej@packetizer.com>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * All Rights Reserved.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *****************************************************************************
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * $Id: sha1.h 12 2009-06-22 19:34:25Z paulej $
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *****************************************************************************
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * Description:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This class implements the Secure Hashing Standard as defined
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * in FIPS PUB 180-1 published April 17, 1995.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Many of the variable names in this class, especially the single
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * character names, were used because those were the names used
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * in the publication.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * Please read the file sha1.cpp for more information.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 */
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #ifndef _SHA1_H_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #define _SHA1_H_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 class SHA1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 SHA1();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 virtual ~SHA1();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 /*
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 * Re-initialize the class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 */
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 void Reset();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 /*
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 * Returns the message digest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 */
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 bool Result(unsigned *message_digest_array);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 /*
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 * Provide input to SHA1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 */
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 void Input( const unsigned char *message_array,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 unsigned length);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 void Input( const char *message_array,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 unsigned length);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 void Input(unsigned char message_element);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 void Input(char message_element);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 SHA1& operator<<(const char *message_array);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 SHA1& operator<<(const unsigned char *message_array);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 SHA1& operator<<(const char message_element);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 SHA1& operator<<(const unsigned char message_element);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 /*
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 * Process the next 512 bits of the message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 */
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 void ProcessMessageBlock();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 /*
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 * Pads the current message block to 512 bits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 */
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 void PadMessage();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 /*
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 * Performs a circular left shift operation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 */
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 inline unsigned CircularShift(int bits, unsigned word);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 unsigned H[5]; // Message digest buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 unsigned Length_Low; // Message length in bits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 unsigned Length_High; // Message length in bits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 unsigned char Message_Block[64]; // 512-bit message blocks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 int Message_Block_Index; // Index into message block array
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 bool Computed; // Is the digest computed?
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 bool Corrupted; // Is the message digest corruped?
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 #endif