A deterministic implementation of some of the OpenSSL functionalities
C Makefile Python C++
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.


Build Code Coverage


The dOpenSSL library extends the OpenSSL Project cryptographic library so as to provide deterministic random generation functionalities. Basically, dOpenSSL guarantees that should a big number or a cryptographic key be generated, given a PRNG's state, the result would be always the same.

The OpenSSL random generator introduces entropy in many places, making it unusable in a deterministic way. Thus, some functions have been cloned and adapted in order to guarantee determinism.

This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/)


Retrieve the dOpenSSL sources on Github as follows

$> git clone git://github.com/infinit/dopenssl.git


First of all, go to the directory containing the dOpenSSL's sources:

$> cd dopenssl/

Here you will find all the sources, tests and samples related to dOpenSSL. Then, go to the build directory related to your machine's operating system and architecture. All the build directories are located in _build/.

For the purpose of this tutorial, we will assume your machine runs a Linux 64-bit operating system.

$> cd _build/linux64/

There are two ways for building dOpenSSL. The first relies on the Drake build system (which must be installed on your system) with which dOpenSSL has been developed. The other way consists in invoking a simple Makefile (generated by Drake).


Assuming Drake has been installed on your system and is referenced in the PYTHONPATH environment variable, simply invoke the //build rule so as to compile and generate the dOpenSSL library.

$> ./drake //build
Compile sources/dopenssl/rand.o
Compile sources/dopenssl/bn.o
Compile sources/dopenssl/rsa.o
Link lib/libdopenssl.a
Link lib/libdopenssl.so

Alternatively, one may want to invoke the drake script with a specific python binary, so as to use the latest python version for instance:

$> python3.2 ./drake //build

At this point, the dOpenSSL library has been built successfully.


Simply invoke the Makefile's build rule as follows:

$> make build


Making sure the dOpenSSL library has been properly built and behaves as expected on your system is important.

Note that the following assumes your are still in the _build/linux64/ directory.


Just invoke the //check rule which will both compile the tests and run them.

$> ./drake //check
Compile tests/dopenssl/rsa.o
Compile tests/dopenssl/rand.o
Compile tests/dopenssl/bn.o
Link tests/dopenssl/rsa
Link tests/dopenssl/rand
Link tests/dopenssl/bn
Run tests/dopenssl/rsa
Run tests/dopenssl/rand
Run tests/dopenssl/bn


Likewise, invoke the check rule so as to run the tests.

$> make check


Installing dOpenSSL on your system is as simple as the previous steps.


Invoke the //install rule so as to copy the library files on your system. Note that the --prefix option can be passed so as to specify the destination directory.

The example below install the dOpenSSL library in $HOME/local/ with the header files in $HOME/local/include/ and the library files in $HOME/local/lib/.

$> ./drake //install --prefix=$HOME/local/


Once again, nothing could be simpler, the install rule make it extremely easy to install the library files:

$> make install

Note that you may need to be root in order to install the dOpenSSL library in one of your system's directories.


The following source code can be copied and pasted in a test file, say test.c. This sample shows how dOpenSSL can be used to generate cryptographic keys --- in this case 2048-bit RSA keys --- in a deterministic way i.e based on a given passphrase. The program therefore assures that, given the same passphrase, the exact same RSA key will be generated.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <dopenssl/rsa.h>
#include <dopenssl/rand.h>

int main(int argc, char **argv)
  if (argc != 2)
    printf("usage: %s [passphrase]\n", argv[0]);

  unsigned int const bits = 2048;

  char const* passphrase = argv[1];
  unsigned int const length = strlen(passphrase);
  unsigned int const size = bits / 8;
  unsigned int const occurences = size / length + 1;

  unsigned char* seed = malloc(occurences * length + 1);
  memset(seed, 0x0, occurences * length + 1);

  /* Concatenate the passphrase so as to create a 256-byte buffer */
  unsigned int i;
  for (i = 0; i < occurences; i++)
    strncpy(seed + (i * length), passphrase, length);

  /* Initialize the deterministic random generator */
  if (dRAND_init() != 1)
    printf("[error] unable to initialize the random generator\n");
    return (1);

  /* Generate the RSA key */
  RSA* rsa = NULL;

  if ((rsa = dRSA_deduce_privatekey(bits, seed, size)) == NULL)
    printf("[error] unable to generate the RSA key pair\n");
    return (1);

  /* Display the RSA components */
  RSA_print_fp(stdout, rsa, 0);

  /* Clean the resources */
  if (dRAND_clean() != 1)
    printf("[error] unable to clean the random generator\n");
    return (1);

  return (0);

Assuming the dOpenSSL library has been installed in $HOME/local/, the sample program can be compiled as follows:

$> gcc -I $HOME/local/include -L $HOME/local/lib -ldopenssl -lcrypto test.c -o test

Note that you may need to add the library directory where OpenSSL has been installed e.g /usr/lib/, /opt/local/lib/ etc.

$> gcc -I $HOME/local/include -L $HOME/local/lib -L /opt/local/lib -ldopenssl -lcrypto test.c -o test

Then, in order to launch the program, you may need to specify your system where to look for libraries, again assuming dOpenSSL has been installed in $HOME/local/:

$> export LD_LIBRARY_PATH=$HOME/local/lib:${LD_LIBRARY_PATH}

Finally, just launch the sample program by providing a passphrase:

$> ./test "chiche donne nous tout"
Private-Key: (2048 bit)

Note that you should get exactly the same output since dOpenSSL guarantees the result is deterministic.


The library relies upon the following libraries:

  • OpenSSL which provides the fundamental cryptographic operations.


The library is composed of a three components, all required for ensuring the determinism of the cryptography key generation mechanism.

First, a deterministic random implementation is provided, referred to as dRAND.

Although this implementation is deterministic, determinism must also be assured at the BIGNUM level because some of the functions introduce entroy, the ones related to BN_generate_prime_ex() for instance.

Finally a set of functions for deducing a private/public key from a PRNG state in a deterministic way is provided for every asymmetric cryptosystem, such as RSA.

In other words, some of the OpenSSL library's functions have been slightly modified so as to remove the operations destined at adding entropy, especially the ones based on uninitialized variables.

The reader interested in looking at these slight modifications can look around for "PATCHED".