I'm trying to debug my own implementation of the ECDSA signature. To compare the intermediate results I would like to force the OpenSSL, Crypto++ or whatever else package to use a known "random" number instead of generating it each time the signature is created. Is there a way to do so?
Since I'm working with the brainpool curves I can't use the microsoft crypto API. This doesn't support the brainpool curves in the Crypto API until Windows 10.
Another way could to be retrieve the random used after the ECDSA signature creation from one of the popular packages.
I appreciate any help
Yes, this is possible with OpenSSL. OpenSSL provides the ability to override the default source of random numbers. To do this use the RAND_set_rand_method()
function documented here:
https://www.openssl.org/docs/man1.1.0/crypto/RAND_set_rand_method.html
This function takes as an argument a RAND_METHOD
structure which contains function pointers to the implementations of the OpenSSL random capabilities. Replace the bytes
element with your own implementation.
For example
RAND_METHOD myrand, *oldrand;
oldrand = RAND_get_rand_method();
myrand = *oldrand;
myrand.bytes = mybytes;
RAND_set_rand_method(myrand);
Where mybytes
is defined like this:
static int mybytes(unsigned char *buf, int num)
{
/* Replace with however you want the random function to work */
memset(buf, 0, num);
return 1;
}
OpenSSL's own ecdsatest code does exactly this. For example see:
https://github.com/openssl/openssl/blob/OpenSSL_1_1_0-stable/test/ecdsatest.c#L65