add wolfSSL_EVP_md4 function

This commit is contained in:
Jacob Barthelmeh
2017-04-13 17:36:12 -06:00
parent ca50d13149
commit 47f234dce2
7 changed files with 135 additions and 15 deletions

View File

@@ -12856,7 +12856,9 @@ const WOLFSSL_EVP_MD *wolfSSL_EVP_get_digestbyname(const char *name)
static const struct alias {
const char *name;
const char *alias;
} alias_tbl[] = {
} alias_tbl[] =
{
{"MD4", "ssl3-md4"},
{"MD5", "ssl3-md5"},
{"SHA", "ssl3-sha1"},
{"SHA", "SHA1"},
@@ -12904,6 +12906,18 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
}
#ifndef NO_MD4
/* return a pointer to MD4 EVP type */
const WOLFSSL_EVP_MD* wolfSSL_EVP_md4(void)
{
WOLFSSL_ENTER("wolfSSL_EVP_md4");
return EVP_get_digestbyname("MD4");
}
#endif /* NO_MD4 */
#ifndef NO_MD5
const WOLFSSL_EVP_MD* wolfSSL_EVP_md5(void)
@@ -13861,6 +13875,12 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
ret = wolfSSL_SHA512_Init(&(ctx->hash.digest.sha512));
}
#endif
#ifndef NO_MD4
else if (XSTRNCMP(type, "MD4", 3) == 0) {
ctx->macType = MD4;
wolfSSL_MD4_Init(&(ctx->hash.digest.md4));
}
#endif
#ifndef NO_MD5
else if (XSTRNCMP(type, "MD5", 3) == 0) {
ctx->macType = WC_MD5;
@@ -13888,6 +13908,12 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
WOLFSSL_ENTER("EVP_DigestUpdate");
switch (ctx->macType) {
#ifndef NO_MD4
case MD4:
wolfSSL_MD4_Update((MD4_CTX*)&ctx->hash, data,
(unsigned long)sz);
break;
#endif
#ifndef NO_MD5
case WC_MD5:
wolfSSL_MD5_Update((MD5_CTX*)&ctx->hash, data,
@@ -13938,6 +13964,12 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
{
WOLFSSL_ENTER("EVP_DigestFinal");
switch (ctx->macType) {
#ifndef NO_MD4
case MD4:
wolfSSL_MD4_Final(md, (MD4_CTX*)&ctx->hash);
if (s) *s = MD4_DIGEST_SIZE;
break;
#endif
#ifndef NO_MD5
case WC_MD5:
wolfSSL_MD5_Final(md, (MD5_CTX*)&ctx->hash);

View File

@@ -15877,6 +15877,29 @@ static void test_wolfSSL_sk_GENERAL_NAME(void)
#endif
}
static void test_wolfSSL_MD4(void)
{
#if defined(OPENSSL_EXTRA) && !defined(NO_MD4)
MD4_CTX md4;
unsigned char out[16]; /* MD4_DIGEST_SIZE */
const char* msg = "12345678901234567890123456789012345678901234567890123456"
"789012345678901234567890";
const char* test = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f"
"\xcc\x05\x36";
int msgSz = (int)XSTRLEN(msg);
printf(testingFmt, "wolfSSL_MD4()");
XMEMSET(out, 0, sizeof(out));
MD4_Init(&md4);
MD4_Update(&md4, (const void*)msg, (unsigned long)msgSz);
MD4_Final(out, &md4);
AssertIntEQ(XMEMCMP(out, test, sizeof(out)), 0);
printf(resultFmt, passed);
#endif
}
static void test_no_op_functions(void)
{
#if defined(OPENSSL_EXTRA)
@@ -16698,6 +16721,7 @@ void ApiTest(void)
test_wolfSSL_SESSION();
test_wolfSSL_DES_ecb_encrypt();
test_wolfSSL_sk_GENERAL_NAME();
test_wolfSSL_MD4();
/* test the no op functions for compatibility */
test_no_op_functions();

View File

@@ -35,6 +35,9 @@
#include "prefix_evp.h"
#endif
#ifndef NO_MD4
#include <wolfssl/openssl/md4.h>
#endif
#ifndef NO_MD5
#include <wolfssl/openssl/md5.h>
#endif
@@ -64,6 +67,9 @@ typedef struct WOLFSSL_EVP_PKEY WOLFSSL_EVP_PKEY;
#define WOLFSSL_EVP_TYPE_DEFINED
#endif
#ifndef NO_MD4
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_md4(void);
#endif
#ifndef NO_MD5
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_md5(void);
#endif
@@ -93,6 +99,9 @@ WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_enc_null(void);
typedef union {
#ifndef NO_MD4
WOLFSSL_MD4_CTX md4;
#endif
#ifndef NO_MD5
WOLFSSL_MD5_CTX md5;
#endif
@@ -414,6 +423,9 @@ typedef WOLFSSL_EVP_CIPHER EVP_CIPHER;
typedef WOLFSSL_EVP_MD_CTX EVP_MD_CTX;
typedef WOLFSSL_EVP_CIPHER_CTX EVP_CIPHER_CTX;
#ifndef NO_MD4
#define EVP_md4 wolfSSL_EVP_md4
#endif
#ifndef NO_MD5
#define EVP_md5 wolfSSL_EVP_md5
#endif

View File

@@ -1 +1,62 @@
/* md4.h for libcurl */
/* md4.h
*
* Copyright (C) 2006-2016 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef WOLFSSL_MD4_H_
#define WOLFSSL_MD4_H_
#include <wolfssl/wolfcrypt/settings.h>
#ifndef NO_MD4
#ifdef WOLFSSL_PREFIX
#include "prefix_md4.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct WOLFSSL_MD4_CTX {
int buffer[32]; /* big enough to hold, check size in Init */
} WOLFSSL_MD4_CTX;
WOLFSSL_API void wolfSSL_MD4_Init(WOLFSSL_MD4_CTX*);
WOLFSSL_API void wolfSSL_MD4_Update(WOLFSSL_MD4_CTX*, const void*, unsigned long);
WOLFSSL_API void wolfSSL_MD4_Final(unsigned char*, WOLFSSL_MD4_CTX*);
typedef WOLFSSL_MD4_CTX MD4_CTX;
#define MD4_Init wolfSSL_MD4_Init
#define MD4_Update wolfSSL_MD4_Update
#define MD4_Final wolfSSL_MD4_Final
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* NO_MD4 */
#endif /* WOLFSSL_MD4_H_ */

View File

@@ -91,7 +91,6 @@ typedef WOLFSSL_ASN1_OBJECT BASIC_CONSTRAINTS;
#define ASN1_UTCTIME WOLFSSL_ASN1_TIME
#define ASN1_GENERALIZEDTIME WOLFSSL_ASN1_TIME
typedef WOLFSSL_MD4_CTX MD4_CTX;
typedef WOLFSSL_COMP_METHOD COMP_METHOD;
typedef WOLFSSL_X509_REVOKED X509_REVOKED;
typedef WOLFSSL_X509_OBJECT X509_OBJECT;
@@ -251,9 +250,9 @@ typedef WOLFSSL_X509_STORE_CTX X509_STORE_CTX;
#define SSLv2_client_method wolfSSLv2_client_method
#define SSLv2_server_method wolfSSLv2_server_method
#define MD4_Init wolfSSL_MD4_Init
#define MD4_Update wolfSSL_MD4_Update
#define MD4_Final wolfSSL_MD4_Final
#define MD4_Init wolfSSL_MD4_Init
#define MD4_Update wolfSSL_MD4_Update
#define MD4_Final wolfSSL_MD4_Final
#define BIO_new wolfSSL_BIO_new
#define BIO_free wolfSSL_BIO_free

View File

@@ -247,10 +247,6 @@ typedef char WOLFSSL_EVP_MD;
#define WOLFSSL_EVP_PKEY_DEFAULT EVP_PKEY_RSA /* default key type */
typedef struct WOLFSSL_MD4_CTX {
int buffer[32]; /* big enough to hold, check size in Init */
} WOLFSSL_MD4_CTX;
enum BIO_TYPE {
WOLFSSL_BIO_BUFFER = 1,
@@ -748,11 +744,6 @@ WOLFSSL_API WOLFSSL_METHOD* wolfSSLv23_client_method(void);
WOLFSSL_API WOLFSSL_METHOD* wolfSSLv2_client_method(void);
WOLFSSL_API WOLFSSL_METHOD* wolfSSLv2_server_method(void);
WOLFSSL_API void wolfSSL_MD4_Init(WOLFSSL_MD4_CTX*);
WOLFSSL_API void wolfSSL_MD4_Update(WOLFSSL_MD4_CTX*, const void*, unsigned long);
WOLFSSL_API void wolfSSL_MD4_Final(unsigned char*, WOLFSSL_MD4_CTX*);
WOLFSSL_API WOLFSSL_BIO* wolfSSL_BIO_new(WOLFSSL_BIO_METHOD*);
WOLFSSL_API int wolfSSL_BIO_free(WOLFSSL_BIO*);
WOLFSSL_API int wolfSSL_BIO_free_all(WOLFSSL_BIO*);

View File

@@ -33,6 +33,7 @@
/* in bytes */
enum {
MD4 = 9, /* hash type unique */
MD4_BLOCK_SIZE = 64,
MD4_DIGEST_SIZE = 16,
MD4_PAD_SIZE = 56