RigsofRods
Soft-body Physics Simulation
SHA1.h
Go to the documentation of this file.
1 /*
2  100% free public domain implementation of the SHA-1 algorithm
3  by Dominik Reichl <dominik.reichl@t-online.de>
4  Web: http://www.dominik-reichl.de/
5 
6  This version is modified for Rigs of Rods project
7  https://sourceforge.net/projects/rigsofrods/
8 
9  Version 1.6 - 2005-02-07 (thanks to Howard Kapustein for patches)
10  - You can set the endianness in your files, no need to modify the
11  header file of the CSHA1 class any more
12  - Aligned data support
13  - Made support/compilation of the utility functions (ReportHash
14  and HashFile) optional (useful, if bytes count, for example in
15  embedded environments)
16 
17  Version 1.5 - 2005-01-01
18  - 64-bit compiler compatibility added
19  - Made variable wiping optional (define SHA1_WIPE_VARIABLES)
20  - Removed unnecessary variable initializations
21  - ROL32 improvement for the Microsoft compiler (using _rotl)
22 
23  ======== Test Vectors (from FIPS PUB 180-1) ========
24 
25  SHA1("abc") =
26  A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
27 
28  SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
29  84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
30 
31  SHA1(A million repetitions of "a") =
32  34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
33 */
34 
35 #pragma once
36 
37 #include "Application.h"
38 
39 #include <stdint.h> //"pstdint.h" // Needed for uint32_t, uint8_t
40 
41 #if !defined(SHA1_UTILITY_FUNCTIONS) && !defined(SHA1_NO_UTILITY_FUNCTIONS)
42 #define SHA1_UTILITY_FUNCTIONS
43 #endif
44 
45 #include <memory.h> // Needed for memset and memcpy
46 
47 #ifdef SHA1_UTILITY_FUNCTIONS
48 #include <stdio.h> // Needed for file access and sprintf
49 #include <string.h> // Needed for strcat and strcpy
50 #endif
51 
52 #ifdef _MSC_VER
53 #include <stdlib.h>
54 #endif
55 
56 // You can define the endian mode in your files, without modifying the SHA1
57 // source files. Just #define SHA1_LITTLE_ENDIAN or #define SHA1_BIG_ENDIAN
58 // in your files, before including the SHA1.h header file. If you don't
59 // define anything, the class defaults to little endian.
60 
61 #if !defined(SHA1_LITTLE_ENDIAN) && !defined(SHA1_BIG_ENDIAN)
62 #define SHA1_LITTLE_ENDIAN
63 #endif
64 
65 // Same here. If you want variable wiping, #define SHA1_WIPE_VARIABLES, if
66 // not, #define SHA1_NO_WIPE_VARIABLES. If you don't define anything, it
67 // defaults to wiping.
68 
69 #if !defined(SHA1_WIPE_VARIABLES) && !defined(SHA1_NO_WIPE_VARIABLES)
70 #define SHA1_WIPE_VARIABLES
71 #endif
72 
74 // Declare SHA1 workspace
75 
76 typedef union
77 {
78  uint8_t c[64];
79  uint32_t l[16];
81 
82 namespace RoR {
83 
84 class CSHA1
85 {
86 public:
87 
88  // Constructor and Destructor
89  CSHA1();
90  ~CSHA1();
91 
92  uint32_t m_state[5];
93  uint32_t m_count[2];
94  uint32_t __reserved1[1];
95  uint8_t m_buffer[64];
96  uint8_t m_digest[20];
97  uint32_t __reserved2[3];
98 
99  void Reset();
100 
101  // Update the hash value
102  void UpdateHash(uint8_t* data, uint32_t len);
103 
104  // Finalize hash and report
105  void Final();
106 
107  // Report functions: as pre-formatted and raw data
108 #ifdef SHA1_UTILITY_FUNCTIONS
109  std::string ReportHash();
110 #endif
111  void GetHash(uint8_t* puDest);
112 
113 private:
114  // Private SHA-1 transformation
115  void Transform(uint32_t* state, uint8_t* buffer);
116 
117  // Member variables
118  uint8_t m_workspace[64];
119  SHA1_WORKSPACE_BLOCK* m_block; // SHA1 pointer to the byte array above
120 };
121 
122 }; //namespace RoR
123 
RoR::CSHA1::Final
void Final()
Definition: SHA1.cpp:168
RoR::CSHA1::__reserved1
uint32_t __reserved1[1]
Definition: SHA1.h:94
RoR::CSHA1::m_digest
uint8_t m_digest[20]
Definition: SHA1.h:96
RoR::CSHA1
Definition: SHA1.h:84
RoR::CSHA1::~CSHA1
~CSHA1()
Definition: SHA1.cpp:82
RoR::CSHA1::m_block
SHA1_WORKSPACE_BLOCK * m_block
Definition: SHA1.h:119
RoR::CSHA1::m_count
uint32_t m_count[2]
Definition: SHA1.h:93
RoR::CSHA1::__reserved2
uint32_t __reserved2[3]
Definition: SHA1.h:97
Application.h
Central state/object manager and communications hub.
RoR::CSHA1::Reset
void Reset()
Definition: SHA1.cpp:87
RoR::CSHA1::UpdateHash
void UpdateHash(uint8_t *data, uint32_t len)
Definition: SHA1.cpp:143
SHA1_WORKSPACE_BLOCK
Definition: SHA1.h:76
RoR::CSHA1::m_state
uint32_t m_state[5]
Definition: SHA1.h:92
RoR::CSHA1::ReportHash
std::string ReportHash()
Definition: SHA1.cpp:202
RoR::CSHA1::m_workspace
uint8_t m_workspace[64]
Definition: SHA1.h:118
RoR::CSHA1::Transform
void Transform(uint32_t *state, uint8_t *buffer)
Definition: SHA1.cpp:100
RoR::CSHA1::m_buffer
uint8_t m_buffer[64]
Definition: SHA1.h:95
RoR::CSHA1::GetHash
void GetHash(uint8_t *puDest)
Definition: SHA1.cpp:219
RoR
Definition: AppContext.h:36
RoR::CSHA1::CSHA1
CSHA1()
Definition: SHA1.cpp:69