Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
primitives
hashes
SHA1
SHA1.H
Go to the documentation of this file.
1
/*---------------------------------------------------------------------------*\
2
========= |
3
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4
\\ / O peration |
5
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6
\\/ M anipulation |
7
-------------------------------------------------------------------------------
8
License
9
This file is part of OpenFOAM.
10
11
OpenFOAM is free software: you can redistribute it and/or modify it
12
under the terms of the GNU General Public License as published by
13
the Free Software Foundation, either version 3 of the License, or
14
(at your option) any later version.
15
16
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19
for more details.
20
21
You should have received a copy of the GNU General Public License
22
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23
24
Class
25
Foam::SHA1
26
27
Description
28
Functions to compute SHA1 message digest according to the NIST
29
specification FIPS-180-1.
30
31
Adapted from the gnulib implementation.
32
33
SeeAlso
34
Foam::SHA1Digest
35
36
SourceFiles
37
SHA1I.H
38
SHA1.C
39
40
\*---------------------------------------------------------------------------*/
41
42
#ifndef SHA1_H
43
#define SHA1_H
44
45
#include <string>
46
#include <cstddef>
47
#include <stdint.h>
// C++0x uses <cstdint>
48
49
#include "
SHA1Digest.H
"
50
51
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52
53
namespace
Foam
54
{
55
56
// Forward declaration of classes
57
class
Ostream;
58
59
// Forward declaration of friend functions and operators
60
class
SHA1;
61
class
SHA1Digest;
62
Ostream&
operator<<
(Ostream&,
const
SHA1&);
63
64
65
/*---------------------------------------------------------------------------*\
66
Class SHA1 Declaration
67
\*---------------------------------------------------------------------------*/
68
69
class
SHA1
70
{
71
// Private data
72
73
//- Track if the hashsum has been finalized (added count, etc)
74
bool
finalized_;
75
76
//- The hash sums
77
uint32_t hashsumA_;
78
uint32_t hashsumB_;
79
uint32_t hashsumC_;
80
uint32_t hashsumD_;
81
uint32_t hashsumE_;
82
83
//- The total number processed, saved as 64-bit
84
uint32_t bufTotal_[2];
85
86
//- The number of elements pending in the buffer
87
uint32_t bufLen_;
88
89
//- The input processing buffer
90
uint32_t buffer_[32];
91
92
// Private Member Functions
93
94
//- Swap bytes from internal to network (big-endian) order
95
static
inline
uint32_t swapBytes(uint32_t);
96
97
//- Copy the 4-byte value into the memory location pointed to by *dst.
98
// If the architecture allows unaligned access this is equivalent to
99
// *(uint32_t *) cp = val
100
static
inline
void
set_uint32(
unsigned
char
*
cp
, uint32_t);
101
102
//- Process data block-wise, LEN must be a multiple of 64!
103
void
processBlock(
const
void
*data,
size_t
len);
104
105
//- Process for the next LEN bytes, LEN need not be a multiple of 64.
106
void
processBytes(
const
void
*data,
size_t
len);
107
108
//- Calculate current digest from appended data.
109
void
calcDigest(
SHA1Digest
&)
const
;
110
111
public
:
112
113
// Constructors
114
115
//- Construct null
116
inline
SHA1
();
117
118
//- Construct and append initial std::string
119
explicit
inline
SHA1
(
const
std::string&);
120
121
//- Construct and append initial string
122
explicit
inline
SHA1
(
const
char
*);
123
124
// Member Functions
125
126
//- Reset the hashed data before appending more
127
void
clear
();
128
129
//- Append data for processing
130
inline
SHA1
&
append
(
const
char
* data,
size_t
len);
131
132
//- Append string for processing
133
inline
SHA1
&
append
(
const
std::string&);
134
135
//- Append string for processing
136
inline
SHA1
&
append
(
const
char
* str);
137
138
//- Finalized the calculations (normally not needed directly).
139
// Returns false if no bytes were passed for processing
140
bool
finalize
();
141
142
//- Calculate current digest from appended data.
143
SHA1Digest
digest
()
const
;
144
145
146
// Member Operators
147
148
//- Equality operator
149
inline
bool
operator==
(
const
SHA1Digest
&)
const
;
150
151
//- Inequality operator
152
inline
bool
operator!=
(
const
SHA1Digest
&)
const
;
153
154
//- Equality operator
155
inline
bool
operator==
(
const
SHA1
&)
const
;
156
157
//- Inequality operator
158
inline
bool
operator!=
(
const
SHA1
&)
const
;
159
160
//- Convert to a digest, calculate current digest from appended data.
161
inline
operator
SHA1Digest
()
const
;
162
163
// Friend Functions
164
165
// Friend Operators
166
167
inline
friend
Ostream
&
operator<<
(
Ostream
&,
const
SHA1
&);
168
169
};
170
171
172
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173
174
}
// End namespace Foam
175
176
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177
178
#include "
SHA1I.H
"
179
180
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181
182
#endif
183
184
// ************************ vim: set sw=4 sts=4 et: ************************ //