Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle big integers in C

Tags:

c

cryptography

I want to implement cryptography algorithms. So I need a suitable data type to handle integers with a lot of digits.

Many recent languages, such as Java, Python and Ruby provide native ways to do this. However, I'm programming in C, and I was wondering what is the best way and easiest way to implement elementary operations there.

I would like to write it without any external library. I thought about two options:

  1. Using an array of char (like strings, that would be good for encryption/decryption keys)
  2. Using an array of bits (I don't know how to do it, but I think this would be compiler-dependant)

What would you do?

like image 705
kwadr4tic Avatar asked Dec 05 '22 18:12

kwadr4tic


1 Answers

The (to me) obvious choice would be GMP whose main developer, Torbjörn Granlund, was a member of the Swedish five man team that won the Simon Singh "Cipher Challenge" in 2000.

According to the website the code can be used to calculate 1000000000 digits of pi in 1957 seconds on an AMD Phenom II @ 3.2 GHz.

The code has been developed since 1991.

like image 82
Olof Forshell Avatar answered Dec 08 '22 00:12

Olof Forshell