wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue May 02 08:44:47 2017 +0000
Revision:
7:481bce714567
wolfSSL3.10.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 7:481bce714567 1 /* hash.h
wolfSSL 7:481bce714567 2 *
wolfSSL 7:481bce714567 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 7:481bce714567 4 *
wolfSSL 7:481bce714567 5 * This file is part of wolfSSL.
wolfSSL 7:481bce714567 6 *
wolfSSL 7:481bce714567 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 7:481bce714567 8 * it under the terms of the GNU General Public License as published by
wolfSSL 7:481bce714567 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 7:481bce714567 10 * (at your option) any later version.
wolfSSL 7:481bce714567 11 *
wolfSSL 7:481bce714567 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 7:481bce714567 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 7:481bce714567 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 7:481bce714567 15 * GNU General Public License for more details.
wolfSSL 7:481bce714567 16 *
wolfSSL 7:481bce714567 17 * You should have received a copy of the GNU General Public License
wolfSSL 7:481bce714567 18 * along with this program; if not, write to the Free Software
wolfSSL 7:481bce714567 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 7:481bce714567 20 */
wolfSSL 7:481bce714567 21
wolfSSL 7:481bce714567 22
wolfSSL 7:481bce714567 23 #ifndef WOLF_CRYPT_HASH_H
wolfSSL 7:481bce714567 24 #define WOLF_CRYPT_HASH_H
wolfSSL 7:481bce714567 25
wolfSSL 7:481bce714567 26 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 7:481bce714567 27
wolfSSL 7:481bce714567 28 #ifndef NO_MD5
wolfSSL 7:481bce714567 29 #include <wolfssl/wolfcrypt/md5.h>
wolfSSL 7:481bce714567 30 #endif
wolfSSL 7:481bce714567 31 #ifndef NO_SHA
wolfSSL 7:481bce714567 32 #include <wolfssl/wolfcrypt/sha.h>
wolfSSL 7:481bce714567 33 #endif
wolfSSL 7:481bce714567 34 #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
wolfSSL 7:481bce714567 35 #include <wolfssl/wolfcrypt/sha256.h>
wolfSSL 7:481bce714567 36 #endif
wolfSSL 7:481bce714567 37 #if defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
wolfSSL 7:481bce714567 38 #include <wolfssl/wolfcrypt/sha512.h>
wolfSSL 7:481bce714567 39 #endif
wolfSSL 7:481bce714567 40
wolfSSL 7:481bce714567 41 #ifdef __cplusplus
wolfSSL 7:481bce714567 42 extern "C" {
wolfSSL 7:481bce714567 43 #endif
wolfSSL 7:481bce714567 44
wolfSSL 7:481bce714567 45 /* Hash types */
wolfSSL 7:481bce714567 46 enum wc_HashType {
wolfSSL 7:481bce714567 47 WC_HASH_TYPE_NONE = 0,
wolfSSL 7:481bce714567 48 WC_HASH_TYPE_MD2 = 1,
wolfSSL 7:481bce714567 49 WC_HASH_TYPE_MD4 = 2,
wolfSSL 7:481bce714567 50 WC_HASH_TYPE_MD5 = 3,
wolfSSL 7:481bce714567 51 WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */
wolfSSL 7:481bce714567 52 WC_HASH_TYPE_SHA224 = 9,
wolfSSL 7:481bce714567 53 WC_HASH_TYPE_SHA256 = 5,
wolfSSL 7:481bce714567 54 WC_HASH_TYPE_SHA384 = 6,
wolfSSL 7:481bce714567 55 WC_HASH_TYPE_SHA512 = 7,
wolfSSL 7:481bce714567 56 WC_HASH_TYPE_MD5_SHA = 8,
wolfSSL 7:481bce714567 57 };
wolfSSL 7:481bce714567 58
wolfSSL 7:481bce714567 59 typedef union {
wolfSSL 7:481bce714567 60 #ifndef NO_MD5
wolfSSL 7:481bce714567 61 Md5 md5;
wolfSSL 7:481bce714567 62 #endif
wolfSSL 7:481bce714567 63 #ifndef NO_SHA
wolfSSL 7:481bce714567 64 Sha sha;
wolfSSL 7:481bce714567 65 #endif
wolfSSL 7:481bce714567 66 #ifdef WOLFSSL_SHA224
wolfSSL 7:481bce714567 67 Sha224 sha224;
wolfSSL 7:481bce714567 68 #endif
wolfSSL 7:481bce714567 69 #ifndef NO_SHA256
wolfSSL 7:481bce714567 70 Sha256 sha256;
wolfSSL 7:481bce714567 71 #endif
wolfSSL 7:481bce714567 72 #ifdef WOLFSSL_SHA384
wolfSSL 7:481bce714567 73 Sha384 sha384;
wolfSSL 7:481bce714567 74 #endif
wolfSSL 7:481bce714567 75 #ifdef WOLFSSL_SHA512
wolfSSL 7:481bce714567 76 Sha512 sha512;
wolfSSL 7:481bce714567 77 #endif
wolfSSL 7:481bce714567 78 } wc_HashAlg;
wolfSSL 7:481bce714567 79
wolfSSL 7:481bce714567 80 /* Find largest possible digest size
wolfSSL 7:481bce714567 81 Note if this gets up to the size of 80 or over check smallstack build */
wolfSSL 7:481bce714567 82 #if defined(WOLFSSL_SHA512)
wolfSSL 7:481bce714567 83 #define WC_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
wolfSSL 7:481bce714567 84 #elif defined(WOLFSSL_SHA384)
wolfSSL 7:481bce714567 85 #define WC_MAX_DIGEST_SIZE SHA384_DIGEST_SIZE
wolfSSL 7:481bce714567 86 #elif !defined(NO_SHA256)
wolfSSL 7:481bce714567 87 #define WC_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE
wolfSSL 7:481bce714567 88 #elif defined(WOLFSSL_SHA224)
wolfSSL 7:481bce714567 89 #define WC_MAX_DIGEST_SIZE SHA224_DIGEST_SIZE
wolfSSL 7:481bce714567 90 #elif !defined(NO_SHA)
wolfSSL 7:481bce714567 91 #define WC_MAX_DIGEST_SIZE SHA_DIGEST_SIZE
wolfSSL 7:481bce714567 92 #elif !defined(NO_MD5)
wolfSSL 7:481bce714567 93 #define WC_MAX_DIGEST_SIZE MD5_DIGEST_SIZE
wolfSSL 7:481bce714567 94 #else
wolfSSL 7:481bce714567 95 #define WC_MAX_DIGEST_SIZE 64 /* default to max size of 64 */
wolfSSL 7:481bce714567 96 #endif
wolfSSL 7:481bce714567 97
wolfSSL 7:481bce714567 98 #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
wolfSSL 7:481bce714567 99 WOLFSSL_API int wc_HashGetOID(enum wc_HashType hash_type);
wolfSSL 7:481bce714567 100 #endif
wolfSSL 7:481bce714567 101
wolfSSL 7:481bce714567 102 WOLFSSL_API int wc_HashGetDigestSize(enum wc_HashType hash_type);
wolfSSL 7:481bce714567 103 WOLFSSL_API int wc_Hash(enum wc_HashType hash_type,
wolfSSL 7:481bce714567 104 const byte* data, word32 data_len,
wolfSSL 7:481bce714567 105 byte* hash, word32 hash_len);
wolfSSL 7:481bce714567 106
wolfSSL 7:481bce714567 107 /* generic hash operation wrappers */
wolfSSL 7:481bce714567 108 WOLFSSL_API int wc_HashInit(wc_HashAlg* hash, enum wc_HashType type);
wolfSSL 7:481bce714567 109 WOLFSSL_API int wc_HashUpdate(wc_HashAlg* hash, enum wc_HashType type,
wolfSSL 7:481bce714567 110 const byte* data, word32 dataSz);
wolfSSL 7:481bce714567 111 WOLFSSL_API int wc_HashFinal(wc_HashAlg* hash, enum wc_HashType type,
wolfSSL 7:481bce714567 112 byte* out);
wolfSSL 7:481bce714567 113
wolfSSL 7:481bce714567 114
wolfSSL 7:481bce714567 115 #ifndef NO_MD5
wolfSSL 7:481bce714567 116 #include <wolfssl/wolfcrypt/md5.h>
wolfSSL 7:481bce714567 117 WOLFSSL_API void wc_Md5GetHash(Md5*, byte*);
wolfSSL 7:481bce714567 118 WOLFSSL_API void wc_Md5RestorePos(Md5*, Md5*);
wolfSSL 7:481bce714567 119 #if defined(WOLFSSL_TI_HASH)
wolfSSL 7:481bce714567 120 WOLFSSL_API void wc_Md5Free(Md5*);
wolfSSL 7:481bce714567 121 #else
wolfSSL 7:481bce714567 122 #define wc_Md5Free(d)
wolfSSL 7:481bce714567 123 #endif
wolfSSL 7:481bce714567 124 #endif
wolfSSL 7:481bce714567 125
wolfSSL 7:481bce714567 126 #ifndef NO_SHA
wolfSSL 7:481bce714567 127 #include <wolfssl/wolfcrypt/sha.h>
wolfSSL 7:481bce714567 128 WOLFSSL_API int wc_ShaGetHash(Sha*, byte*);
wolfSSL 7:481bce714567 129 WOLFSSL_API void wc_ShaRestorePos(Sha*, Sha*);
wolfSSL 7:481bce714567 130 WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*);
wolfSSL 7:481bce714567 131 #if defined(WOLFSSL_TI_HASH)
wolfSSL 7:481bce714567 132 WOLFSSL_API void wc_ShaFree(Sha*);
wolfSSL 7:481bce714567 133 #else
wolfSSL 7:481bce714567 134 #define wc_ShaFree(d)
wolfSSL 7:481bce714567 135 #endif
wolfSSL 7:481bce714567 136 #endif
wolfSSL 7:481bce714567 137
wolfSSL 7:481bce714567 138 #ifndef NO_SHA256
wolfSSL 7:481bce714567 139 #include <wolfssl/wolfcrypt/sha256.h>
wolfSSL 7:481bce714567 140 WOLFSSL_API int wc_Sha256GetHash(Sha256*, byte*);
wolfSSL 7:481bce714567 141 WOLFSSL_API void wc_Sha256RestorePos(Sha256*, Sha256*);
wolfSSL 7:481bce714567 142 WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*);
wolfSSL 7:481bce714567 143 #if defined(WOLFSSL_TI_HASH)
wolfSSL 7:481bce714567 144 WOLFSSL_API void wc_Sha256Free(Sha256*);
wolfSSL 7:481bce714567 145 #else
wolfSSL 7:481bce714567 146 #define wc_Sha256Free(d)
wolfSSL 7:481bce714567 147 #endif
wolfSSL 7:481bce714567 148
wolfSSL 7:481bce714567 149 #if defined(WOLFSSL_SHA224)
wolfSSL 7:481bce714567 150 WOLFSSL_API int wc_Sha224GetHash(Sha224*, byte*);
wolfSSL 7:481bce714567 151 WOLFSSL_API int wc_Sha224Hash(const byte*, word32, byte*);
wolfSSL 7:481bce714567 152 #define wc_Sha224Free(d)
wolfSSL 7:481bce714567 153 #endif /* defined(WOLFSSL_SHA224) */
wolfSSL 7:481bce714567 154 #endif
wolfSSL 7:481bce714567 155
wolfSSL 7:481bce714567 156 #ifdef WOLFSSL_SHA512
wolfSSL 7:481bce714567 157 #include <wolfssl/wolfcrypt/sha512.h>
wolfSSL 7:481bce714567 158 WOLFSSL_API int wc_Sha512GetHash(Sha512*, byte*);
wolfSSL 7:481bce714567 159 WOLFSSL_API int wc_Sha512Hash(const byte*, word32, byte*);
wolfSSL 7:481bce714567 160 #define wc_Sha512Free(d)
wolfSSL 7:481bce714567 161
wolfSSL 7:481bce714567 162 #if defined(WOLFSSL_SHA384)
wolfSSL 7:481bce714567 163 WOLFSSL_API int wc_Sha384GetHash(Sha384*, byte*);
wolfSSL 7:481bce714567 164 WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*);
wolfSSL 7:481bce714567 165 #define wc_Sha384Free(d)
wolfSSL 7:481bce714567 166 #endif /* defined(WOLFSSL_SHA384) */
wolfSSL 7:481bce714567 167 #endif /* WOLFSSL_SHA512 */
wolfSSL 7:481bce714567 168
wolfSSL 7:481bce714567 169
wolfSSL 7:481bce714567 170 #ifdef __cplusplus
wolfSSL 7:481bce714567 171 } /* extern "C" */
wolfSSL 7:481bce714567 172 #endif
wolfSSL 7:481bce714567 173
wolfSSL 7:481bce714567 174 #endif /* WOLF_CRYPT_HASH_H */
wolfSSL 7:481bce714567 175