rsa: Use IOS_HeapRealloc for Mini-GMP

This commit is contained in:
GaryOderNichts 2023-04-01 22:54:44 +02:00
commit 2b69cdd166
3 changed files with 6 additions and 13 deletions

View file

@ -35,6 +35,7 @@ PROVIDE(IOS_ReadOTP = 0x050568fc);
PROVIDE(IOS_HeapAlloc = 0x05056924);
PROVIDE(IOS_HeapAllocAligned = 0x0505692c);
PROVIDE(IOS_HeapFree = 0x05056934);
PROVIDE(IOS_HeapRealloc = 0x05056944);
PROVIDE(IOS_Open = 0x05056984);
PROVIDE(IOS_Close = 0x0505698c);

View file

@ -92,6 +92,7 @@ int IOS_ReadOTP(int index, void* buffer, uint32_t size);
void* IOS_HeapAlloc(uint32_t heap, uint32_t size);
void* IOS_HeapAllocAligned(uint32_t heap, uint32_t size, uint32_t alignment);
void IOS_HeapFree(uint32_t heap, void* ptr);
void* IOS_HeapRealloc(uint32_t heap, void* ptr, uint32_t size);
int IOS_Open(const char* device, int mode);
int IOS_Close(int fd);

View file

@ -46,27 +46,18 @@ static const uint32_t rsa_pubexp = 0x10001;
static void *ios_gmp_alloc(size_t size)
{
return IOS_HeapAlloc(CROSS_PROCESS_HEAP_ID, size);
return IOS_HeapAlloc(LOCAL_PROCESS_HEAP_ID, size);
}
static void *ios_gmp_realloc(void *buf, size_t old_size, size_t new_size)
{
void *newbuf = IOS_HeapAlloc(CROSS_PROCESS_HEAP_ID, new_size);
if (!newbuf)
return NULL;
// Copy the existing buffer into the new buffer.
size_t to_copy = (old_size < new_size ? old_size : new_size);
if (to_copy > 0) {
memcpy(newbuf, buf, to_copy);
}
IOS_HeapFree(CROSS_PROCESS_HEAP_ID, buf);
return newbuf;
((void)old_size);
return IOS_HeapRealloc(LOCAL_PROCESS_HEAP_ID, buf, new_size);
}
static void ios_gmp_free(void *p, size_t unused_size)
{
((void)unused_size);
IOS_HeapFree(CROSS_PROCESS_HEAP_ID, p);
IOS_HeapFree(LOCAL_PROCESS_HEAP_ID, p);
}
/**