155714Skris/* crypto/sha/sha.h */
255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
355714Skris * All rights reserved.
455714Skris *
555714Skris * This package is an SSL implementation written
655714Skris * by Eric Young (eay@cryptsoft.com).
755714Skris * The implementation was written so as to conform with Netscapes SSL.
855714Skris *
955714Skris * This library is free for commercial and non-commercial use as long as
1055714Skris * the following conditions are aheared to.  The following conditions
1155714Skris * apply to all code found in this distribution, be it the RC4, RSA,
1255714Skris * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1355714Skris * included with this distribution is covered by the same copyright terms
1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1555714Skris *
1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in
1755714Skris * the code are not to be removed.
1855714Skris * If this package is used in a product, Eric Young should be given attribution
1955714Skris * as the author of the parts of the library used.
2055714Skris * This can be in the form of a textual message at program startup or
2155714Skris * in documentation (online or textual) provided with the package.
2255714Skris *
2355714Skris * Redistribution and use in source and binary forms, with or without
2455714Skris * modification, are permitted provided that the following conditions
2555714Skris * are met:
2655714Skris * 1. Redistributions of source code must retain the copyright
2755714Skris *    notice, this list of conditions and the following disclaimer.
2855714Skris * 2. Redistributions in binary form must reproduce the above copyright
2955714Skris *    notice, this list of conditions and the following disclaimer in the
3055714Skris *    documentation and/or other materials provided with the distribution.
3155714Skris * 3. All advertising materials mentioning features or use of this software
3255714Skris *    must display the following acknowledgement:
3355714Skris *    "This product includes cryptographic software written by
3455714Skris *     Eric Young (eay@cryptsoft.com)"
3555714Skris *    The word 'cryptographic' can be left out if the rouines from the library
3655714Skris *    being used are not cryptographic related :-).
3755714Skris * 4. If you include any Windows specific code (or a derivative thereof) from
3855714Skris *    the apps directory (application code) you must include an acknowledgement:
3955714Skris *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4055714Skris *
4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4455714Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5155714Skris * SUCH DAMAGE.
5255714Skris *
5355714Skris * The licence and distribution terms for any publically available version or
5455714Skris * derivative of this code cannot be changed.  i.e. this code cannot simply be
5555714Skris * copied and put under another distribution licence
5655714Skris * [including the GNU Public Licence.]
5755714Skris */
5855714Skris
5955714Skris#ifndef HEADER_SHA_H
6055714Skris#define HEADER_SHA_H
6155714Skris
62109998Smarkm#include <openssl/e_os2.h>
63167612Ssimon#include <stddef.h>
64109998Smarkm
6555714Skris#ifdef  __cplusplus
6655714Skrisextern "C" {
6755714Skris#endif
6855714Skris
69109998Smarkm#if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1))
7055714Skris#error SHA is disabled.
7155714Skris#endif
7255714Skris
73142425Snectar#if defined(OPENSSL_FIPS)
74160814Ssimon#define FIPS_SHA_SIZE_T size_t
75142425Snectar#endif
76142425Snectar
7755714Skris/*
7855714Skris * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7955714Skris * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
8055714Skris * ! SHA_LONG_LOG2 has to be defined along.                        !
8155714Skris * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8255714Skris */
8355714Skris
84238405Sjkim#if defined(__LP32__)
8555714Skris#define SHA_LONG unsigned long
86109998Smarkm#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
8755714Skris#define SHA_LONG unsigned long
8855714Skris#define SHA_LONG_LOG2 3
8955714Skris#else
9055714Skris#define SHA_LONG unsigned int
9155714Skris#endif
9255714Skris
9355714Skris#define SHA_LBLOCK	16
9455714Skris#define SHA_CBLOCK	(SHA_LBLOCK*4)	/* SHA treats input data as a
9555714Skris					 * contiguous array of 32 bit
9655714Skris					 * wide big-endian values. */
9755714Skris#define SHA_LAST_BLOCK  (SHA_CBLOCK-8)
9855714Skris#define SHA_DIGEST_LENGTH 20
9955714Skris
10055714Skristypedef struct SHAstate_st
10155714Skris	{
10255714Skris	SHA_LONG h0,h1,h2,h3,h4;
10355714Skris	SHA_LONG Nl,Nh;
10455714Skris	SHA_LONG data[SHA_LBLOCK];
105160814Ssimon	unsigned int num;
10655714Skris	} SHA_CTX;
10755714Skris
108109998Smarkm#ifndef OPENSSL_NO_SHA0
109194206Ssimon#ifdef OPENSSL_FIPS
110194206Ssimonint private_SHA_Init(SHA_CTX *c);
111194206Ssimon#endif
112109998Smarkmint SHA_Init(SHA_CTX *c);
113160814Ssimonint SHA_Update(SHA_CTX *c, const void *data, size_t len);
114109998Smarkmint SHA_Final(unsigned char *md, SHA_CTX *c);
115160814Ssimonunsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md);
11659191Skrisvoid SHA_Transform(SHA_CTX *c, const unsigned char *data);
11755714Skris#endif
118109998Smarkm#ifndef OPENSSL_NO_SHA1
119238405Sjkim#ifdef OPENSSL_FIPS
120238405Sjkimint private_SHA1_Init(SHA_CTX *c);
121238405Sjkim#endif
122109998Smarkmint SHA1_Init(SHA_CTX *c);
123160814Ssimonint SHA1_Update(SHA_CTX *c, const void *data, size_t len);
124109998Smarkmint SHA1_Final(unsigned char *md, SHA_CTX *c);
125160814Ssimonunsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
12659191Skrisvoid SHA1_Transform(SHA_CTX *c, const unsigned char *data);
12755714Skris#endif
128160814Ssimon
129160814Ssimon#define SHA256_CBLOCK	(SHA_LBLOCK*4)	/* SHA-256 treats input data as a
130160814Ssimon					 * contiguous array of 32 bit
131160814Ssimon					 * wide big-endian values. */
132160814Ssimon#define SHA224_DIGEST_LENGTH	28
133160814Ssimon#define SHA256_DIGEST_LENGTH	32
134160814Ssimon
135160814Ssimontypedef struct SHA256state_st
136160814Ssimon	{
137160814Ssimon	SHA_LONG h[8];
138160814Ssimon	SHA_LONG Nl,Nh;
139160814Ssimon	SHA_LONG data[SHA_LBLOCK];
140160814Ssimon	unsigned int num,md_len;
141160814Ssimon	} SHA256_CTX;
142160814Ssimon
143160814Ssimon#ifndef OPENSSL_NO_SHA256
144238405Sjkim#ifdef OPENSSL_FIPS
145238405Sjkimint private_SHA224_Init(SHA256_CTX *c);
146238405Sjkimint private_SHA256_Init(SHA256_CTX *c);
147238405Sjkim#endif
148160814Ssimonint SHA224_Init(SHA256_CTX *c);
149160814Ssimonint SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
150160814Ssimonint SHA224_Final(unsigned char *md, SHA256_CTX *c);
151160814Ssimonunsigned char *SHA224(const unsigned char *d, size_t n,unsigned char *md);
152160814Ssimonint SHA256_Init(SHA256_CTX *c);
153160814Ssimonint SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
154160814Ssimonint SHA256_Final(unsigned char *md, SHA256_CTX *c);
155160814Ssimonunsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md);
156160814Ssimonvoid SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
157160814Ssimon#endif
158160814Ssimon
159160814Ssimon#define SHA384_DIGEST_LENGTH	48
160160814Ssimon#define SHA512_DIGEST_LENGTH	64
161160814Ssimon
162160814Ssimon#ifndef OPENSSL_NO_SHA512
163160814Ssimon/*
164160814Ssimon * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
165160814Ssimon * being exactly 64-bit wide. See Implementation Notes in sha512.c
166160814Ssimon * for further details.
167160814Ssimon */
168160814Ssimon#define SHA512_CBLOCK	(SHA_LBLOCK*8)	/* SHA-512 treats input data as a
169160814Ssimon					 * contiguous array of 64 bit
170160814Ssimon					 * wide big-endian values. */
171160814Ssimon#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
172160814Ssimon#define SHA_LONG64 unsigned __int64
173160814Ssimon#define U64(C)     C##UI64
174160814Ssimon#elif defined(__arch64__)
175160814Ssimon#define SHA_LONG64 unsigned long
176160814Ssimon#define U64(C)     C##UL
177160814Ssimon#else
178160814Ssimon#define SHA_LONG64 unsigned long long
179160814Ssimon#define U64(C)     C##ULL
180160814Ssimon#endif
181160814Ssimon
182160814Ssimontypedef struct SHA512state_st
183160814Ssimon	{
184160814Ssimon	SHA_LONG64 h[8];
185160814Ssimon	SHA_LONG64 Nl,Nh;
186160814Ssimon	union {
187160814Ssimon		SHA_LONG64	d[SHA_LBLOCK];
188160814Ssimon		unsigned char	p[SHA512_CBLOCK];
189160814Ssimon	} u;
190160814Ssimon	unsigned int num,md_len;
191160814Ssimon	} SHA512_CTX;
192160814Ssimon#endif
193160814Ssimon
194160814Ssimon#ifndef OPENSSL_NO_SHA512
195238405Sjkim#ifdef OPENSSL_FIPS
196238405Sjkimint private_SHA384_Init(SHA512_CTX *c);
197238405Sjkimint private_SHA512_Init(SHA512_CTX *c);
198238405Sjkim#endif
199160814Ssimonint SHA384_Init(SHA512_CTX *c);
200160814Ssimonint SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
201160814Ssimonint SHA384_Final(unsigned char *md, SHA512_CTX *c);
202160814Ssimonunsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md);
203160814Ssimonint SHA512_Init(SHA512_CTX *c);
204160814Ssimonint SHA512_Update(SHA512_CTX *c, const void *data, size_t len);
205160814Ssimonint SHA512_Final(unsigned char *md, SHA512_CTX *c);
206160814Ssimonunsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md);
207160814Ssimonvoid SHA512_Transform(SHA512_CTX *c, const unsigned char *data);
208160814Ssimon#endif
209160814Ssimon
21055714Skris#ifdef  __cplusplus
21155714Skris}
21255714Skris#endif
21355714Skris
21455714Skris#endif
215