2

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?

samoz
  • 56,849
  • 55
  • 141
  • 195

4 Answers4

4

Check out the GNU Multiple Precision Arithmetic Library.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
1

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

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
  • 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 Apr 09 '10 at 14:52
  • 2
    @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 Apr 09 '10 at 15:21
  • This answer is prove why you get upvote if you only have already some reputation even if answer is totally missed with point. – unalignedmemoryaccess Jul 04 '17 at 11:57
  • @tilz0R: Except back when I answered this in 2010 I didn't already have some reputation :) – Billy ONeal Jul 06 '17 at 02:31
1

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
  • 516
  • 2
  • 3
  • Quite a few protocols require 128 bit modular exponentiation. – samoz Apr 10 '10 at 17:25
  • @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 Apr 12 '10 at 11:18
0

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.

mrks
  • 1,421
  • 2
  • 12
  • 20