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