Topic: Manually populate the RsaKey structure for a private key?
Is there a way to manually populate the parameters of an RSA private key? I had come up with this, but get linker errors of "undefined reference to mp_init and mp_read_unsigned_bin"
int parseMPIntFromBuffer(mp_int* mpi, const uint8_t *pIn, int length)
{
if (mp_init(mpi) != MP_OKAY)
{
printf("Error initializing MP integer\n");
return -1;
}
if (mp_read_unsigned_bin(mpi, pIn, length) < 0)
{
printf("Error reading bignum\n");
return -1;
}
return 0;
}
...
// Parse the key values
if (
(parseMPIntFromBuffer(&(pKey->p), &(pIn[0 * 64]), 64) != 0)
|| (parseMPIntFromBuffer(&(pKey->q), &(pIn[1 * 64]), 64) != 0)
|| (parseMPIntFromBuffer(&(pKey->dP), &(pIn[2 * 64]), 64) != 0)
|| (parseMPIntFromBuffer(&(pKey->dQ), &(pIn[3 * 64]), 64) != 0)
|| (parseMPIntFromBuffer(&(pKey->u), &(pIn[4 * 64]), 64) != 0)
)
{
printf("Error parsing the private key\n");
return -1;
}
If there isn't a way to expose those functions to the linker, is it guaranteed across architectures that the buffer will be entirely little-endian? If so, I should be able to populate the "used, alloc, sign" elements of mp_int and simply reverse the buffers to get the private key - though that seems like it would be reinventing the wheel.
Thanks in advance.