The libgcrypt rsa code is mostly visible at https://dev.gnupg.org/source/libgcrypt/browse/master/cipher/rsa.c . (I had to work around some network issues reaching git.gnupg.org, and found dev.gnupg.org which works for me.)
The basic operations of use are public() and secret(). They basically just call out to mpi_powm, which is a wrapper for gcry_mpi_powm(). There's a #define in gcrypt.h, which is a different file generated from
gcrypt.h.in .
Before moving off rsa.c, it's notable that:
- public() basically just wraps mpi_powm, using the same structures
- secret() has an additional step to remove leading zeros
- secret() has a special form that might be used when p and q are known called secret_core_crt()
- there's something else called secret_blinded() that is likely documented in a header file or elsewhere
Basically, everything of interest is likely in mpi_powm.
I'm taking it slower now, because complexity will increase as we get deeper. mpi_powm could look frighteningly new.