views:

139

answers:

4

I am writing a cryptography application and need to work with 128 bit integers.

In addition to standard add, subtract, multiply, divide, and comparisons, I also need a power and modulo function as well.

Does anyone know of a library or other implementation that can do this? If not 128-bit, is there a 64-bit option available?

+3  A: 

Check out the GNU Multiple Precision Arithmetic Library.

Bill the Lizard
+1  A: 

Most any modern compiler is going to provide at least 64 bit through the use of the long long type.

Billy ONeal
Which isn't really good enough. A cryptosystem with a 64-bit key is vulnerable to a brute-force attack (although it isn't trivial). A cryptosystem with a 128-bit key is invulnerable to a brute-force attack, unless the laws of physics change or there's a new model of computation (I've seen claims that quantum computing could reduce a 128-bit key decrypt to two 64-bit key decrypts; I don't know how accurate those are.)
David Thornley
@David Thornley: 1. I agree. 2. The OP asked if there was a 64 bit type available, so I answered it. I said nothing about how suitable that would be for crypto. 3. My assumption was that it'd be easier to implement 128 bit operations if 64 bit integers are available on your platform.
Billy ONeal
A: 

Look for the Montgomery algorithms for multiplication and powers in a finite field. I don't know any library but I am quiet sure there are.

markus
A: 

gcc supports uint128_t, which is a 128-bit integer, though this isn't very portable.

Since I don't know any main stream cryptosystems that use 128-bit modular arithmetic, I'm wondering what scheme you are implementing.

abc
Quite a few protocols require 128 bit modular exponentiation.
samoz
@samoz: 128-bit arithmetic is far to small for public key crypto. But otherwise I don't know any cryptosystem that uses modular exponentiation. So I'm still wondering what you are trying to implement. I.e., it might well be possible that you could use special purpose modular reduction or some other tricks to improve you implementation.
abc