0

I'm using the following program to generate an RSA key of 4 bytes length (unsigned long). So my question is how can i modify my program to work with big integers ?

void keygen(unsigned long int e, unsigned long int p, unsigned long int q)
{
    unsigned long int phi,d,n,s;

    n = p*q;
    phi=(p-1)*(q-1);

    d = phi / e ;

    do
    {
        d++;
    }
    while( ((d*e) % phi) != 1 );

    printf("\n public key: { e=%u n=%u }",e,n);
    printf("\n private key: { d=%u n=%u }",d,n);
    printf("\n verify modulo = %d\n",((d*e) % phi)); /* this need to be 1 */
}

void main()
{
    keygen(3, 17, 19);
    system("pause");
}
Radu
  • 73
  • 1
  • 3
  • 10
  • What do you mean by "how can I modify the algorithm"? Do you mean how do you perform the mathematical operations? – mnistic Jun 27 '18 at 10:46
  • 1
    What do you mean by "a RSA key length is 128 bytes?". Do you mean that for RSA2048? Because RSA1024 has a key length of 64bytes – Stoogy Jun 27 '18 at 13:36
  • 1
    The security of such algorithm requires to manipulate integers which are way longer than the ones you can find in regular programming languages. You need to use specific module to manipulate arbitrary long integers... except if it is just a school exercise. – perror Jun 27 '18 at 14:14
  • mnistic yes, how can i perfome the mathematical operations when e, p and q are vectors ? – Radu Jun 28 '18 at 09:58

0 Answers0