-1
$\begingroup$

I want to implement RSA algorithm using C language. I have read the size of primes in RSA like p and q are 2048 bits long. How to declare such 2048 bit values in C. As i know that the data types like int , long ,long long int even are less than 64 bits. Please suggest.

$\endgroup$
  • 1
    $\begingroup$ You could use a bignum library (or just use an array of unsigned char's/int's/whatever, and implement the multiprecision math yourself, however that's rarely worth the effort). $\endgroup$ – poncho Jul 9 at 1:44
1
$\begingroup$

1. This is what you asked:

How to declare such 2048 bit values in C. As i know that the data types like int , long ,long long int even are less than 64 bits. Please suggest.

2. You can use the The GNU MP Bignum Library.

This is the manual.

3 This is how to declare such 2048 bit values in C using The GNU MP Bignum Library .

// this is the big number p  
mpz_t p;       

// initialize  the big number p
mpz_inits (p, NULL);

// declaration or assignment of p 
mpz_set_str (p, "0x00ed6aead4012490897cc99074d534488d8cd85ecd0839fb6b1e12bd7a6a7849431a5aef1938e97b3cdeedfbd1166fa044c2785a1838bf1e71d88ff3009d1aac5f74756d1b3742e2931249e42b60f993d934df85d5bbd64e2dcb726e80a692b628f544549a15a4c85655c27a26ca144db403a27137fde1a9cdb8f46e8f677d1ecd", 0);
    
| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ This is an example of use of GMP from C. It's a pragmatic solution to "I want to implement RSA algorithm using C language" using other people's code. In my view, it does not answer the question "How to declare 2048 bit key in RSA" in the C language. OTOH, if that question has to be asked, there is a lot of work ahead, and most of that work is off-topic. $\endgroup$ – fgrieu Jul 9 at 5:07
  • 2
    $\begingroup$ I modify it. I think the question is that How to declare 2048 bit key in RSA" in the C language., I give a method in C. Please check it 。 $\endgroup$ – 孙海城 Jul 9 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.