wolfSSL 3.11.1 for TLS1.3 beta
Fork of wolfSSL by
wolfssl/wolfcrypt/hash.h@4:1b0d80432c79, 2016-04-28 (annotated)
- Committer:
- wolfSSL
- Date:
- Thu Apr 28 00:57:21 2016 +0000
- Revision:
- 4:1b0d80432c79
wolfSSL 3.9.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 4:1b0d80432c79 | 1 | /* hash.h |
wolfSSL | 4:1b0d80432c79 | 2 | * |
wolfSSL | 4:1b0d80432c79 | 3 | * Copyright (C) 2006-2016 wolfSSL Inc. |
wolfSSL | 4:1b0d80432c79 | 4 | * |
wolfSSL | 4:1b0d80432c79 | 5 | * This file is part of wolfSSL. |
wolfSSL | 4:1b0d80432c79 | 6 | * |
wolfSSL | 4:1b0d80432c79 | 7 | * wolfSSL is free software; you can redistribute it and/or modify |
wolfSSL | 4:1b0d80432c79 | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 4:1b0d80432c79 | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 4:1b0d80432c79 | 10 | * (at your option) any later version. |
wolfSSL | 4:1b0d80432c79 | 11 | * |
wolfSSL | 4:1b0d80432c79 | 12 | * wolfSSL is distributed in the hope that it will be useful, |
wolfSSL | 4:1b0d80432c79 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 4:1b0d80432c79 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 4:1b0d80432c79 | 15 | * GNU General Public License for more details. |
wolfSSL | 4:1b0d80432c79 | 16 | * |
wolfSSL | 4:1b0d80432c79 | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 4:1b0d80432c79 | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 4:1b0d80432c79 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
wolfSSL | 4:1b0d80432c79 | 20 | */ |
wolfSSL | 4:1b0d80432c79 | 21 | |
wolfSSL | 4:1b0d80432c79 | 22 | |
wolfSSL | 4:1b0d80432c79 | 23 | #ifndef WOLF_CRYPT_HASH_H |
wolfSSL | 4:1b0d80432c79 | 24 | #define WOLF_CRYPT_HASH_H |
wolfSSL | 4:1b0d80432c79 | 25 | |
wolfSSL | 4:1b0d80432c79 | 26 | #include <wolfssl/wolfcrypt/types.h> |
wolfSSL | 4:1b0d80432c79 | 27 | |
wolfSSL | 4:1b0d80432c79 | 28 | #ifdef __cplusplus |
wolfSSL | 4:1b0d80432c79 | 29 | extern "C" { |
wolfSSL | 4:1b0d80432c79 | 30 | #endif |
wolfSSL | 4:1b0d80432c79 | 31 | |
wolfSSL | 4:1b0d80432c79 | 32 | /* Hash types */ |
wolfSSL | 4:1b0d80432c79 | 33 | enum wc_HashType { |
wolfSSL | 4:1b0d80432c79 | 34 | WC_HASH_TYPE_NONE = 0, |
wolfSSL | 4:1b0d80432c79 | 35 | WC_HASH_TYPE_MD2 = 1, |
wolfSSL | 4:1b0d80432c79 | 36 | WC_HASH_TYPE_MD4 = 2, |
wolfSSL | 4:1b0d80432c79 | 37 | WC_HASH_TYPE_MD5 = 3, |
wolfSSL | 4:1b0d80432c79 | 38 | WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */ |
wolfSSL | 4:1b0d80432c79 | 39 | WC_HASH_TYPE_SHA256 = 5, |
wolfSSL | 4:1b0d80432c79 | 40 | WC_HASH_TYPE_SHA384 = 6, |
wolfSSL | 4:1b0d80432c79 | 41 | WC_HASH_TYPE_SHA512 = 7, |
wolfSSL | 4:1b0d80432c79 | 42 | }; |
wolfSSL | 4:1b0d80432c79 | 43 | |
wolfSSL | 4:1b0d80432c79 | 44 | /* Find largest possible digest size |
wolfSSL | 4:1b0d80432c79 | 45 | Note if this gets up to the size of 80 or over check smallstack build */ |
wolfSSL | 4:1b0d80432c79 | 46 | #if defined(WOLFSSL_SHA512) |
wolfSSL | 4:1b0d80432c79 | 47 | #define WC_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE |
wolfSSL | 4:1b0d80432c79 | 48 | #elif defined(WOLFSSL_SHA384) |
wolfSSL | 4:1b0d80432c79 | 49 | #define WC_MAX_DIGEST_SIZE SHA384_DIGEST_SIZE |
wolfSSL | 4:1b0d80432c79 | 50 | #elif !defined(NO_SHA256) |
wolfSSL | 4:1b0d80432c79 | 51 | #define WC_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE |
wolfSSL | 4:1b0d80432c79 | 52 | #elif !defined(NO_SHA) |
wolfSSL | 4:1b0d80432c79 | 53 | #define WC_MAX_DIGEST_SIZE SHA_DIGEST_SIZE |
wolfSSL | 4:1b0d80432c79 | 54 | #elif !defined(NO_MD5) |
wolfSSL | 4:1b0d80432c79 | 55 | #define WC_MAX_DIGEST_SIZE MD5_DIGEST_SIZE |
wolfSSL | 4:1b0d80432c79 | 56 | #else |
wolfSSL | 4:1b0d80432c79 | 57 | #define WC_MAX_DIGEST_SIZE 64 /* default to max size of 64 */ |
wolfSSL | 4:1b0d80432c79 | 58 | #endif |
wolfSSL | 4:1b0d80432c79 | 59 | |
wolfSSL | 4:1b0d80432c79 | 60 | #ifndef NO_ASN |
wolfSSL | 4:1b0d80432c79 | 61 | WOLFSSL_API int wc_HashGetOID(enum wc_HashType hash_type); |
wolfSSL | 4:1b0d80432c79 | 62 | #endif |
wolfSSL | 4:1b0d80432c79 | 63 | |
wolfSSL | 4:1b0d80432c79 | 64 | WOLFSSL_API int wc_HashGetDigestSize(enum wc_HashType hash_type); |
wolfSSL | 4:1b0d80432c79 | 65 | WOLFSSL_API int wc_Hash(enum wc_HashType hash_type, |
wolfSSL | 4:1b0d80432c79 | 66 | const byte* data, word32 data_len, |
wolfSSL | 4:1b0d80432c79 | 67 | byte* hash, word32 hash_len); |
wolfSSL | 4:1b0d80432c79 | 68 | |
wolfSSL | 4:1b0d80432c79 | 69 | |
wolfSSL | 4:1b0d80432c79 | 70 | #ifndef NO_MD5 |
wolfSSL | 4:1b0d80432c79 | 71 | #include <wolfssl/wolfcrypt/md5.h> |
wolfSSL | 4:1b0d80432c79 | 72 | WOLFSSL_API void wc_Md5GetHash(Md5*, byte*); |
wolfSSL | 4:1b0d80432c79 | 73 | WOLFSSL_API void wc_Md5RestorePos(Md5*, Md5*); |
wolfSSL | 4:1b0d80432c79 | 74 | #if defined(WOLFSSL_TI_HASH) |
wolfSSL | 4:1b0d80432c79 | 75 | WOLFSSL_API void wc_Md5Free(Md5*); |
wolfSSL | 4:1b0d80432c79 | 76 | #else |
wolfSSL | 4:1b0d80432c79 | 77 | #define wc_Md5Free(d) |
wolfSSL | 4:1b0d80432c79 | 78 | #endif |
wolfSSL | 4:1b0d80432c79 | 79 | #endif |
wolfSSL | 4:1b0d80432c79 | 80 | |
wolfSSL | 4:1b0d80432c79 | 81 | #ifndef NO_SHA |
wolfSSL | 4:1b0d80432c79 | 82 | #include <wolfssl/wolfcrypt/sha.h> |
wolfSSL | 4:1b0d80432c79 | 83 | WOLFSSL_API int wc_ShaGetHash(Sha*, byte*); |
wolfSSL | 4:1b0d80432c79 | 84 | WOLFSSL_API void wc_ShaRestorePos(Sha*, Sha*); |
wolfSSL | 4:1b0d80432c79 | 85 | WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*); |
wolfSSL | 4:1b0d80432c79 | 86 | #if defined(WOLFSSL_TI_HASH) |
wolfSSL | 4:1b0d80432c79 | 87 | WOLFSSL_API void wc_ShaFree(Sha*); |
wolfSSL | 4:1b0d80432c79 | 88 | #else |
wolfSSL | 4:1b0d80432c79 | 89 | #define wc_ShaFree(d) |
wolfSSL | 4:1b0d80432c79 | 90 | #endif |
wolfSSL | 4:1b0d80432c79 | 91 | #endif |
wolfSSL | 4:1b0d80432c79 | 92 | |
wolfSSL | 4:1b0d80432c79 | 93 | #ifndef NO_SHA256 |
wolfSSL | 4:1b0d80432c79 | 94 | #include <wolfssl/wolfcrypt/sha256.h> |
wolfSSL | 4:1b0d80432c79 | 95 | WOLFSSL_API int wc_Sha256GetHash(Sha256*, byte*); |
wolfSSL | 4:1b0d80432c79 | 96 | WOLFSSL_API void wc_Sha256RestorePos(Sha256*, Sha256*); |
wolfSSL | 4:1b0d80432c79 | 97 | WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*); |
wolfSSL | 4:1b0d80432c79 | 98 | #if defined(WOLFSSL_TI_HASH) |
wolfSSL | 4:1b0d80432c79 | 99 | WOLFSSL_API void wc_Sha256Free(Sha256*); |
wolfSSL | 4:1b0d80432c79 | 100 | #else |
wolfSSL | 4:1b0d80432c79 | 101 | #define wc_Sha256Free(d) |
wolfSSL | 4:1b0d80432c79 | 102 | #endif |
wolfSSL | 4:1b0d80432c79 | 103 | #endif |
wolfSSL | 4:1b0d80432c79 | 104 | |
wolfSSL | 4:1b0d80432c79 | 105 | #ifdef WOLFSSL_SHA512 |
wolfSSL | 4:1b0d80432c79 | 106 | #include <wolfssl/wolfcrypt/sha512.h> |
wolfSSL | 4:1b0d80432c79 | 107 | WOLFSSL_API int wc_Sha512Hash(const byte*, word32, byte*); |
wolfSSL | 4:1b0d80432c79 | 108 | #if defined(WOLFSSL_TI_HASH) |
wolfSSL | 4:1b0d80432c79 | 109 | WOLFSSL_API void wc_Sha512Free(Sha512*); |
wolfSSL | 4:1b0d80432c79 | 110 | #else |
wolfSSL | 4:1b0d80432c79 | 111 | #define wc_Sha512Free(d) |
wolfSSL | 4:1b0d80432c79 | 112 | #endif |
wolfSSL | 4:1b0d80432c79 | 113 | #if defined(WOLFSSL_SHA384) |
wolfSSL | 4:1b0d80432c79 | 114 | WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*); |
wolfSSL | 4:1b0d80432c79 | 115 | #if defined(WOLFSSL_TI_HASH) |
wolfSSL | 4:1b0d80432c79 | 116 | WOLFSSL_API void wc_Sha384Free(Sha384*); |
wolfSSL | 4:1b0d80432c79 | 117 | #else |
wolfSSL | 4:1b0d80432c79 | 118 | #define wc_Sha384Free(d) |
wolfSSL | 4:1b0d80432c79 | 119 | #endif |
wolfSSL | 4:1b0d80432c79 | 120 | #endif /* defined(WOLFSSL_SHA384) */ |
wolfSSL | 4:1b0d80432c79 | 121 | #endif /* WOLFSSL_SHA512 */ |
wolfSSL | 4:1b0d80432c79 | 122 | |
wolfSSL | 4:1b0d80432c79 | 123 | |
wolfSSL | 4:1b0d80432c79 | 124 | #ifdef __cplusplus |
wolfSSL | 4:1b0d80432c79 | 125 | } /* extern "C" */ |
wolfSSL | 4:1b0d80432c79 | 126 | #endif |
wolfSSL | 4:1b0d80432c79 | 127 | |
wolfSSL | 4:1b0d80432c79 | 128 | #endif /* WOLF_CRYPT_HASH_H */ |
wolfSSL | 4:1b0d80432c79 | 129 |