~ubuntu-branches/ubuntu/precise/primrose/precise

« back to all changes in this revision

Viewing changes to minorGems/crypto/hashes/sha1.h

  • Committer: Bazaar Package Importer
  • Author(s): Paul Wise
  • Date: 2009-04-06 19:26:56 UTC
  • Revision ID: james.westby@ubuntu.com-20090406192656-cri7503gebyvfl8t
Tags: upstream-5+dfsg1
ImportĀ upstreamĀ versionĀ 5+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Modification History
 
3
 *
 
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.
 
8
 *
 
9
 * 2003-September-15   Jason Rohrer
 
10
 * Added support for hashing raw (non-string) data.
 
11
 * Removed legacy C code.
 
12
 */
 
13
 
 
14
 
 
15
 
 
16
/*
 
17
 * sha.h
 
18
 *
 
19
 * Originally taken from the public domain SHA1 implementation
 
20
 * written by by Steve Reid <steve@edmweb.com>
 
21
 * 
 
22
 * Modified by Aaron D. Gifford <agifford@infowest.com>
 
23
 *
 
24
 * NO COPYRIGHT - THIS IS 100% IN THE PUBLIC DOMAIN
 
25
 *
 
26
 * The original unmodified version is available at:
 
27
 *    ftp://ftp.funet.fi/pub/crypt/hash/sha/sha1.c
 
28
 *
 
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
 
39
 * SUCH DAMAGE.
 
40
 */
 
41
 
 
42
#ifndef __SHA1_H__
 
43
#define __SHA1_H__
 
44
 
 
45
 
 
46
#include "minorGems/system/endian.h"
 
47
 
 
48
    
 
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 */
 
52
 
 
53
/*
 
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.
 
59
 */
 
60
 
 
61
#define SHA1_BLOCK_LENGTH       64
 
62
#define SHA1_DIGEST_LENGTH      20
 
63
 
 
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];
 
69
} SHA_CTX;
 
70
 
 
71
 
 
72
 
 
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);
 
76
 
 
77
 
 
78
 
 
79
/**
 
80
 * Computes a unencoded 20-byte digest from data.
 
81
 *
 
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.
 
86
 *
 
87
 * @return the digest as a byte array of length 20.
 
88
 *   Must be destroyed by caller.
 
89
 */
 
90
unsigned char *computeRawSHA1Digest( unsigned char *inData, int inDataLength );
 
91
 
 
92
 
 
93
 
 
94
/**
 
95
 * Computes a unencoded 20-byte digest from an arbitrary string message.
 
96
 *
 
97
 * @param inString the message as a \0-terminated string.
 
98
 *   Must be destroyed by caller.
 
99
 *
 
100
 * @return the digest as a byte array of length 20.
 
101
 *   Must be destroyed by caller.
 
102
 */
 
103
unsigned char *computeRawSHA1Digest( char *inString );
 
104
 
 
105
 
 
106
    
 
107
/**
 
108
 * Computes a hex-encoded string digest from data.
 
109
 *
 
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.
 
114
 *
 
115
 * @return the digest as a \0-terminated string.
 
116
 *   Must be destroyed by caller.
 
117
 */
 
118
char *computeSHA1Digest( unsigned char *inData, int inDataLength );
 
119
 
 
120
 
 
121
    
 
122
/**
 
123
 * Computes a hex-encoded string digest from an arbitrary string message.
 
124
 *
 
125
 * @param inString the message as a \0-terminated string.
 
126
 *   Must be destroyed by caller.
 
127
 *
 
128
 * @return the digest as a \0-terminated string.
 
129
 *   Must be destroyed by caller.
 
130
 */
 
131
char *computeSHA1Digest( char *inString );
 
132
 
 
133
 
 
134
 
 
135
#endif
 
136