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:
- Using an array of char (like strings, that would be good for encryption/decryption keys)
- 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?
If you are interested in Cryptography, then everything has to be correct. Either you spend many months writing and testing and testing and testing… your own big number arithmetic functions, or you use an existing library.
It is difficult enough getting crypto to work correctly when you know that the methods you are using are correct. It is almost impossible if the methods you are using have subtle errors.
For crypto use GMP, and concentrate on the crypto.
If you want to write your own large number arithmetic package, then by all means do so. I have done the same myself and it is an interesting and useful experience. But don’t use your own work for anything critical.