- Help Needed with PowMod for RSA
- 17 Oct 2021 04:23:07 pm Permalink
- Last edited by ACagliano on 17 Oct 2021 08:32:15 pm; edited 2 times in total
For quite some while I have been working with beckadamtheinventor and others on a modular exponentation function that I can use in hashlib for RSA. While I am familiar with the general methods that can be used for a powmod function---l2r or r2l binary, the difficulty is in writing one in assembly that is efficient. I tried in C but ran up against not knowing how to do modulus (or bigint stuff in general, effectively), beck succeeded in the pow section but ran into issues with the modulus and bounding, same as Zeda. To this end, I'm making a topic asking for help from anyone who is good at this type of math... I sure am not... to write the following function in assembly. A C variant that can be converted into asm works too. Thanks in advance.
uint2048_t ^ 65537 % uint2048_t
msg = uint2048_t, variable
exp = constant value 65537
mod = uint2048_t, variable
void vint_powmod(const uint8_t* msg, uint24_t exp, const uint8_t* mod, uint8_t modlen, uint8_t* out);
// exponent can be hardcoded
// out can be omitted if it would be easier to write to *msg
// modlen = length of key (modulus), in bytes
// length of msg will be implied as equal to that.
// the RSA wrapper will reject any msg not equal in length.
// modulus and msg are in size range min = 1024, max = 2048 bits