Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of wolfSSL by
hash.h
00001 /* hash.h 00002 * 00003 * Copyright (C) 2006-2016 wolfSSL Inc. 00004 * 00005 * This file is part of wolfSSL. 00006 * 00007 * wolfSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * wolfSSL is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 00020 */ 00021 00022 00023 #ifndef WOLF_CRYPT_HASH_H 00024 #define WOLF_CRYPT_HASH_H 00025 00026 #include <wolfssl/wolfcrypt/types.h> 00027 00028 #ifndef NO_MD5 00029 #include <wolfssl/wolfcrypt/md5.h> 00030 #endif 00031 #ifndef NO_SHA 00032 #include <wolfssl/wolfcrypt/sha.h> 00033 #endif 00034 #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) 00035 #include <wolfssl/wolfcrypt/sha256.h> 00036 #endif 00037 #if defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512) 00038 #include <wolfssl/wolfcrypt/sha512.h> 00039 #endif 00040 00041 #ifdef __cplusplus 00042 extern "C" { 00043 #endif 00044 00045 /* Hash types */ 00046 enum wc_HashType { 00047 WC_HASH_TYPE_NONE = 0, 00048 WC_HASH_TYPE_MD2 = 1, 00049 WC_HASH_TYPE_MD4 = 2, 00050 WC_HASH_TYPE_MD5 = 3, 00051 WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */ 00052 WC_HASH_TYPE_SHA224 = 9, 00053 WC_HASH_TYPE_SHA256 = 5, 00054 WC_HASH_TYPE_SHA384 = 6, 00055 WC_HASH_TYPE_SHA512 = 7, 00056 WC_HASH_TYPE_MD5_SHA = 8, 00057 }; 00058 00059 typedef union { 00060 #ifndef NO_MD5 00061 Md5 md5; 00062 #endif 00063 #ifndef NO_SHA 00064 Sha sha; 00065 #endif 00066 #ifdef WOLFSSL_SHA224 00067 Sha224 sha224; 00068 #endif 00069 #ifndef NO_SHA256 00070 Sha256 sha256; 00071 #endif 00072 #ifdef WOLFSSL_SHA384 00073 Sha384 sha384; 00074 #endif 00075 #ifdef WOLFSSL_SHA512 00076 Sha512 sha512; 00077 #endif 00078 } wc_HashAlg; 00079 00080 /* Find largest possible digest size 00081 Note if this gets up to the size of 80 or over check smallstack build */ 00082 #if defined(WOLFSSL_SHA512) 00083 #define WC_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE 00084 #elif defined(WOLFSSL_SHA384) 00085 #define WC_MAX_DIGEST_SIZE SHA384_DIGEST_SIZE 00086 #elif !defined(NO_SHA256) 00087 #define WC_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE 00088 #elif defined(WOLFSSL_SHA224) 00089 #define WC_MAX_DIGEST_SIZE SHA224_DIGEST_SIZE 00090 #elif !defined(NO_SHA) 00091 #define WC_MAX_DIGEST_SIZE SHA_DIGEST_SIZE 00092 #elif !defined(NO_MD5) 00093 #define WC_MAX_DIGEST_SIZE MD5_DIGEST_SIZE 00094 #else 00095 #define WC_MAX_DIGEST_SIZE 64 /* default to max size of 64 */ 00096 #endif 00097 00098 #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) 00099 WOLFSSL_API int wc_HashGetOID(enum wc_HashType hash_type); 00100 #endif 00101 00102 WOLFSSL_API int wc_HashGetDigestSize(enum wc_HashType hash_type); 00103 WOLFSSL_API int wc_Hash(enum wc_HashType hash_type, 00104 const byte* data, word32 data_len, 00105 byte* hash, word32 hash_len); 00106 00107 /* generic hash operation wrappers */ 00108 WOLFSSL_API int wc_HashInit(wc_HashAlg* hash, enum wc_HashType type); 00109 WOLFSSL_API int wc_HashUpdate(wc_HashAlg* hash, enum wc_HashType type, 00110 const byte* data, word32 dataSz); 00111 WOLFSSL_API int wc_HashFinal(wc_HashAlg* hash, enum wc_HashType type, 00112 byte* out); 00113 00114 00115 #ifndef NO_MD5 00116 #include <wolfssl/wolfcrypt/md5.h> 00117 WOLFSSL_API int wc_Md5Hash(const byte* data, word32 len, byte* hash); 00118 #endif 00119 00120 #ifndef NO_SHA 00121 #include <wolfssl/wolfcrypt/sha.h> 00122 WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*); 00123 #endif 00124 00125 #ifndef NO_SHA256 00126 #include <wolfssl/wolfcrypt/sha256.h> 00127 WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*); 00128 00129 #if defined(WOLFSSL_SHA224) 00130 WOLFSSL_API int wc_Sha224Hash(const byte*, word32, byte*); 00131 #endif /* defined(WOLFSSL_SHA224) */ 00132 #endif 00133 00134 #ifdef WOLFSSL_SHA512 00135 #include <wolfssl/wolfcrypt/sha512.h> 00136 WOLFSSL_API int wc_Sha512Hash(const byte*, word32, byte*); 00137 00138 #if defined(WOLFSSL_SHA384) 00139 WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*); 00140 #endif /* defined(WOLFSSL_SHA384) */ 00141 #endif /* WOLFSSL_SHA512 */ 00142 00143 #ifdef __cplusplus 00144 } /* extern "C" */ 00145 #endif 00146 00147 #endif /* WOLF_CRYPT_HASH_H */ 00148
Generated on Tue Jul 12 2022 23:30:55 by
1.7.2
