Reprezentation of large numbers in cryptographical application

Hi,
I would like to ask you, how I should work with large numbers. I need to generate number bigger than 2^160 a work with it bit by bit and then hash it. I searched for some information but I’ve found only main data types and data structures. Is there any structure or data type to represent such a large number and work with it?
Thanks

BigInt is probably what you need:

https://docs.julialang.org/en/stable/manual/integers-and-floating-point-numbers/#Arbitrary-Precision-Arithmetic-1

I’m trying to create number 2^160 using:

BigInt(2^160) => result 0

but I’m still limited by size of Int → 2^64 = 0, so I got result 0 for BigInt also. Everything alse works fine, I can sum or multiply number which cross that 2^64 border.

BigInt(2^62) ^ 2 => works
BigInt(2^124) => does not work

Did I miss anything?

The problem with this is, that 2^160 would have to be an Int before it is converted to a BigInt (which obviously does not work). So you can e.g. write big(2)^big(160)

2 Likes

Please note that BigInt is in general not appropriate for production cryptographic implementations because the operations on it are not constant time, so you need to make sure not to expose side timing side channels.

5 Likes

Is it only matter of time why it is not suitable? I’m working on elliptic curve generation according to this article:
1030_Buchmann
Then I’m gonna test a few algorithms to solve ECDLP, so I think that this issue is not connected to my work.

It’s just fine for doing cryptography research, all I wanted to point out is that writing secure implementations of real-world cryptographic protocols is more difficult than getting the math right, and BigInt is not suitable for that purpose.

4 Likes