mirror of
https://github.com/moparisthebest/curl
synced 2024-11-16 06:25:03 -05:00
md4: Move the WinCrypt implementation out of the NTLM code
This commit is contained in:
parent
11c50f7655
commit
c5eb2fd618
@ -25,7 +25,8 @@
|
|||||||
#include "curl_setup.h"
|
#include "curl_setup.h"
|
||||||
|
|
||||||
#if defined(USE_GNUTLS_NETTLE) || defined(USE_GNUTLS) || \
|
#if defined(USE_GNUTLS_NETTLE) || defined(USE_GNUTLS) || \
|
||||||
defined(USE_OPENSSL) || defined(USE_SECTRANSP) || defined(USE_NSS) || \
|
defined(USE_OPENSSL) || defined(USE_SECTRANSP) || \
|
||||||
|
defined(USE_WIN32_CRYPTO) || defined(USE_NSS) || \
|
||||||
defined(USE_OS400CRYPTO) || \
|
defined(USE_OS400CRYPTO) || \
|
||||||
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C))
|
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C))
|
||||||
|
|
||||||
@ -34,8 +35,9 @@
|
|||||||
void Curl_md4it(unsigned char *output, const unsigned char *input, size_t len);
|
void Curl_md4it(unsigned char *output, const unsigned char *input, size_t len);
|
||||||
|
|
||||||
#endif /* defined(USE_GNUTLS_NETTLE) || defined(USE_GNUTLS) ||
|
#endif /* defined(USE_GNUTLS_NETTLE) || defined(USE_GNUTLS) ||
|
||||||
defined(USE_OPENSSL) || defined(USE_SECTRANSP) || defined(USE_NSS) ||
|
defined(USE_OPENSSL) || defined(USE_SECTRANSP) || \
|
||||||
defined(USE_OS400CRYPTO) ||
|
defined(USE_WIN32_CRYPTO) || defined(USE_NSS) || \
|
||||||
|
defined(USE_OS400CRYPTO) || \
|
||||||
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C)) */
|
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C)) */
|
||||||
|
|
||||||
#endif /* HEADER_CURL_MD4_H */
|
#endif /* HEADER_CURL_MD4_H */
|
||||||
|
@ -110,6 +110,7 @@
|
|||||||
# include "curl_md4.h"
|
# include "curl_md4.h"
|
||||||
#elif defined(USE_WIN32_CRYPTO)
|
#elif defined(USE_WIN32_CRYPTO)
|
||||||
# include <wincrypt.h>
|
# include <wincrypt.h>
|
||||||
|
# include "curl_md4.h"
|
||||||
#else
|
#else
|
||||||
# error "Can't compile NTLM support without a crypto library."
|
# error "Can't compile NTLM support without a crypto library."
|
||||||
#endif
|
#endif
|
||||||
@ -584,18 +585,7 @@ CURLcode Curl_ntlm_core_mk_nt_hash(struct Curl_easy *data,
|
|||||||
#elif defined(USE_OS400CRYPTO)
|
#elif defined(USE_OS400CRYPTO)
|
||||||
Curl_md4it(ntbuffer, pw, 2 * len);
|
Curl_md4it(ntbuffer, pw, 2 * len);
|
||||||
#elif defined(USE_WIN32_CRYPTO)
|
#elif defined(USE_WIN32_CRYPTO)
|
||||||
HCRYPTPROV hprov;
|
Curl_md4it(ntbuffer, pw, 2 * len);
|
||||||
if(CryptAcquireContext(&hprov, NULL, NULL, PROV_RSA_FULL,
|
|
||||||
CRYPT_VERIFYCONTEXT)) {
|
|
||||||
HCRYPTHASH hhash;
|
|
||||||
if(CryptCreateHash(hprov, CALG_MD4, 0, 0, &hhash)) {
|
|
||||||
DWORD length = 16;
|
|
||||||
CryptHashData(hhash, pw, (unsigned int)len * 2, 0);
|
|
||||||
CryptGetHashParam(hhash, HP_HASHVAL, ntbuffer, &length, 0);
|
|
||||||
CryptDestroyHash(hhash);
|
|
||||||
}
|
|
||||||
CryptReleaseContext(hprov, 0);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memset(ntbuffer + 16, 0, 21 - 16);
|
memset(ntbuffer + 16, 0, 21 - 16);
|
||||||
|
54
lib/md4.c
54
lib/md4.c
@ -134,6 +134,52 @@ static void MD4_Final(unsigned char *result, MD4_CTX *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif defined(USE_WIN32_CRYPTO)
|
||||||
|
|
||||||
|
#include <wincrypt.h>
|
||||||
|
|
||||||
|
#include "curl_md4.h"
|
||||||
|
#include "warnless.h"
|
||||||
|
#include "curl_memory.h"
|
||||||
|
/* The last #include file should be: */
|
||||||
|
#include "memdebug.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
HCRYPTPROV hCryptProv;
|
||||||
|
HCRYPTHASH hHash;
|
||||||
|
} MD4_CTX;
|
||||||
|
|
||||||
|
static void MD4_Init(MD4_CTX *ctx)
|
||||||
|
{
|
||||||
|
ctx->hCryptProv = 0;
|
||||||
|
ctx->hHash = 0;
|
||||||
|
|
||||||
|
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_FULL,
|
||||||
|
CRYPT_VERIFYCONTEXT)) {
|
||||||
|
CryptCreateHash(ctx->hCryptProv, CALG_MD4, 0, 0, &ctx->hHash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size)
|
||||||
|
{
|
||||||
|
CryptHashData(ctx->hHash, data, (unsigned int) size, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void MD4_Final(unsigned char *result, MD4_CTX *ctx)
|
||||||
|
{
|
||||||
|
unsigned long length = 0;
|
||||||
|
|
||||||
|
CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
|
||||||
|
if(length == MD4_DIGEST_LENGTH)
|
||||||
|
CryptGetHashParam(ctx->hHash, HP_HASHVAL, result, &length, 0);
|
||||||
|
|
||||||
|
if(ctx->hHash)
|
||||||
|
CryptDestroyHash(ctx->hHash);
|
||||||
|
|
||||||
|
if(ctx->hCryptProv)
|
||||||
|
CryptReleaseContext(ctx->hCryptProv, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#elif defined(USE_NSS) || defined(USE_OS400CRYPTO) || \
|
#elif defined(USE_NSS) || defined(USE_OS400CRYPTO) || \
|
||||||
(defined(USE_OPENSSL) && defined(OPENSSL_NO_MD4)) || \
|
(defined(USE_OPENSSL) && defined(OPENSSL_NO_MD4)) || \
|
||||||
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C))
|
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C))
|
||||||
@ -431,7 +477,8 @@ static void MD4_Final(unsigned char *result, MD4_CTX *ctx)
|
|||||||
#endif /* CRYPTO LIBS */
|
#endif /* CRYPTO LIBS */
|
||||||
|
|
||||||
#if defined(USE_GNUTLS_NETTLE) || defined(USE_GNUTLS) || \
|
#if defined(USE_GNUTLS_NETTLE) || defined(USE_GNUTLS) || \
|
||||||
defined(USE_OPENSSL) || defined(USE_SECTRANSP) || defined(USE_NSS) || \
|
defined(USE_OPENSSL) || defined(USE_SECTRANSP) || \
|
||||||
|
defined(USE_WIN32_CRYPTO) || defined(USE_NSS) || \
|
||||||
defined(USE_OS400CRYPTO) || \
|
defined(USE_OS400CRYPTO) || \
|
||||||
(defined(USE_OPENSSL) && defined(OPENSSL_NO_MD4)) || \
|
(defined(USE_OPENSSL) && defined(OPENSSL_NO_MD4)) || \
|
||||||
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C))
|
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C))
|
||||||
@ -445,6 +492,7 @@ void Curl_md4it(unsigned char *output, const unsigned char *input, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* defined(USE_GNUTLS_NETTLE) || defined(USE_GNUTLS) ||
|
#endif /* defined(USE_GNUTLS_NETTLE) || defined(USE_GNUTLS) ||
|
||||||
defined(USE_OPENSSL) || defined(USE_SECTRANSP) || defined(USE_NSS) ||
|
defined(USE_OPENSSL) || defined(USE_SECTRANSP) || \
|
||||||
defined(USE_OS400CRYPTO) ||
|
defined(USE_WIN32_CRYPTO) || defined(USE_NSS) || \
|
||||||
|
defined(USE_OS400CRYPTO) || \
|
||||||
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C)) */
|
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C)) */
|
||||||
|
Loading…
Reference in New Issue
Block a user