summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Holme <steve_holme@hotmail.com>2020-02-20 01:49:31 +0000
committerSteve Holme <steve_holme@hotmail.com>2020-03-08 11:45:28 +0000
commit1369b8ad31d5fff44af1a0f2b5fa8b24b4c24b09 (patch)
tree27756d15b8504acc1e07ce8f759fee9daf567d75
parent92d63a10aa12b7c76f54fbdd8a362ddb3a64ae52 (diff)
downloadcurl-1369b8ad31d5fff44af1a0f2b5fa8b24b4c24b09.tar.gz
sha256: Added WinCrypt implementation
Closed #5030
-rw-r--r--lib/sha256.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/sha256.c b/lib/sha256.c
index a14f42aa3..352d577e8 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -192,6 +192,49 @@ static void SHA256_Final(unsigned char *digest, SHA256_CTX *ctx)
(void) CC_SHA256_Final(digest, ctx);
}
+#elif defined(USE_WIN32_CRYPTO)
+
+#include <wincrypt.h>
+
+typedef struct {
+ HCRYPTPROV hCryptProv;
+ HCRYPTHASH hHash;
+} SHA256_CTX;
+
+#if !defined(CALG_SHA_256)
+#define CALG_SHA_256 0x0000800c
+#endif
+
+static void SHA256_Init(SHA256_CTX *ctx)
+{
+ if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL,
+ PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) {
+ CryptCreateHash(ctx->hCryptProv, CALG_SHA_256, 0, 0, &ctx->hHash);
+ }
+}
+
+static void SHA256_Update(SHA256_CTX *ctx,
+ const unsigned char *data,
+ unsigned int length)
+{
+ CryptHashData(ctx->hHash, (unsigned char *) data, length, 0);
+}
+
+static void SHA256_Final(unsigned char *digest, SHA256_CTX *ctx)
+{
+ unsigned long length;
+
+ CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
+ if(length == SHA256_DIGEST_LENGTH)
+ CryptGetHashParam(ctx->hHash, HP_HASHVAL, digest, &length, 0);
+
+ if(ctx->hHash)
+ CryptDestroyHash(ctx->hHash);
+
+ if(ctx->hCryptProv)
+ CryptReleaseContext(ctx->hCryptProv, 0);
+}
+
#else
/* When no other crypto library is available we use this code segment */