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. 8296341Sdelphij * 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). 15296341Sdelphij * 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. 22296341Sdelphij * 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 :-). 37296341Sdelphij * 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)" 40296341Sdelphij * 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. 52296341Sdelphij * 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 60296341Sdelphij# define HEADER_SHA_H 6155714Skris 62296341Sdelphij# include <openssl/e_os2.h> 63296341Sdelphij# include <stddef.h> 64109998Smarkm 6555714Skris#ifdef __cplusplus 6655714Skrisextern "C" { 6755714Skris#endif 6855714Skris 69296341Sdelphij# if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1)) 70296341Sdelphij# error SHA is disabled. 71296341Sdelphij# endif 7255714Skris 73296341Sdelphij# if defined(OPENSSL_FIPS) 74296341Sdelphij# define FIPS_SHA_SIZE_T size_t 75296341Sdelphij# endif 76142425Snectar 77296341Sdelphij/*- 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 84296341Sdelphij# if defined(__LP32__) 85296341Sdelphij# define SHA_LONG unsigned long 86296341Sdelphij# elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 87296341Sdelphij# define SHA_LONG unsigned long 88296341Sdelphij# define SHA_LONG_LOG2 3 89296341Sdelphij# else 90296341Sdelphij# define SHA_LONG unsigned int 91296341Sdelphij# endif 9255714Skris 93296341Sdelphij# define SHA_LBLOCK 16 94296341Sdelphij# define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a 95296341Sdelphij * contiguous array of 32 bit wide 96296341Sdelphij * big-endian values. */ 97296341Sdelphij# define SHA_LAST_BLOCK (SHA_CBLOCK-8) 98296341Sdelphij# define SHA_DIGEST_LENGTH 20 9955714Skris 100296341Sdelphijtypedef struct SHAstate_st { 101296341Sdelphij SHA_LONG h0, h1, h2, h3, h4; 102296341Sdelphij SHA_LONG Nl, Nh; 103296341Sdelphij SHA_LONG data[SHA_LBLOCK]; 104296341Sdelphij unsigned int num; 105296341Sdelphij} SHA_CTX; 10655714Skris 107296341Sdelphij# ifndef OPENSSL_NO_SHA0 108296341Sdelphij# ifdef OPENSSL_FIPS 109194206Ssimonint private_SHA_Init(SHA_CTX *c); 110296341Sdelphij# endif 111109998Smarkmint SHA_Init(SHA_CTX *c); 112160814Ssimonint SHA_Update(SHA_CTX *c, const void *data, size_t len); 113109998Smarkmint SHA_Final(unsigned char *md, SHA_CTX *c); 114160814Ssimonunsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md); 11559191Skrisvoid SHA_Transform(SHA_CTX *c, const unsigned char *data); 116296341Sdelphij# endif 117296341Sdelphij# ifndef OPENSSL_NO_SHA1 118296341Sdelphij# ifdef OPENSSL_FIPS 119238405Sjkimint private_SHA1_Init(SHA_CTX *c); 120296341Sdelphij# endif 121109998Smarkmint SHA1_Init(SHA_CTX *c); 122160814Ssimonint SHA1_Update(SHA_CTX *c, const void *data, size_t len); 123109998Smarkmint SHA1_Final(unsigned char *md, SHA_CTX *c); 124160814Ssimonunsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); 12559191Skrisvoid SHA1_Transform(SHA_CTX *c, const unsigned char *data); 126296341Sdelphij# endif 127160814Ssimon 128296341Sdelphij# define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a 129296341Sdelphij * contiguous array of 32 bit wide 130296341Sdelphij * big-endian values. */ 131296341Sdelphij# define SHA224_DIGEST_LENGTH 28 132296341Sdelphij# define SHA256_DIGEST_LENGTH 32 133160814Ssimon 134296341Sdelphijtypedef struct SHA256state_st { 135296341Sdelphij SHA_LONG h[8]; 136296341Sdelphij SHA_LONG Nl, Nh; 137296341Sdelphij SHA_LONG data[SHA_LBLOCK]; 138296341Sdelphij unsigned int num, md_len; 139296341Sdelphij} SHA256_CTX; 140160814Ssimon 141296341Sdelphij# ifndef OPENSSL_NO_SHA256 142296341Sdelphij# ifdef OPENSSL_FIPS 143238405Sjkimint private_SHA224_Init(SHA256_CTX *c); 144238405Sjkimint private_SHA256_Init(SHA256_CTX *c); 145296341Sdelphij# endif 146160814Ssimonint SHA224_Init(SHA256_CTX *c); 147160814Ssimonint SHA224_Update(SHA256_CTX *c, const void *data, size_t len); 148160814Ssimonint SHA224_Final(unsigned char *md, SHA256_CTX *c); 149296341Sdelphijunsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md); 150160814Ssimonint SHA256_Init(SHA256_CTX *c); 151160814Ssimonint SHA256_Update(SHA256_CTX *c, const void *data, size_t len); 152160814Ssimonint SHA256_Final(unsigned char *md, SHA256_CTX *c); 153296341Sdelphijunsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md); 154160814Ssimonvoid SHA256_Transform(SHA256_CTX *c, const unsigned char *data); 155296341Sdelphij# endif 156160814Ssimon 157296341Sdelphij# define SHA384_DIGEST_LENGTH 48 158296341Sdelphij# define SHA512_DIGEST_LENGTH 64 159160814Ssimon 160296341Sdelphij# ifndef OPENSSL_NO_SHA512 161160814Ssimon/* 162160814Ssimon * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64 163160814Ssimon * being exactly 64-bit wide. See Implementation Notes in sha512.c 164160814Ssimon * for further details. 165160814Ssimon */ 166296341Sdelphij/* 167296341Sdelphij * SHA-512 treats input data as a 168296341Sdelphij * contiguous array of 64 bit 169296341Sdelphij * wide big-endian values. 170296341Sdelphij */ 171296341Sdelphij# define SHA512_CBLOCK (SHA_LBLOCK*8) 172296341Sdelphij# if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) 173296341Sdelphij# define SHA_LONG64 unsigned __int64 174296341Sdelphij# define U64(C) C##UI64 175296341Sdelphij# elif defined(__arch64__) 176296341Sdelphij# define SHA_LONG64 unsigned long 177296341Sdelphij# define U64(C) C##UL 178296341Sdelphij# else 179296341Sdelphij# define SHA_LONG64 unsigned long long 180296341Sdelphij# define U64(C) C##ULL 181296341Sdelphij# endif 182160814Ssimon 183296341Sdelphijtypedef struct SHA512state_st { 184296341Sdelphij SHA_LONG64 h[8]; 185296341Sdelphij SHA_LONG64 Nl, Nh; 186296341Sdelphij union { 187296341Sdelphij SHA_LONG64 d[SHA_LBLOCK]; 188296341Sdelphij unsigned char p[SHA512_CBLOCK]; 189296341Sdelphij } u; 190296341Sdelphij unsigned int num, md_len; 191296341Sdelphij} SHA512_CTX; 192296341Sdelphij# endif 193160814Ssimon 194296341Sdelphij# ifndef OPENSSL_NO_SHA512 195296341Sdelphij# ifdef OPENSSL_FIPS 196238405Sjkimint private_SHA384_Init(SHA512_CTX *c); 197238405Sjkimint private_SHA512_Init(SHA512_CTX *c); 198296341Sdelphij# 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); 202296341Sdelphijunsigned 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); 206296341Sdelphijunsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md); 207160814Ssimonvoid SHA512_Transform(SHA512_CTX *c, const unsigned char *data); 208296341Sdelphij# endif 209160814Ssimon 21055714Skris#ifdef __cplusplus 21155714Skris} 21255714Skris#endif 21355714Skris 21455714Skris#endif 215