10Sstevel@tonic-gate /* crypto/sha/sha.h */ 20Sstevel@tonic-gate /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 30Sstevel@tonic-gate * All rights reserved. 40Sstevel@tonic-gate * 50Sstevel@tonic-gate * This package is an SSL implementation written 60Sstevel@tonic-gate * by Eric Young (eay@cryptsoft.com). 70Sstevel@tonic-gate * The implementation was written so as to conform with Netscapes SSL. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * This library is free for commercial and non-commercial use as long as 100Sstevel@tonic-gate * the following conditions are aheared to. The following conditions 110Sstevel@tonic-gate * apply to all code found in this distribution, be it the RC4, RSA, 120Sstevel@tonic-gate * lhash, DES, etc., code; not just the SSL code. The SSL documentation 130Sstevel@tonic-gate * included with this distribution is covered by the same copyright terms 140Sstevel@tonic-gate * except that the holder is Tim Hudson (tjh@cryptsoft.com). 150Sstevel@tonic-gate * 160Sstevel@tonic-gate * Copyright remains Eric Young's, and as such any Copyright notices in 170Sstevel@tonic-gate * the code are not to be removed. 180Sstevel@tonic-gate * If this package is used in a product, Eric Young should be given attribution 190Sstevel@tonic-gate * as the author of the parts of the library used. 200Sstevel@tonic-gate * This can be in the form of a textual message at program startup or 210Sstevel@tonic-gate * in documentation (online or textual) provided with the package. 220Sstevel@tonic-gate * 230Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 240Sstevel@tonic-gate * modification, are permitted provided that the following conditions 250Sstevel@tonic-gate * are met: 260Sstevel@tonic-gate * 1. Redistributions of source code must retain the copyright 270Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 280Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 290Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 300Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 310Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 320Sstevel@tonic-gate * must display the following acknowledgement: 330Sstevel@tonic-gate * "This product includes cryptographic software written by 340Sstevel@tonic-gate * Eric Young (eay@cryptsoft.com)" 350Sstevel@tonic-gate * The word 'cryptographic' can be left out if the rouines from the library 360Sstevel@tonic-gate * being used are not cryptographic related :-). 370Sstevel@tonic-gate * 4. If you include any Windows specific code (or a derivative thereof) from 380Sstevel@tonic-gate * the apps directory (application code) you must include an acknowledgement: 390Sstevel@tonic-gate * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 400Sstevel@tonic-gate * 410Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 420Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 430Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 440Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 450Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 460Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 470Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 480Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 490Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 500Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 510Sstevel@tonic-gate * SUCH DAMAGE. 520Sstevel@tonic-gate * 530Sstevel@tonic-gate * The licence and distribution terms for any publically available version or 540Sstevel@tonic-gate * derivative of this code cannot be changed. i.e. this code cannot simply be 550Sstevel@tonic-gate * copied and put under another distribution licence 560Sstevel@tonic-gate * [including the GNU Public Licence.] 570Sstevel@tonic-gate */ 580Sstevel@tonic-gate 590Sstevel@tonic-gate #ifndef HEADER_SHA_H 600Sstevel@tonic-gate #define HEADER_SHA_H 610Sstevel@tonic-gate 620Sstevel@tonic-gate #include <openssl/e_os2.h> 630Sstevel@tonic-gate 640Sstevel@tonic-gate #ifdef __cplusplus 650Sstevel@tonic-gate extern "C" { 660Sstevel@tonic-gate #endif 670Sstevel@tonic-gate 680Sstevel@tonic-gate #if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1)) 690Sstevel@tonic-gate #error SHA is disabled. 700Sstevel@tonic-gate #endif 710Sstevel@tonic-gate 72*2139Sjp161948 #if defined(OPENSSL_FIPS) 73*2139Sjp161948 #define FIPS_SHA_SIZE_T size_t 74*2139Sjp161948 #endif 75*2139Sjp161948 760Sstevel@tonic-gate /* 770Sstevel@tonic-gate * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 780Sstevel@tonic-gate * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then ! 790Sstevel@tonic-gate * ! SHA_LONG_LOG2 has to be defined along. ! 800Sstevel@tonic-gate * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 810Sstevel@tonic-gate */ 820Sstevel@tonic-gate 830Sstevel@tonic-gate #if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) 840Sstevel@tonic-gate #define SHA_LONG unsigned long 850Sstevel@tonic-gate #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 860Sstevel@tonic-gate #define SHA_LONG unsigned long 870Sstevel@tonic-gate #define SHA_LONG_LOG2 3 880Sstevel@tonic-gate #else 890Sstevel@tonic-gate #define SHA_LONG unsigned int 900Sstevel@tonic-gate #endif 910Sstevel@tonic-gate 920Sstevel@tonic-gate #define SHA_LBLOCK 16 930Sstevel@tonic-gate #define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a 940Sstevel@tonic-gate * contiguous array of 32 bit 950Sstevel@tonic-gate * wide big-endian values. */ 960Sstevel@tonic-gate #define SHA_LAST_BLOCK (SHA_CBLOCK-8) 970Sstevel@tonic-gate #define SHA_DIGEST_LENGTH 20 980Sstevel@tonic-gate 990Sstevel@tonic-gate typedef struct SHAstate_st 1000Sstevel@tonic-gate { 1010Sstevel@tonic-gate SHA_LONG h0,h1,h2,h3,h4; 1020Sstevel@tonic-gate SHA_LONG Nl,Nh; 1030Sstevel@tonic-gate SHA_LONG data[SHA_LBLOCK]; 104*2139Sjp161948 unsigned int num; 1050Sstevel@tonic-gate } SHA_CTX; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate #ifndef OPENSSL_NO_SHA0 1080Sstevel@tonic-gate int SHA_Init(SHA_CTX *c); 109*2139Sjp161948 int SHA_Update(SHA_CTX *c, const void *data, size_t len); 1100Sstevel@tonic-gate int SHA_Final(unsigned char *md, SHA_CTX *c); 111*2139Sjp161948 unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md); 1120Sstevel@tonic-gate void SHA_Transform(SHA_CTX *c, const unsigned char *data); 1130Sstevel@tonic-gate #endif 1140Sstevel@tonic-gate #ifndef OPENSSL_NO_SHA1 1150Sstevel@tonic-gate int SHA1_Init(SHA_CTX *c); 116*2139Sjp161948 int SHA1_Update(SHA_CTX *c, const void *data, size_t len); 1170Sstevel@tonic-gate int SHA1_Final(unsigned char *md, SHA_CTX *c); 118*2139Sjp161948 unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); 1190Sstevel@tonic-gate void SHA1_Transform(SHA_CTX *c, const unsigned char *data); 1200Sstevel@tonic-gate #endif 121*2139Sjp161948 122*2139Sjp161948 #define SHA256_CBLOCK (SHA_LBLOCK*4) /* SHA-256 treats input data as a 123*2139Sjp161948 * contiguous array of 32 bit 124*2139Sjp161948 * wide big-endian values. */ 125*2139Sjp161948 #define SHA224_DIGEST_LENGTH 28 126*2139Sjp161948 #define SHA256_DIGEST_LENGTH 32 127*2139Sjp161948 128*2139Sjp161948 typedef struct SHA256state_st 129*2139Sjp161948 { 130*2139Sjp161948 SHA_LONG h[8]; 131*2139Sjp161948 SHA_LONG Nl,Nh; 132*2139Sjp161948 SHA_LONG data[SHA_LBLOCK]; 133*2139Sjp161948 unsigned int num,md_len; 134*2139Sjp161948 } SHA256_CTX; 135*2139Sjp161948 136*2139Sjp161948 #ifndef OPENSSL_NO_SHA256 137*2139Sjp161948 int SHA224_Init(SHA256_CTX *c); 138*2139Sjp161948 int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); 139*2139Sjp161948 int SHA224_Final(unsigned char *md, SHA256_CTX *c); 140*2139Sjp161948 unsigned char *SHA224(const unsigned char *d, size_t n,unsigned char *md); 141*2139Sjp161948 int SHA256_Init(SHA256_CTX *c); 142*2139Sjp161948 int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); 143*2139Sjp161948 int SHA256_Final(unsigned char *md, SHA256_CTX *c); 144*2139Sjp161948 unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md); 145*2139Sjp161948 void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); 146*2139Sjp161948 #endif 147*2139Sjp161948 148*2139Sjp161948 #define SHA384_DIGEST_LENGTH 48 149*2139Sjp161948 #define SHA512_DIGEST_LENGTH 64 150*2139Sjp161948 151*2139Sjp161948 #ifndef OPENSSL_NO_SHA512 152*2139Sjp161948 /* 153*2139Sjp161948 * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64 154*2139Sjp161948 * being exactly 64-bit wide. See Implementation Notes in sha512.c 155*2139Sjp161948 * for further details. 156*2139Sjp161948 */ 157*2139Sjp161948 #define SHA512_CBLOCK (SHA_LBLOCK*8) /* SHA-512 treats input data as a 158*2139Sjp161948 * contiguous array of 64 bit 159*2139Sjp161948 * wide big-endian values. */ 160*2139Sjp161948 #if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) 161*2139Sjp161948 #define SHA_LONG64 unsigned __int64 162*2139Sjp161948 #define U64(C) C##UI64 163*2139Sjp161948 #elif defined(__arch64__) 164*2139Sjp161948 #define SHA_LONG64 unsigned long 165*2139Sjp161948 #define U64(C) C##UL 166*2139Sjp161948 #else 167*2139Sjp161948 #define SHA_LONG64 unsigned long long 168*2139Sjp161948 #define U64(C) C##ULL 169*2139Sjp161948 #endif 170*2139Sjp161948 171*2139Sjp161948 typedef struct SHA512state_st 172*2139Sjp161948 { 173*2139Sjp161948 SHA_LONG64 h[8]; 174*2139Sjp161948 SHA_LONG64 Nl,Nh; 175*2139Sjp161948 union { 176*2139Sjp161948 SHA_LONG64 d[SHA_LBLOCK]; 177*2139Sjp161948 unsigned char p[SHA512_CBLOCK]; 178*2139Sjp161948 } u; 179*2139Sjp161948 unsigned int num,md_len; 180*2139Sjp161948 } SHA512_CTX; 181*2139Sjp161948 #endif 182*2139Sjp161948 183*2139Sjp161948 #ifndef OPENSSL_NO_SHA512 184*2139Sjp161948 int SHA384_Init(SHA512_CTX *c); 185*2139Sjp161948 int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); 186*2139Sjp161948 int SHA384_Final(unsigned char *md, SHA512_CTX *c); 187*2139Sjp161948 unsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md); 188*2139Sjp161948 int SHA512_Init(SHA512_CTX *c); 189*2139Sjp161948 int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); 190*2139Sjp161948 int SHA512_Final(unsigned char *md, SHA512_CTX *c); 191*2139Sjp161948 unsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md); 192*2139Sjp161948 void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); 193*2139Sjp161948 #endif 194*2139Sjp161948 1950Sstevel@tonic-gate #ifdef __cplusplus 1960Sstevel@tonic-gate } 1970Sstevel@tonic-gate #endif 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate #endif 200