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 30 01:44:10 2017 +0000
Revision:
11:cee25a834751
wolfSSL 3.11.0

Who changed what in which revision?

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