Skip to content

Commit

Permalink
rsa: Use IOS_HeapRealloc for Mini-GMP
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts committed Apr 1, 2023
1 parent 3622284 commit 2b69cdd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
1 change: 1 addition & 0 deletions ios_mcp/imports.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions ios_mcp/source/imports.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 4 additions & 13 deletions ios_mcp/source/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 2b69cdd

Please sign in to comment.