sl@0
|
1 |
/* crypto/sha/sha.h */
|
sl@0
|
2 |
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
*
|
sl@0
|
5 |
* This package is an SSL implementation written
|
sl@0
|
6 |
* by Eric Young (eay@cryptsoft.com).
|
sl@0
|
7 |
* The implementation was written so as to conform with Netscapes SSL.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is free for commercial and non-commercial use as long as
|
sl@0
|
10 |
* the following conditions are aheared to. The following conditions
|
sl@0
|
11 |
* apply to all code found in this distribution, be it the RC4, RSA,
|
sl@0
|
12 |
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
sl@0
|
13 |
* included with this distribution is covered by the same copyright terms
|
sl@0
|
14 |
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
sl@0
|
15 |
*
|
sl@0
|
16 |
* Copyright remains Eric Young's, and as such any Copyright notices in
|
sl@0
|
17 |
* the code are not to be removed.
|
sl@0
|
18 |
* If this package is used in a product, Eric Young should be given attribution
|
sl@0
|
19 |
* as the author of the parts of the library used.
|
sl@0
|
20 |
* This can be in the form of a textual message at program startup or
|
sl@0
|
21 |
* in documentation (online or textual) provided with the package.
|
sl@0
|
22 |
*
|
sl@0
|
23 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
24 |
* modification, are permitted provided that the following conditions
|
sl@0
|
25 |
* are met:
|
sl@0
|
26 |
* 1. Redistributions of source code must retain the copyright
|
sl@0
|
27 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
28 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
29 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
30 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
31 |
* 3. All advertising materials mentioning features or use of this software
|
sl@0
|
32 |
* must display the following acknowledgement:
|
sl@0
|
33 |
* "This product includes cryptographic software written by
|
sl@0
|
34 |
* Eric Young (eay@cryptsoft.com)"
|
sl@0
|
35 |
* The word 'cryptographic' can be left out if the rouines from the library
|
sl@0
|
36 |
* being used are not cryptographic related :-).
|
sl@0
|
37 |
* 4. If you include any Windows specific code (or a derivative thereof) from
|
sl@0
|
38 |
* the apps directory (application code) you must include an acknowledgement:
|
sl@0
|
39 |
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
sl@0
|
40 |
*
|
sl@0
|
41 |
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
sl@0
|
42 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
43 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
44 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
sl@0
|
45 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
sl@0
|
46 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
sl@0
|
47 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
48 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
sl@0
|
49 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
sl@0
|
50 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
sl@0
|
51 |
* SUCH DAMAGE.
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* The licence and distribution terms for any publically available version or
|
sl@0
|
54 |
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
sl@0
|
55 |
* copied and put under another distribution licence
|
sl@0
|
56 |
* [including the GNU Public Licence.]
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
/*
|
sl@0
|
59 |
© Portions copyright (c) 2006-2010 Nokia Corporation. All rights reserved.
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
|
sl@0
|
62 |
#ifndef HEADER_SHA_H
|
sl@0
|
63 |
#define HEADER_SHA_H
|
sl@0
|
64 |
|
sl@0
|
65 |
#if (defined(__SYMBIAN32__) && !defined(SYMBIAN))
|
sl@0
|
66 |
#define SYMBIAN
|
sl@0
|
67 |
#endif
|
sl@0
|
68 |
|
sl@0
|
69 |
#ifdef SYMBIAN
|
sl@0
|
70 |
#include <e32def.h>
|
sl@0
|
71 |
#endif
|
sl@0
|
72 |
#include <openssl/e_os2.h>
|
sl@0
|
73 |
#include <stddef.h>
|
sl@0
|
74 |
|
sl@0
|
75 |
#ifdef __cplusplus
|
sl@0
|
76 |
extern "C" {
|
sl@0
|
77 |
#endif
|
sl@0
|
78 |
|
sl@0
|
79 |
#if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1))
|
sl@0
|
80 |
#error SHA is disabled.
|
sl@0
|
81 |
#endif
|
sl@0
|
82 |
|
sl@0
|
83 |
#if defined(OPENSSL_FIPS)
|
sl@0
|
84 |
#define FIPS_SHA_SIZE_T size_t
|
sl@0
|
85 |
#endif
|
sl@0
|
86 |
|
sl@0
|
87 |
/*
|
sl@0
|
88 |
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
sl@0
|
89 |
* ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
|
sl@0
|
90 |
* ! SHA_LONG_LOG2 has to be defined along. !
|
sl@0
|
91 |
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
sl@0
|
92 |
*/
|
sl@0
|
93 |
|
sl@0
|
94 |
#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
|
sl@0
|
95 |
#define SHA_LONG unsigned long
|
sl@0
|
96 |
#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
|
sl@0
|
97 |
#define SHA_LONG unsigned long
|
sl@0
|
98 |
#define SHA_LONG_LOG2 3
|
sl@0
|
99 |
#else
|
sl@0
|
100 |
#define SHA_LONG unsigned int
|
sl@0
|
101 |
#endif
|
sl@0
|
102 |
|
sl@0
|
103 |
#define SHA_LBLOCK 16
|
sl@0
|
104 |
#define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a
|
sl@0
|
105 |
* contiguous array of 32 bit
|
sl@0
|
106 |
* wide big-endian values. */
|
sl@0
|
107 |
#define SHA_LAST_BLOCK (SHA_CBLOCK-8)
|
sl@0
|
108 |
#define SHA_DIGEST_LENGTH 20
|
sl@0
|
109 |
|
sl@0
|
110 |
typedef struct SHAstate_st
|
sl@0
|
111 |
{
|
sl@0
|
112 |
SHA_LONG h0,h1,h2,h3,h4;
|
sl@0
|
113 |
SHA_LONG Nl,Nh;
|
sl@0
|
114 |
SHA_LONG data[SHA_LBLOCK];
|
sl@0
|
115 |
unsigned int num;
|
sl@0
|
116 |
} SHA_CTX;
|
sl@0
|
117 |
|
sl@0
|
118 |
#ifndef OPENSSL_NO_SHA0
|
sl@0
|
119 |
IMPORT_C int SHA_Init(SHA_CTX *c);
|
sl@0
|
120 |
IMPORT_C int SHA_Update(SHA_CTX *c, const void *data, size_t len);
|
sl@0
|
121 |
IMPORT_C int SHA_Final(unsigned char *md, SHA_CTX *c);
|
sl@0
|
122 |
IMPORT_C unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md);
|
sl@0
|
123 |
IMPORT_C void SHA_Transform(SHA_CTX *c, const unsigned char *data);
|
sl@0
|
124 |
#endif
|
sl@0
|
125 |
#ifndef OPENSSL_NO_SHA1
|
sl@0
|
126 |
IMPORT_C int SHA1_Init(SHA_CTX *c);
|
sl@0
|
127 |
IMPORT_C int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
|
sl@0
|
128 |
IMPORT_C int SHA1_Final(unsigned char *md, SHA_CTX *c);
|
sl@0
|
129 |
IMPORT_C unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
|
sl@0
|
130 |
IMPORT_C void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
|
sl@0
|
131 |
#endif
|
sl@0
|
132 |
|
sl@0
|
133 |
#define SHA256_CBLOCK (SHA_LBLOCK*4) /* SHA-256 treats input data as a
|
sl@0
|
134 |
* contiguous array of 32 bit
|
sl@0
|
135 |
* wide big-endian values. */
|
sl@0
|
136 |
#define SHA224_DIGEST_LENGTH 28
|
sl@0
|
137 |
#define SHA256_DIGEST_LENGTH 32
|
sl@0
|
138 |
|
sl@0
|
139 |
typedef struct SHA256state_st
|
sl@0
|
140 |
{
|
sl@0
|
141 |
SHA_LONG h[8];
|
sl@0
|
142 |
SHA_LONG Nl,Nh;
|
sl@0
|
143 |
SHA_LONG data[SHA_LBLOCK];
|
sl@0
|
144 |
unsigned int num,md_len;
|
sl@0
|
145 |
} SHA256_CTX;
|
sl@0
|
146 |
|
sl@0
|
147 |
#ifndef OPENSSL_NO_SHA256
|
sl@0
|
148 |
IMPORT_C int SHA224_Init(SHA256_CTX *c);
|
sl@0
|
149 |
IMPORT_C int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
|
sl@0
|
150 |
IMPORT_C int SHA224_Final(unsigned char *md, SHA256_CTX *c);
|
sl@0
|
151 |
IMPORT_C unsigned char *SHA224(const unsigned char *d, size_t n,unsigned char *md);
|
sl@0
|
152 |
IMPORT_C int SHA256_Init(SHA256_CTX *c);
|
sl@0
|
153 |
IMPORT_C int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
|
sl@0
|
154 |
IMPORT_C int SHA256_Final(unsigned char *md, SHA256_CTX *c);
|
sl@0
|
155 |
IMPORT_C unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md);
|
sl@0
|
156 |
IMPORT_C void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
|
sl@0
|
157 |
#endif
|
sl@0
|
158 |
|
sl@0
|
159 |
#define SHA384_DIGEST_LENGTH 48
|
sl@0
|
160 |
#define SHA512_DIGEST_LENGTH 64
|
sl@0
|
161 |
|
sl@0
|
162 |
#ifndef OPENSSL_NO_SHA512
|
sl@0
|
163 |
/*
|
sl@0
|
164 |
* Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
|
sl@0
|
165 |
* being exactly 64-bit wide. See Implementation Notes in sha512.c
|
sl@0
|
166 |
* for further details.
|
sl@0
|
167 |
*/
|
sl@0
|
168 |
#define SHA512_CBLOCK (SHA_LBLOCK*8) /* SHA-512 treats input data as a
|
sl@0
|
169 |
* contiguous array of 64 bit
|
sl@0
|
170 |
* wide big-endian values. */
|
sl@0
|
171 |
#ifdef SYMBIAN
|
sl@0
|
172 |
#define SHA_LONG64 TUint64
|
sl@0
|
173 |
#define U64(C) C##ULL
|
sl@0
|
174 |
#else
|
sl@0
|
175 |
#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
|
sl@0
|
176 |
#define SHA_LONG64 unsigned __int64
|
sl@0
|
177 |
#define U64(C) C##UI64
|
sl@0
|
178 |
#elif defined(__arch64__)
|
sl@0
|
179 |
#define SHA_LONG64 unsigned long
|
sl@0
|
180 |
#define U64(C) C##UL
|
sl@0
|
181 |
#else
|
sl@0
|
182 |
#define SHA_LONG64 unsigned long long
|
sl@0
|
183 |
#define U64(C) C##ULL
|
sl@0
|
184 |
#endif
|
sl@0
|
185 |
#endif
|
sl@0
|
186 |
|
sl@0
|
187 |
typedef struct SHA512state_st
|
sl@0
|
188 |
{
|
sl@0
|
189 |
SHA_LONG64 h[8];
|
sl@0
|
190 |
SHA_LONG64 Nl,Nh;
|
sl@0
|
191 |
union {
|
sl@0
|
192 |
SHA_LONG64 d[SHA_LBLOCK];
|
sl@0
|
193 |
unsigned char p[SHA512_CBLOCK];
|
sl@0
|
194 |
} u;
|
sl@0
|
195 |
unsigned int num,md_len;
|
sl@0
|
196 |
} SHA512_CTX;
|
sl@0
|
197 |
#endif
|
sl@0
|
198 |
|
sl@0
|
199 |
#ifndef OPENSSL_NO_SHA512
|
sl@0
|
200 |
IMPORT_C int SHA384_Init(SHA512_CTX *c);
|
sl@0
|
201 |
IMPORT_C int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
|
sl@0
|
202 |
IMPORT_C int SHA384_Final(unsigned char *md, SHA512_CTX *c);
|
sl@0
|
203 |
IMPORT_C unsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md);
|
sl@0
|
204 |
IMPORT_C int SHA512_Init(SHA512_CTX *c);
|
sl@0
|
205 |
IMPORT_C int SHA512_Update(SHA512_CTX *c, const void *data, size_t len);
|
sl@0
|
206 |
IMPORT_C int SHA512_Final(unsigned char *md, SHA512_CTX *c);
|
sl@0
|
207 |
IMPORT_C unsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md);
|
sl@0
|
208 |
IMPORT_C void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);
|
sl@0
|
209 |
#endif
|
sl@0
|
210 |
|
sl@0
|
211 |
#ifdef __cplusplus
|
sl@0
|
212 |
}
|
sl@0
|
213 |
#endif
|
sl@0
|
214 |
|
sl@0
|
215 |
#endif
|