Xuyi Wang / wolfSSL

Dependents:   OS

Committer:
sPymbed
Date:
Tue Nov 19 14:32:16 2019 +0000
Revision:
16:048e5e270a58
Parent:
15:117db924cf7c
working ssl

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 15:117db924cf7c 1 /* hash.h
wolfSSL 15:117db924cf7c 2 *
wolfSSL 15:117db924cf7c 3 * Copyright (C) 2006-2017 wolfSSL Inc.
wolfSSL 15:117db924cf7c 4 *
wolfSSL 15:117db924cf7c 5 * This file is part of wolfSSL.
wolfSSL 15:117db924cf7c 6 *
wolfSSL 15:117db924cf7c 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 15:117db924cf7c 8 * it under the terms of the GNU General Public License as published by
wolfSSL 15:117db924cf7c 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 15:117db924cf7c 10 * (at your option) any later version.
wolfSSL 15:117db924cf7c 11 *
wolfSSL 15:117db924cf7c 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 15:117db924cf7c 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 15:117db924cf7c 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 15:117db924cf7c 15 * GNU General Public License for more details.
wolfSSL 15:117db924cf7c 16 *
wolfSSL 15:117db924cf7c 17 * You should have received a copy of the GNU General Public License
wolfSSL 15:117db924cf7c 18 * along with this program; if not, write to the Free Software
wolfSSL 15:117db924cf7c 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 15:117db924cf7c 20 */
wolfSSL 15:117db924cf7c 21
wolfSSL 15:117db924cf7c 22 /*!
wolfSSL 15:117db924cf7c 23 \file wolfssl/wolfcrypt/hash.h
wolfSSL 15:117db924cf7c 24 */
wolfSSL 15:117db924cf7c 25
wolfSSL 15:117db924cf7c 26 #ifndef WOLF_CRYPT_HASH_H
wolfSSL 15:117db924cf7c 27 #define WOLF_CRYPT_HASH_H
wolfSSL 15:117db924cf7c 28
wolfSSL 15:117db924cf7c 29 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 15:117db924cf7c 30
wolfSSL 15:117db924cf7c 31 #ifndef NO_MD5
wolfSSL 15:117db924cf7c 32 #include <wolfssl/wolfcrypt/md5.h>
wolfSSL 15:117db924cf7c 33 #endif
wolfSSL 15:117db924cf7c 34 #ifndef NO_SHA
wolfSSL 15:117db924cf7c 35 #include <wolfssl/wolfcrypt/sha.h>
wolfSSL 15:117db924cf7c 36 #endif
wolfSSL 15:117db924cf7c 37 #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
wolfSSL 15:117db924cf7c 38 #include <wolfssl/wolfcrypt/sha256.h>
wolfSSL 15:117db924cf7c 39 #endif
wolfSSL 15:117db924cf7c 40 #if defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
wolfSSL 15:117db924cf7c 41 #include <wolfssl/wolfcrypt/sha512.h>
wolfSSL 15:117db924cf7c 42 #endif
wolfSSL 15:117db924cf7c 43 #ifdef HAVE_BLAKE2
wolfSSL 15:117db924cf7c 44 #include <wolfssl/wolfcrypt/blake2.h>
wolfSSL 15:117db924cf7c 45 #endif
wolfSSL 15:117db924cf7c 46 #ifdef WOLFSSL_SHA3
wolfSSL 15:117db924cf7c 47 #include <wolfssl/wolfcrypt/sha3.h>
wolfSSL 15:117db924cf7c 48 #endif
wolfSSL 15:117db924cf7c 49 #ifndef NO_MD4
wolfSSL 15:117db924cf7c 50 #include <wolfssl/wolfcrypt/md4.h>
wolfSSL 15:117db924cf7c 51 #endif
wolfSSL 15:117db924cf7c 52 #ifdef WOLFSSL_MD2
wolfSSL 15:117db924cf7c 53 #include <wolfssl/wolfcrypt/md2.h>
wolfSSL 15:117db924cf7c 54 #endif
wolfSSL 15:117db924cf7c 55
wolfSSL 15:117db924cf7c 56
wolfSSL 15:117db924cf7c 57 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 58 extern "C" {
wolfSSL 15:117db924cf7c 59 #endif
wolfSSL 15:117db924cf7c 60
wolfSSL 15:117db924cf7c 61 #if !defined(HAVE_FIPS) && !defined(NO_OLD_WC_NAMES)
wolfSSL 15:117db924cf7c 62 #define MAX_DIGEST_SIZE WC_MAX_DIGEST_SIZE
wolfSSL 15:117db924cf7c 63 #endif
wolfSSL 15:117db924cf7c 64
wolfSSL 15:117db924cf7c 65
wolfSSL 15:117db924cf7c 66 typedef union {
wolfSSL 15:117db924cf7c 67 #ifndef NO_MD5
wolfSSL 15:117db924cf7c 68 wc_Md5 md5;
wolfSSL 15:117db924cf7c 69 #endif
wolfSSL 15:117db924cf7c 70 #ifndef NO_SHA
wolfSSL 15:117db924cf7c 71 wc_Sha sha;
wolfSSL 15:117db924cf7c 72 #endif
wolfSSL 15:117db924cf7c 73 #ifdef WOLFSSL_SHA224
wolfSSL 15:117db924cf7c 74 wc_Sha224 sha224;
wolfSSL 15:117db924cf7c 75 #endif
wolfSSL 15:117db924cf7c 76 #ifndef NO_SHA256
wolfSSL 15:117db924cf7c 77 wc_Sha256 sha256;
wolfSSL 15:117db924cf7c 78 #endif
wolfSSL 15:117db924cf7c 79 #ifdef WOLFSSL_SHA384
wolfSSL 15:117db924cf7c 80 wc_Sha384 sha384;
wolfSSL 15:117db924cf7c 81 #endif
wolfSSL 15:117db924cf7c 82 #ifdef WOLFSSL_SHA512
wolfSSL 15:117db924cf7c 83 wc_Sha512 sha512;
wolfSSL 15:117db924cf7c 84 #endif
wolfSSL 15:117db924cf7c 85 } wc_HashAlg;
wolfSSL 15:117db924cf7c 86
wolfSSL 15:117db924cf7c 87 /* Find largest possible digest size
wolfSSL 15:117db924cf7c 88 Note if this gets up to the size of 80 or over check smallstack build */
wolfSSL 15:117db924cf7c 89 #if defined(WOLFSSL_SHA3)
wolfSSL 15:117db924cf7c 90 #define WC_MAX_DIGEST_SIZE WC_SHA3_512_DIGEST_SIZE
wolfSSL 15:117db924cf7c 91 #define WC_MAX_BLOCK_SIZE WC_SHA3_224_BLOCK_SIZE /* 224 is the largest block size */
wolfSSL 15:117db924cf7c 92 #elif defined(WOLFSSL_SHA512)
wolfSSL 15:117db924cf7c 93 #define WC_MAX_DIGEST_SIZE WC_SHA512_DIGEST_SIZE
wolfSSL 15:117db924cf7c 94 #define WC_MAX_BLOCK_SIZE WC_SHA512_BLOCK_SIZE
wolfSSL 15:117db924cf7c 95 #elif defined(HAVE_BLAKE2)
wolfSSL 15:117db924cf7c 96 #define WC_MAX_DIGEST_SIZE BLAKE2B_OUTBYTES
wolfSSL 15:117db924cf7c 97 #define WC_MAX_BLOCK_SIZE BLAKE2B_BLOCKBYTES
wolfSSL 15:117db924cf7c 98 #elif defined(WOLFSSL_SHA384)
wolfSSL 15:117db924cf7c 99 #define WC_MAX_DIGEST_SIZE WC_SHA384_DIGEST_SIZE
wolfSSL 15:117db924cf7c 100 #define WC_MAX_BLOCK_SIZE WC_SHA384_BLOCK_SIZE
wolfSSL 15:117db924cf7c 101 #elif !defined(NO_SHA256)
wolfSSL 15:117db924cf7c 102 #define WC_MAX_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
wolfSSL 15:117db924cf7c 103 #define WC_MAX_BLOCK_SIZE WC_SHA256_BLOCK_SIZE
wolfSSL 15:117db924cf7c 104 #elif defined(WOLFSSL_SHA224)
wolfSSL 15:117db924cf7c 105 #define WC_MAX_DIGEST_SIZE WC_SHA224_DIGEST_SIZE
wolfSSL 15:117db924cf7c 106 #define WC_MAX_BLOCK_SIZE WC_SHA224_BLOCK_SIZE
wolfSSL 15:117db924cf7c 107 #elif !defined(NO_SHA)
wolfSSL 15:117db924cf7c 108 #define WC_MAX_DIGEST_SIZE WC_SHA_DIGEST_SIZE
wolfSSL 15:117db924cf7c 109 #define WC_MAX_BLOCK_SIZE WC_SHA_BLOCK_SIZE
wolfSSL 15:117db924cf7c 110 #elif !defined(NO_MD5)
wolfSSL 15:117db924cf7c 111 #define WC_MAX_DIGEST_SIZE WC_MD5_DIGEST_SIZE
wolfSSL 15:117db924cf7c 112 #define WC_MAX_BLOCK_SIZE WC_MD5_BLOCK_SIZE
wolfSSL 15:117db924cf7c 113 #else
wolfSSL 15:117db924cf7c 114 #define WC_MAX_DIGEST_SIZE 64 /* default to max size of 64 */
wolfSSL 15:117db924cf7c 115 #define WC_MAX_BLOCK_SIZE 128
wolfSSL 15:117db924cf7c 116 #endif
wolfSSL 15:117db924cf7c 117
wolfSSL 15:117db924cf7c 118 #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
wolfSSL 15:117db924cf7c 119 WOLFSSL_API int wc_HashGetOID(enum wc_HashType hash_type);
wolfSSL 15:117db924cf7c 120 WOLFSSL_API enum wc_HashType wc_OidGetHash(int oid);
wolfSSL 15:117db924cf7c 121 #endif
wolfSSL 15:117db924cf7c 122
wolfSSL 15:117db924cf7c 123 WOLFSSL_API enum wc_HashType wc_HashTypeConvert(int hashType);
wolfSSL 15:117db924cf7c 124
wolfSSL 15:117db924cf7c 125 WOLFSSL_API int wc_HashGetDigestSize(enum wc_HashType hash_type);
wolfSSL 15:117db924cf7c 126 WOLFSSL_API int wc_HashGetBlockSize(enum wc_HashType hash_type);
wolfSSL 15:117db924cf7c 127 WOLFSSL_API int wc_Hash(enum wc_HashType hash_type,
wolfSSL 15:117db924cf7c 128 const byte* data, word32 data_len,
wolfSSL 15:117db924cf7c 129 byte* hash, word32 hash_len);
wolfSSL 15:117db924cf7c 130
wolfSSL 15:117db924cf7c 131 /* generic hash operation wrappers */
wolfSSL 15:117db924cf7c 132 WOLFSSL_API int wc_HashInit(wc_HashAlg* hash, enum wc_HashType type);
wolfSSL 15:117db924cf7c 133 WOLFSSL_API int wc_HashUpdate(wc_HashAlg* hash, enum wc_HashType type,
wolfSSL 15:117db924cf7c 134 const byte* data, word32 dataSz);
wolfSSL 15:117db924cf7c 135 WOLFSSL_API int wc_HashFinal(wc_HashAlg* hash, enum wc_HashType type,
wolfSSL 15:117db924cf7c 136 byte* out);
wolfSSL 15:117db924cf7c 137
wolfSSL 15:117db924cf7c 138
wolfSSL 15:117db924cf7c 139 #ifndef NO_MD5
wolfSSL 15:117db924cf7c 140 #include <wolfssl/wolfcrypt/md5.h>
wolfSSL 15:117db924cf7c 141 WOLFSSL_API int wc_Md5Hash(const byte* data, word32 len, byte* hash);
wolfSSL 15:117db924cf7c 142 #endif
wolfSSL 15:117db924cf7c 143
wolfSSL 15:117db924cf7c 144 #ifndef NO_SHA
wolfSSL 15:117db924cf7c 145 #include <wolfssl/wolfcrypt/sha.h>
wolfSSL 15:117db924cf7c 146 WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*);
wolfSSL 15:117db924cf7c 147 #endif
wolfSSL 15:117db924cf7c 148
wolfSSL 15:117db924cf7c 149 #ifdef WOLFSSL_SHA224
wolfSSL 15:117db924cf7c 150 #include <wolfssl/wolfcrypt/sha256.h>
wolfSSL 15:117db924cf7c 151 WOLFSSL_API int wc_Sha224Hash(const byte*, word32, byte*);
wolfSSL 15:117db924cf7c 152 #endif /* defined(WOLFSSL_SHA224) */
wolfSSL 15:117db924cf7c 153
wolfSSL 15:117db924cf7c 154 #ifndef NO_SHA256
wolfSSL 15:117db924cf7c 155 #include <wolfssl/wolfcrypt/sha256.h>
wolfSSL 15:117db924cf7c 156 WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*);
wolfSSL 15:117db924cf7c 157 #endif
wolfSSL 15:117db924cf7c 158
wolfSSL 15:117db924cf7c 159 #ifdef WOLFSSL_SHA384
wolfSSL 15:117db924cf7c 160 #include <wolfssl/wolfcrypt/sha512.h>
wolfSSL 15:117db924cf7c 161 WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*);
wolfSSL 15:117db924cf7c 162 #endif /* defined(WOLFSSL_SHA384) */
wolfSSL 15:117db924cf7c 163
wolfSSL 15:117db924cf7c 164 #ifdef WOLFSSL_SHA512
wolfSSL 15:117db924cf7c 165 #include <wolfssl/wolfcrypt/sha512.h>
wolfSSL 15:117db924cf7c 166 WOLFSSL_API int wc_Sha512Hash(const byte*, word32, byte*);
wolfSSL 15:117db924cf7c 167 #endif /* WOLFSSL_SHA512 */
wolfSSL 15:117db924cf7c 168
wolfSSL 15:117db924cf7c 169 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 170 } /* extern "C" */
wolfSSL 15:117db924cf7c 171 #endif
wolfSSL 15:117db924cf7c 172
wolfSSL 15:117db924cf7c 173 #endif /* WOLF_CRYPT_HASH_H */
wolfSSL 15:117db924cf7c 174