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