Commit 3e855644 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

rsaenh: Use bcrypt for MD5 hashes.

parent 2b7fcef8
......@@ -33,10 +33,6 @@
#include <stdio.h>
/* Function prototypes copied from dlls/advapi32/crypt_md5.c */
VOID WINAPI MD5Init( MD5_CTX *ctx );
VOID WINAPI MD5Update( MD5_CTX *ctx, const unsigned char *buf, unsigned int len );
VOID WINAPI MD5Final( MD5_CTX *ctx );
/* Function prototype copied from dlls/advapi32/crypt.c */
BOOL WINAPI SystemFunction036(PVOID pbBuffer, ULONG dwLen);
......@@ -56,8 +52,8 @@ BOOL init_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext)
break;
case CALG_MD5:
MD5Init(&pHashContext->md5);
return TRUE;
status = BCryptOpenAlgorithmProvider(&provider, BCRYPT_MD5_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
break;
case CALG_SHA:
status = BCryptOpenAlgorithmProvider(&provider, BCRYPT_SHA1_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
......@@ -89,48 +85,21 @@ BOOL init_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext)
BOOL update_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, const BYTE *pbData,
DWORD dwDataLen)
{
switch (aiAlgid)
{
case CALG_MD5:
MD5Update(&pHashContext->md5, pbData, dwDataLen);
break;
default:
BCryptHashData(pHashContext->bcrypt_hash, (UCHAR*)pbData, dwDataLen, 0);
}
BCryptHashData(pHashContext->bcrypt_hash, (UCHAR*)pbData, dwDataLen, 0);
return TRUE;
}
BOOL finalize_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, BYTE *pbHashValue)
{
switch (aiAlgid)
{
case CALG_MD5:
MD5Final(&pHashContext->md5);
memcpy(pbHashValue, pHashContext->md5.digest, 16);
break;
default:
BCryptFinishHash(pHashContext->bcrypt_hash, pbHashValue, RSAENH_MAX_HASH_SIZE, 0);
BCryptDestroyHash(pHashContext->bcrypt_hash);
break;
}
BCryptFinishHash(pHashContext->bcrypt_hash, pbHashValue, RSAENH_MAX_HASH_SIZE, 0);
BCryptDestroyHash(pHashContext->bcrypt_hash);
return TRUE;
}
BOOL duplicate_hash_impl(ALG_ID aiAlgid, const HASH_CONTEXT *pSrcHashContext,
HASH_CONTEXT *pDestHashContext)
{
switch (aiAlgid)
{
case CALG_MD5:
*pDestHashContext = *pSrcHashContext;
return TRUE;
default:
return !BCryptDuplicateHash(pSrcHashContext->bcrypt_hash, &pDestHashContext->bcrypt_hash, NULL, 0, 0);
}
return !BCryptDuplicateHash(pSrcHashContext->bcrypt_hash, &pDestHashContext->bcrypt_hash, NULL, 0, 0);
}
BOOL new_key_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen)
......
......@@ -29,17 +29,7 @@
#define RSAENH_MAX_HASH_SIZE 104
/* Next typedef copied from dlls/advapi32/crypt_md5.c */
typedef struct tagMD5_CTX
{
unsigned int i[2];
unsigned int buf[4];
unsigned char in[64];
unsigned char digest[16];
} MD5_CTX;
typedef union tagHASH_CONTEXT {
MD5_CTX md5;
BCRYPT_HASH_HANDLE bcrypt_hash;
} HASH_CONTEXT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment