1
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* Modified by Barry Leslie on 10/21/08.
20
* I have put a C++ wrapper around the data and functions to create an sha1 class.
24
Original Source from: http://www.faqs.org/rfcs/rfc3174.html
25
and MySQL mysys/sha1.c build 5.1.24.
28
This file implements the Secure Hashing Algorithm 1 as
29
defined in FIPS PUB 180-1 published April 17, 1995.
31
The SHA-1, produces a 160-bit message digest for a given data
32
stream. It should take about 2**n steps to find a message with the
33
same digest as a given message and 2**(n/2) to find any two
34
messages with the same digest, when n is the digest size in bits.
35
Therefore, this algorithm can serve as a means of providing a
36
"fingerprint" for a message.
39
SHA-1 is defined in terms of 32-bit "words". This code uses
40
<stdint.h> (included via "sha1.h" to define 32 and 8 bit unsigned
41
integer types. If your C compiler does not support 32 bit unsigned
42
integers, this code is not appropriate.
45
SHA-1 is designed to work with messages less than 2^64 bits long.
46
Although SHA-1 allows a message digest to be generated for messages
47
of any number of bits less than 2^64, this implementation only
48
works with messages with a length that is a multiple of the size of
58
#define SHA1_HASH_SIZE 20
61
uint8_t val[SHA1_HASH_SIZE];
64
class CSSha1 : public CSObject {
67
uint64_t Length; // Message length in bits
68
uint32_t Intermediate_Hash[SHA1_HASH_SIZE/4]; // Message Digest
69
bool Computed; // Is the digest computed?
70
int16_t Message_Block_Index; // Index into message block array
71
uint8_t Message_Block[64]; // 512-bit message blocks
77
CSSha1() {sha1_reset();}
80
void sha1_input(const void *data, size_t len);
81
void sha1_digest(Sha1Digest *digest);
85
#endif // __CSSHA1_H__