sl@0: /* crypto/sha/sha.h */ sl@0: /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) sl@0: * All rights reserved. sl@0: * sl@0: * This package is an SSL implementation written sl@0: * by Eric Young (eay@cryptsoft.com). sl@0: * The implementation was written so as to conform with Netscapes SSL. sl@0: * sl@0: * This library is free for commercial and non-commercial use as long as sl@0: * the following conditions are aheared to. The following conditions sl@0: * apply to all code found in this distribution, be it the RC4, RSA, sl@0: * lhash, DES, etc., code; not just the SSL code. The SSL documentation sl@0: * included with this distribution is covered by the same copyright terms sl@0: * except that the holder is Tim Hudson (tjh@cryptsoft.com). sl@0: * sl@0: * Copyright remains Eric Young's, and as such any Copyright notices in sl@0: * the code are not to be removed. sl@0: * If this package is used in a product, Eric Young should be given attribution sl@0: * as the author of the parts of the library used. sl@0: * This can be in the form of a textual message at program startup or sl@0: * in documentation (online or textual) provided with the package. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * 3. All advertising materials mentioning features or use of this software sl@0: * must display the following acknowledgement: sl@0: * "This product includes cryptographic software written by sl@0: * Eric Young (eay@cryptsoft.com)" sl@0: * The word 'cryptographic' can be left out if the rouines from the library sl@0: * being used are not cryptographic related :-). sl@0: * 4. If you include any Windows specific code (or a derivative thereof) from sl@0: * the apps directory (application code) you must include an acknowledgement: sl@0: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND sl@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE sl@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL sl@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS sl@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT sl@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY sl@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF sl@0: * SUCH DAMAGE. sl@0: * sl@0: * The licence and distribution terms for any publically available version or sl@0: * derivative of this code cannot be changed. i.e. this code cannot simply be sl@0: * copied and put under another distribution licence sl@0: * [including the GNU Public Licence.] sl@0: */ sl@0: /* sl@0: © Portions copyright (c) 2006-2010 Nokia Corporation. All rights reserved. sl@0: */ sl@0: sl@0: #ifndef HEADER_SHA_H sl@0: #define HEADER_SHA_H sl@0: sl@0: #if (defined(__SYMBIAN32__) && !defined(SYMBIAN)) sl@0: #define SYMBIAN sl@0: #endif sl@0: sl@0: #ifdef SYMBIAN sl@0: #include sl@0: #endif sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __cplusplus sl@0: extern "C" { sl@0: #endif sl@0: sl@0: #if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1)) sl@0: #error SHA is disabled. sl@0: #endif sl@0: sl@0: #if defined(OPENSSL_FIPS) sl@0: #define FIPS_SHA_SIZE_T size_t sl@0: #endif sl@0: sl@0: /* sl@0: * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then ! sl@0: * ! SHA_LONG_LOG2 has to be defined along. ! sl@0: * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: */ sl@0: sl@0: #if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) sl@0: #define SHA_LONG unsigned long sl@0: #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) sl@0: #define SHA_LONG unsigned long sl@0: #define SHA_LONG_LOG2 3 sl@0: #else sl@0: #define SHA_LONG unsigned int sl@0: #endif sl@0: sl@0: #define SHA_LBLOCK 16 sl@0: #define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a sl@0: * contiguous array of 32 bit sl@0: * wide big-endian values. */ sl@0: #define SHA_LAST_BLOCK (SHA_CBLOCK-8) sl@0: #define SHA_DIGEST_LENGTH 20 sl@0: sl@0: typedef struct SHAstate_st sl@0: { sl@0: SHA_LONG h0,h1,h2,h3,h4; sl@0: SHA_LONG Nl,Nh; sl@0: SHA_LONG data[SHA_LBLOCK]; sl@0: unsigned int num; sl@0: } SHA_CTX; sl@0: sl@0: #ifndef OPENSSL_NO_SHA0 sl@0: IMPORT_C int SHA_Init(SHA_CTX *c); sl@0: IMPORT_C int SHA_Update(SHA_CTX *c, const void *data, size_t len); sl@0: IMPORT_C int SHA_Final(unsigned char *md, SHA_CTX *c); sl@0: IMPORT_C unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md); sl@0: IMPORT_C void SHA_Transform(SHA_CTX *c, const unsigned char *data); sl@0: #endif sl@0: #ifndef OPENSSL_NO_SHA1 sl@0: IMPORT_C int SHA1_Init(SHA_CTX *c); sl@0: IMPORT_C int SHA1_Update(SHA_CTX *c, const void *data, size_t len); sl@0: IMPORT_C int SHA1_Final(unsigned char *md, SHA_CTX *c); sl@0: IMPORT_C unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); sl@0: IMPORT_C void SHA1_Transform(SHA_CTX *c, const unsigned char *data); sl@0: #endif sl@0: sl@0: #define SHA256_CBLOCK (SHA_LBLOCK*4) /* SHA-256 treats input data as a sl@0: * contiguous array of 32 bit sl@0: * wide big-endian values. */ sl@0: #define SHA224_DIGEST_LENGTH 28 sl@0: #define SHA256_DIGEST_LENGTH 32 sl@0: sl@0: typedef struct SHA256state_st sl@0: { sl@0: SHA_LONG h[8]; sl@0: SHA_LONG Nl,Nh; sl@0: SHA_LONG data[SHA_LBLOCK]; sl@0: unsigned int num,md_len; sl@0: } SHA256_CTX; sl@0: sl@0: #ifndef OPENSSL_NO_SHA256 sl@0: IMPORT_C int SHA224_Init(SHA256_CTX *c); sl@0: IMPORT_C int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); sl@0: IMPORT_C int SHA224_Final(unsigned char *md, SHA256_CTX *c); sl@0: IMPORT_C unsigned char *SHA224(const unsigned char *d, size_t n,unsigned char *md); sl@0: IMPORT_C int SHA256_Init(SHA256_CTX *c); sl@0: IMPORT_C int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); sl@0: IMPORT_C int SHA256_Final(unsigned char *md, SHA256_CTX *c); sl@0: IMPORT_C unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md); sl@0: IMPORT_C void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); sl@0: #endif sl@0: sl@0: #define SHA384_DIGEST_LENGTH 48 sl@0: #define SHA512_DIGEST_LENGTH 64 sl@0: sl@0: #ifndef OPENSSL_NO_SHA512 sl@0: /* sl@0: * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64 sl@0: * being exactly 64-bit wide. See Implementation Notes in sha512.c sl@0: * for further details. sl@0: */ sl@0: #define SHA512_CBLOCK (SHA_LBLOCK*8) /* SHA-512 treats input data as a sl@0: * contiguous array of 64 bit sl@0: * wide big-endian values. */ sl@0: #ifdef SYMBIAN sl@0: #define SHA_LONG64 TUint64 sl@0: #define U64(C) C##ULL sl@0: #else sl@0: #if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) sl@0: #define SHA_LONG64 unsigned __int64 sl@0: #define U64(C) C##UI64 sl@0: #elif defined(__arch64__) sl@0: #define SHA_LONG64 unsigned long sl@0: #define U64(C) C##UL sl@0: #else sl@0: #define SHA_LONG64 unsigned long long sl@0: #define U64(C) C##ULL sl@0: #endif sl@0: #endif sl@0: sl@0: typedef struct SHA512state_st sl@0: { sl@0: SHA_LONG64 h[8]; sl@0: SHA_LONG64 Nl,Nh; sl@0: union { sl@0: SHA_LONG64 d[SHA_LBLOCK]; sl@0: unsigned char p[SHA512_CBLOCK]; sl@0: } u; sl@0: unsigned int num,md_len; sl@0: } SHA512_CTX; sl@0: #endif sl@0: sl@0: #ifndef OPENSSL_NO_SHA512 sl@0: IMPORT_C int SHA384_Init(SHA512_CTX *c); sl@0: IMPORT_C int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); sl@0: IMPORT_C int SHA384_Final(unsigned char *md, SHA512_CTX *c); sl@0: IMPORT_C unsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md); sl@0: IMPORT_C int SHA512_Init(SHA512_CTX *c); sl@0: IMPORT_C int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); sl@0: IMPORT_C int SHA512_Final(unsigned char *md, SHA512_CTX *c); sl@0: IMPORT_C unsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md); sl@0: IMPORT_C void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); sl@0: #endif sl@0: sl@0: #ifdef __cplusplus sl@0: } sl@0: #endif sl@0: sl@0: #endif