4
* 2002-May-25 Jason Rohrer
5
* Changed to use minorGems endian.h
6
* Added a function for hashing an entire string to a hex digest.
7
* Added a function for getting a raw digest.
9
* 2003-September-15 Jason Rohrer
10
* Added support for hashing raw (non-string) data.
11
* Removed legacy C code.
19
* Originally taken from the public domain SHA1 implementation
20
* written by by Steve Reid <steve@edmweb.com>
22
* Modified by Aaron D. Gifford <agifford@infowest.com>
24
* NO COPYRIGHT - THIS IS 100% IN THE PUBLIC DOMAIN
26
* The original unmodified version is available at:
27
* ftp://ftp.funet.fi/pub/crypt/hash/sha/sha1.c
29
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND
30
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
33
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46
#include "minorGems/system/endian.h"
49
/* Make sure you define these types for your architecture: */
50
typedef unsigned int sha1_quadbyte; /* 4 byte type */
51
typedef unsigned char sha1_byte; /* single byte type */
54
* Be sure to get the above definitions right. For instance, on my
55
* x86 based FreeBSD box, I define LITTLE_ENDIAN and use the type
56
* "unsigned long" for the quadbyte. On FreeBSD on the Alpha, however,
57
* while I still use LITTLE_ENDIAN, I must define the quadbyte type
58
* as "unsigned int" instead.
61
#define SHA1_BLOCK_LENGTH 64
62
#define SHA1_DIGEST_LENGTH 20
64
/* The SHA1 structure: */
65
typedef struct _SHA_CTX {
66
sha1_quadbyte state[5];
67
sha1_quadbyte count[2];
68
sha1_byte buffer[SHA1_BLOCK_LENGTH];
73
void SHA1_Init(SHA_CTX *context);
74
void SHA1_Update(SHA_CTX *context, sha1_byte *data, unsigned int len);
75
void SHA1_Final(sha1_byte digest[SHA1_DIGEST_LENGTH], SHA_CTX* context);
80
* Computes a unencoded 20-byte digest from data.
82
* @param inData the data to hash.
83
* Must be destroyed by caller.
84
* @param inDataLength the length of the data to hash.
85
* Must be destroyed by caller.
87
* @return the digest as a byte array of length 20.
88
* Must be destroyed by caller.
90
unsigned char *computeRawSHA1Digest( unsigned char *inData, int inDataLength );
95
* Computes a unencoded 20-byte digest from an arbitrary string message.
97
* @param inString the message as a \0-terminated string.
98
* Must be destroyed by caller.
100
* @return the digest as a byte array of length 20.
101
* Must be destroyed by caller.
103
unsigned char *computeRawSHA1Digest( char *inString );
108
* Computes a hex-encoded string digest from data.
110
* @param inData the data to hash.
111
* Must be destroyed by caller.
112
* @param inDataLength the length of the data to hash.
113
* Must be destroyed by caller.
115
* @return the digest as a \0-terminated string.
116
* Must be destroyed by caller.
118
char *computeSHA1Digest( unsigned char *inData, int inDataLength );
123
* Computes a hex-encoded string digest from an arbitrary string message.
125
* @param inString the message as a \0-terminated string.
126
* Must be destroyed by caller.
128
* @return the digest as a \0-terminated string.
129
* Must be destroyed by caller.
131
char *computeSHA1Digest( char *inString );