4
votes

I was getting bored so I started looking a little into Cryptography. I got interested in this Fair-Coin Flipping protocol. This protocol works with public key cryptography but requires that the algorithm commute (something like RSA I guess). I thought it would be fun to write this in either C or C++ and was wondering how people generally do this public key cryptography in C or C++. For instance, the first few steps of the protocol are:

  1. Alice and Bob both generate a public/private key pair (which is the commutative secret)
  2. Alice generates two messages, one indicating heads and the other indicating tails and encrypts both of them using her key and sends them to Bob.
  3. ...
  4. ...

Now, for the message, I will use perhaps a string but are there any good libraries for generating the public/private keys and encrypting a given string etc.?

2
Please decide whether you're using C, or using C++. The range of available libraries may be quite different. - Greg Hewgill
@Greg Hewgill: I'll pick C then. I'll look over the other responses and get back. - Legend

2 Answers

4
votes

Look at something like crypto++, rather than doing the cryptography yourself. There are other commercial libraries as well, but that should give you a good start.

1
votes

I wrote a cryptography library as part of a university assignment on combinatorics. I used the GMP (GNUs Multiple Precision) library to generate random huge numbers (any number of bits that your computer can handle. So 4096 bit numbers are easy!)