[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 53/220: md4: Move the WinCrypt implementation out o
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 53/220: md4: Move the WinCrypt implementation out of the NTLM code |
Date: |
Thu, 12 Sep 2019 17:26:53 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit c5eb2fd61869d33e48d55007e6d262c2b80e01e8
Author: Steve Holme <address@hidden>
AuthorDate: Sun Apr 14 03:17:23 2019 +0100
md4: Move the WinCrypt implementation out of the NTLM code
---
lib/curl_md4.h | 8 +++++---
lib/curl_ntlm_core.c | 14 ++------------
lib/md4.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 58 insertions(+), 18 deletions(-)
diff --git a/lib/curl_md4.h b/lib/curl_md4.h
index 59935480d..828b21af4 100644
--- a/lib/curl_md4.h
+++ b/lib/curl_md4.h
@@ -25,7 +25,8 @@
#include "curl_setup.h"
#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_MBEDTLS) && !defined(MBEDTLS_MD4_C))
@@ -34,8 +35,9 @@
void Curl_md4it(unsigned char *output, const unsigned char *input, size_t len);
#endif /* defined(USE_GNUTLS_NETTLE) || defined(USE_GNUTLS) ||
- defined(USE_OPENSSL) || defined(USE_SECTRANSP) || defined(USE_NSS) ||
- defined(USE_OS400CRYPTO) ||
+ defined(USE_OPENSSL) || defined(USE_SECTRANSP) || \
+ defined(USE_WIN32_CRYPTO) || defined(USE_NSS) || \
+ defined(USE_OS400CRYPTO) || \
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C)) */
#endif /* HEADER_CURL_MD4_H */
diff --git a/lib/curl_ntlm_core.c b/lib/curl_ntlm_core.c
index 332d9409a..abf4ac0b5 100644
--- a/lib/curl_ntlm_core.c
+++ b/lib/curl_ntlm_core.c
@@ -110,6 +110,7 @@
# include "curl_md4.h"
#elif defined(USE_WIN32_CRYPTO)
# include <wincrypt.h>
+# include "curl_md4.h"
#else
# error "Can't compile NTLM support without a crypto library."
#endif
@@ -584,18 +585,7 @@ CURLcode Curl_ntlm_core_mk_nt_hash(struct Curl_easy *data,
#elif defined(USE_OS400CRYPTO)
Curl_md4it(ntbuffer, pw, 2 * len);
#elif defined(USE_WIN32_CRYPTO)
- HCRYPTPROV hprov;
- 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);
- }
+ Curl_md4it(ntbuffer, pw, 2 * len);
#endif
memset(ntbuffer + 16, 0, 21 - 16);
diff --git a/lib/md4.c b/lib/md4.c
index eaf513774..45a17b8b0 100644
--- a/lib/md4.c
+++ b/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) || \
(defined(USE_OPENSSL) && defined(OPENSSL_NO_MD4)) || \
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C))
@@ -431,7 +477,8 @@ static void MD4_Final(unsigned char *result, MD4_CTX *ctx)
#endif /* CRYPTO LIBS */
#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_OPENSSL) && defined(OPENSSL_NO_MD4)) || \
(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) ||
- defined(USE_OPENSSL) || defined(USE_SECTRANSP) || defined(USE_NSS) ||
- defined(USE_OS400CRYPTO) ||
+ defined(USE_OPENSSL) || defined(USE_SECTRANSP) || \
+ defined(USE_WIN32_CRYPTO) || defined(USE_NSS) || \
+ defined(USE_OS400CRYPTO) || \
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C)) */
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [GNUnet-SVN] [gnurl] 76/220: quiche: flush egress in h3_stream_recv() too, (continued)
- [GNUnet-SVN] [gnurl] 76/220: quiche: flush egress in h3_stream_recv() too, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 82/220: docs/ALTSVC.md: first basic file format description, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 75/220: RELEASE-NOTES: synced, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 83/220: CURLINFO_RETRY_AFTER: parse the Retry-After header value, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 32/220: plan9: add support for running on Plan 9, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 74/220: os400: take care of CURLOPT_SASL_AUTHZID in curl_easy_setopt_ccsid()., gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 87/220: docs/ALTSVC: remove what works and the experimental explanation, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 102/220: configure: avoid undefined check_for_ca_bundle, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 51/220: md4: Use the Curl_md4it() function for OpenSSL based NTLM, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 56/220: md4: No need to include Curl_md4.h for each TLS library, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 53/220: md4: Move the WinCrypt implementation out of the NTLM code,
gnunet <=
- [GNUnet-SVN] [gnurl] 54/220: md4: Move the mbed TLS MD4 implementation out of the NTLM code, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 59/220: altsvc: fix removal of expired cache entry, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 58/220: RELEASE-NOTES: synced, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 69/220: docs/HTTP3: refreshed as it is now in master and HTTP/3 can be tested, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 78/220: quiche: make POSTFIELDS posts work, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 77/220: quiche: improved error handling and memory cleanups, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 67/220: curl_multi_poll: a sister to curl_multi_wait() that waits more, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 70/220: sasl: Implement SASL authorisation identity via CURLOPT_SASL_AUTHZID, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 71/220: curl: --sasl-authzid added to support CURLOPT_SASL_AUTHZID from the tool, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 99/220: curl_global_init_mem.3: mention it was added in 7.12.0, gnunet, 2019/09/12