md5.h
Go to the documentation of this file.
1 /* md5.h
2  *
3  * Copyright (C) 2006-2020 wolfSSL Inc.
4  *
5  * This file is part of wolfSSL.
6  *
7  * wolfSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * wolfSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20  */
21 
27 #ifndef WOLF_CRYPT_MD5_H
28 #define WOLF_CRYPT_MD5_H
29 
31 
32 #ifndef NO_MD5
33 
34 #ifdef HAVE_FIPS
35  #define wc_InitMd5 InitMd5
36  #define wc_Md5Update Md5Update
37  #define wc_Md5Final Md5Final
38  #define wc_Md5Hash Md5Hash
39 #endif
40 
41 #ifdef __cplusplus
42  extern "C" {
43 #endif
44 
45 #ifndef NO_OLD_WC_NAMES
46  #define Md5 wc_Md5
47  #define MD5 WC_MD5
48  #define MD5_BLOCK_SIZE WC_MD5_BLOCK_SIZE
49  #define MD5_DIGEST_SIZE WC_MD5_DIGEST_SIZE
50  #define WC_MD5_PAD_SIZE WC_MD5_PAD_SIZE
51 #endif
52 
53 /* in bytes */
54 enum {
55  WC_MD5 = WC_HASH_TYPE_MD5,
56  WC_MD5_BLOCK_SIZE = 64,
57  WC_MD5_DIGEST_SIZE = 16,
58  WC_MD5_PAD_SIZE = 56
59 };
60 
61 
62 #ifdef WOLFSSL_MICROCHIP_PIC32MZ
63  #include <wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h>
64 #endif
65 #ifdef STM32_HASH
66  #include <wolfssl/wolfcrypt/port/st/stm32.h>
67 #endif
68 #ifdef WOLFSSL_ASYNC_CRYPT
69  #include <wolfssl/wolfcrypt/async.h>
70 #endif
71 
72 #ifdef WOLFSSL_TI_HASH
73  #include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
74 #elif defined(WOLFSSL_IMX6_CAAM)
75  #include "wolfssl/wolfcrypt/port/caam/wolfcaam_sha.h"
76 #else
77 
78 /* MD5 digest */
79 typedef struct wc_Md5 {
80 #ifdef STM32_HASH
81  STM32_HASH_Context stmCtx;
82 #else
83  word32 buffLen; /* in bytes */
84  word32 loLen; /* length in bytes */
85  word32 hiLen; /* length in bytes */
86  word32 buffer[WC_MD5_BLOCK_SIZE / sizeof(word32)];
87 #ifdef WOLFSSL_PIC32MZ_HASH
88  word32 digest[PIC32_DIGEST_SIZE / sizeof(word32)];
89 #else
90  word32 digest[WC_MD5_DIGEST_SIZE / sizeof(word32)];
91 #endif
92  void* heap;
93 #ifdef WOLFSSL_PIC32MZ_HASH
94  hashUpdCache cache; /* cache for updates */
95 #endif
96 #endif /* STM32_HASH */
97 #ifdef WOLFSSL_ASYNC_CRYPT
98  WC_ASYNC_DEV asyncDev;
99 #endif /* WOLFSSL_ASYNC_CRYPT */
100 #if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
101  word32 flags; /* enum wc_HashFlags in hash.h */
102 #endif
103 } wc_Md5;
104 
105 #endif /* WOLFSSL_TI_HASH */
106 
107 WOLFSSL_API int wc_InitMd5(wc_Md5*);
108 WOLFSSL_API int wc_InitMd5_ex(wc_Md5*, void*, int);
109 WOLFSSL_API int wc_Md5Update(wc_Md5*, const byte*, word32);
110 WOLFSSL_API int wc_Md5Final(wc_Md5*, byte*);
111 WOLFSSL_API void wc_Md5Free(wc_Md5*);
112 
113 WOLFSSL_API int wc_Md5GetHash(wc_Md5*, byte*);
114 WOLFSSL_API int wc_Md5Copy(wc_Md5*, wc_Md5*);
115 
116 #ifdef WOLFSSL_PIC32MZ_HASH
117 WOLFSSL_API void wc_Md5SizeSet(wc_Md5* md5, word32 len);
118 #endif
119 
120 #if defined(WOLFSSL_HASH_FLAGS) || defined(WOLF_CRYPTO_CB)
121  WOLFSSL_API int wc_Md5SetFlags(wc_Md5* md5, word32 flags);
122  WOLFSSL_API int wc_Md5GetFlags(wc_Md5* md5, word32* flags);
123 #endif
124 
125 #ifdef __cplusplus
126  } /* extern "C" */
127 #endif
128 
129 #endif /* NO_MD5 */
130 #endif /* WOLF_CRYPT_MD5_H */
Definition: md5.h:79
Definition: pic32mz-crypt.h:115
WOLFSSL_API int wc_InitMd5(wc_Md5 *)
This function initializes md5. This is automatically called by wc_Md5Hash.
Definition: md5.c:495
Definition: stm32.h:67
WOLFSSL_API int wc_Md5GetHash(wc_Md5 *, byte *)
Gets hash data. Result is placed into hash. Md5 struct is not reset.
Definition: md5.c:516
WOLFSSL_API int wc_Md5Final(wc_Md5 *, byte *)
Finalizes hashing of data. Result is placed into hash. Md5 Struct is reset. Note: This function will ...
Definition: md5.c:436
WOLFSSL_API void wc_Md5Free(wc_Md5 *)
Resets the Md5 structure. Note: this is only supported if you have WOLFSSL_TI_HASH defined...
Definition: md5.c:503
WOLFSSL_API int wc_Md5Update(wc_Md5 *, const byte *, word32)
Can be called to continually hash the provided byte array of length len.
Definition: md5.c:335