From eff781c0aa5a0af2ef7d41ae0b91c0bee80e4b70 Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Thu, 28 Sep 2017 11:12:18 -0600 Subject: [PATCH] add int return to OpenSSL compatibility MD5 functions --- src/ssl.c | 34 ++++++++++++++++++++++++++++------ wolfssl/openssl/md5.h | 6 +++--- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index 523b25bb0..16b8da245 100755 --- a/src/ssl.c +++ b/src/ssl.c @@ -11959,7 +11959,7 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out, #ifndef NO_MD5 - void wolfSSL_MD5_Init(WOLFSSL_MD5_CTX* md5) + int wolfSSL_MD5_Init(WOLFSSL_MD5_CTX* md5) { int ret; typedef char md5_test[sizeof(MD5_CTX) >= sizeof(Md5) ? 1 : -1]; @@ -11967,22 +11967,43 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out, WOLFSSL_ENTER("MD5_Init"); ret = wc_InitMd5((Md5*)md5); - (void)ret; + + /* return 1 on success, 0 otherwise */ + if (ret == 0) + return 1; + + return 0; } - void wolfSSL_MD5_Update(WOLFSSL_MD5_CTX* md5, const void* input, + int wolfSSL_MD5_Update(WOLFSSL_MD5_CTX* md5, const void* input, unsigned long sz) { + int ret; + WOLFSSL_ENTER("wolfSSL_MD5_Update"); - wc_Md5Update((Md5*)md5, (const byte*)input, (word32)sz); + ret = wc_Md5Update((Md5*)md5, (const byte*)input, (word32)sz); + + /* return 1 on success, 0 otherwise */ + if (ret == 0) + return 1; + + return 0; } - void wolfSSL_MD5_Final(byte* input, WOLFSSL_MD5_CTX* md5) + int wolfSSL_MD5_Final(byte* input, WOLFSSL_MD5_CTX* md5) { + int ret; + WOLFSSL_ENTER("MD5_Final"); - wc_Md5Final((Md5*)md5, input); + ret = wc_Md5Final((Md5*)md5, input); + + /* return 1 on success, 0 otherwise */ + if (ret == 0) + return 1; + + return 0; } #endif /* NO_MD5 */ @@ -11991,6 +12012,7 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out, int wolfSSL_SHA_Init(WOLFSSL_SHA_CTX* sha) { int ret; + typedef char sha_test[sizeof(SHA_CTX) >= sizeof(Sha) ? 1 : -1]; (void)sizeof(sha_test); diff --git a/wolfssl/openssl/md5.h b/wolfssl/openssl/md5.h index c4f05d30c..1e5ca3bad 100644 --- a/wolfssl/openssl/md5.h +++ b/wolfssl/openssl/md5.h @@ -21,9 +21,9 @@ typedef struct WOLFSSL_MD5_CTX { int holder[28 + (WC_ASYNC_DEV_SIZE / sizeof(int))]; /* big enough to hold wolfcrypt md5, but check on init */ } WOLFSSL_MD5_CTX; -WOLFSSL_API void wolfSSL_MD5_Init(WOLFSSL_MD5_CTX*); -WOLFSSL_API void wolfSSL_MD5_Update(WOLFSSL_MD5_CTX*, const void*, unsigned long); -WOLFSSL_API void wolfSSL_MD5_Final(unsigned char*, WOLFSSL_MD5_CTX*); +WOLFSSL_API int wolfSSL_MD5_Init(WOLFSSL_MD5_CTX*); +WOLFSSL_API int wolfSSL_MD5_Update(WOLFSSL_MD5_CTX*, const void*, unsigned long); +WOLFSSL_API int wolfSSL_MD5_Final(unsigned char*, WOLFSSL_MD5_CTX*); typedef WOLFSSL_MD5_CTX MD5_CTX;