Commit cec97050 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

rsaenh: Use CRT memory allocators.

parent d72942e9
......@@ -23,6 +23,7 @@
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "windef.h"
#include "winbase.h"
......@@ -70,7 +71,7 @@ void destroy_handle_table(struct handle_table *lpTable)
{
TRACE("(lpTable=%p)\n", lpTable);
HeapFree(GetProcessHeap(), 0, lpTable->paEntries);
free(lpTable->paEntries);
lpTable->mutex.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&lpTable->mutex);
}
......@@ -139,14 +140,14 @@ static BOOL grow_handle_table(struct handle_table *lpTable)
newIEntries = lpTable->iEntries + TABLE_SIZE_INCREMENT;
newEntries = HeapAlloc(GetProcessHeap(), 0, sizeof(struct handle_table_entry)*newIEntries);
newEntries = malloc(sizeof(struct handle_table_entry)*newIEntries);
if (!newEntries)
return FALSE;
if (lpTable->paEntries)
{
memcpy(newEntries, lpTable->paEntries, sizeof(struct handle_table_entry)*lpTable->iEntries);
HeapFree(GetProcessHeap(), 0, lpTable->paEntries);
free(lpTable->paEntries);
}
for (i=lpTable->iEntries; i<newIEntries; i++)
......@@ -356,7 +357,7 @@ HCRYPTKEY new_object(struct handle_table *lpTable, size_t cbSize, DWORD dwType,
if (ppObject)
*ppObject = NULL;
pObject = HeapAlloc(GetProcessHeap(), 0, cbSize);
pObject = malloc(cbSize);
if (!pObject)
return (HCRYPTKEY)INVALID_HANDLE_VALUE;
......@@ -365,7 +366,7 @@ HCRYPTKEY new_object(struct handle_table *lpTable, size_t cbSize, DWORD dwType,
pObject->destructor = destructor;
if (!alloc_handle(lpTable, pObject, &hObject))
HeapFree(GetProcessHeap(), 0, pObject);
free(pObject);
else
if (ppObject)
*ppObject = pObject;
......
......@@ -23,6 +23,7 @@
*/
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
......@@ -273,7 +274,7 @@ BOOL encrypt_block_impl(ALG_ID aiAlgid, DWORD dwKeySpec, KEY_CONTEXT *pKeyContex
}
reverse_bytes(out, outlen);
} else {
in_reversed = HeapAlloc(GetProcessHeap(), 0, inlen);
in_reversed = malloc(inlen);
if (!in_reversed) {
SetLastError(NTE_NO_MEMORY);
return FALSE;
......@@ -281,11 +282,11 @@ BOOL encrypt_block_impl(ALG_ID aiAlgid, DWORD dwKeySpec, KEY_CONTEXT *pKeyContex
memcpy(in_reversed, in, inlen);
reverse_bytes(in_reversed, inlen);
if (rsa_exptmod(in_reversed, inlen, out, &outlen, dwKeySpec, &pKeyContext->rsa) != CRYPT_OK) {
HeapFree(GetProcessHeap(), 0, in_reversed);
free(in_reversed);
SetLastError(NTE_FAIL);
return FALSE;
}
HeapFree(GetProcessHeap(), 0, in_reversed);
free(in_reversed);
}
break;
......@@ -341,14 +342,14 @@ BOOL import_public_key_impl(const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD d
return FALSE;
}
pbTemp = HeapAlloc(GetProcessHeap(), 0, dwKeyLen);
pbTemp = malloc(dwKeyLen);
if (!pbTemp) return FALSE;
memcpy(pbTemp, pbSrc, dwKeyLen);
pKeyContext->rsa.type = PK_PUBLIC;
reverse_bytes(pbTemp, dwKeyLen);
mp_read_unsigned_bin(&pKeyContext->rsa.N, pbTemp, dwKeyLen);
HeapFree(GetProcessHeap(), 0, pbTemp);
free(pbTemp);
mp_set_int(&pKeyContext->rsa.e, dwPubExp);
return TRUE;
......@@ -416,7 +417,7 @@ BOOL import_private_key_impl(const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD
return FALSE;
}
pbTemp = HeapAlloc(GetProcessHeap(), 0, 2*dwKeyLen+5*((dwKeyLen+1)>>1));
pbTemp = malloc(2*dwKeyLen+5*((dwKeyLen+1)>>1));
if (!pbTemp) return FALSE;
memcpy(pbTemp, pbSrc, min(dwDataLen, 2*dwKeyLen+5*((dwKeyLen+1)>>1)));
pbBigNum = pbTemp;
......@@ -448,6 +449,6 @@ BOOL import_private_key_impl(const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD
mp_read_unsigned_bin(&pKeyContext->rsa.d, pbBigNum, dwKeyLen);
mp_set_int(&pKeyContext->rsa.e, dwPubExp);
HeapFree(GetProcessHeap(), 0, pbTemp);
free(pbTemp);
return TRUE;
}
......@@ -29,6 +29,7 @@
*/
#include <stdarg.h>
#include <stdlib.h>
#include "windef.h"
#include "winbase.h"
......@@ -119,7 +120,7 @@ static int mp_grow (mp_int * a, int size)
* in case the operation failed we don't want
* to overwrite the dp member of a.
*/
tmp = HeapReAlloc(GetProcessHeap(), 0, a->dp, sizeof (mp_digit) * size);
tmp = realloc(a->dp, sizeof (mp_digit) * size);
if (tmp == NULL) {
/* reallocation failed but "a" is still valid [can be freed] */
return MP_MEM;
......@@ -204,7 +205,7 @@ static int mp_init (mp_int * a)
int i;
/* allocate memory required and clear it */
a->dp = HeapAlloc(GetProcessHeap(), 0, sizeof (mp_digit) * MP_PREC);
a->dp = malloc(sizeof (mp_digit) * MP_PREC);
if (a->dp == NULL) {
return MP_MEM;
}
......@@ -232,7 +233,7 @@ static int mp_init_size (mp_int * a, int size)
size += (MP_PREC * 2) - (size % MP_PREC);
/* alloc mem */
a->dp = HeapAlloc(GetProcessHeap(), 0, sizeof (mp_digit) * size);
a->dp = malloc(sizeof (mp_digit) * size);
if (a->dp == NULL) {
return MP_MEM;
}
......@@ -264,7 +265,7 @@ mp_clear (mp_int * a)
}
/* free ram */
HeapFree(GetProcessHeap(), 0, a->dp);
free(a->dp);
/* reset members to make debugging easier */
a->dp = NULL;
......@@ -3425,7 +3426,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
bsize = (size>>3)+((size&7)?1:0);
/* we need a buffer of bsize bytes */
tmp = HeapAlloc(GetProcessHeap(), 0, bsize);
tmp = malloc(bsize);
if (tmp == NULL) {
return MP_MEM;
}
......@@ -3490,7 +3491,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
err = MP_OKAY;
error:
HeapFree(GetProcessHeap(), 0, tmp);
free(tmp);
return err;
}
......@@ -3712,7 +3713,7 @@ int mp_shrink (mp_int * a)
{
mp_digit *tmp;
if (a->alloc != a->used && a->used > 0) {
if ((tmp = HeapReAlloc(GetProcessHeap(), 0, a->dp, sizeof (mp_digit) * a->used)) == NULL) {
if ((tmp = realloc(a->dp, sizeof (mp_digit) * a->used)) == NULL) {
return MP_MEM;
}
a->dp = tmp;
......
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