I want to write an openssl dynamic engine, but I can't find any document for that.
My algorithm that I want to write, is a chipper algorithm(like rsa) and a hash algorithm (like md5).
Is any simple engine source code that I can change that and use from that?
Is any simple engine source code that I can change that and use from that?
The Intel RDRAND
engine is pretty easy to understand. You can find its sources with:
openssl-1.0.1f$ grep -R -i ENGINE_rdrand *
crypto/engine/eng_rdrand.c:static ENGINE *ENGINE_rdrand(void)
crypto/engine/eng_rdrand.c: ENGINE *toadd = ENGINE_rdrand();
Here's how you can load and set it as the default random number generator engine (from Random Numbers|Hardware):
unsigned long err = 0;
int rc = 0;
OPENSSL_cpuid_setup();
ENGINE_load_rdrand();
ENGINE* eng = ENGINE_by_id("rdrand");
err = ERR_get_error();
if(NULL == eng) {
fprintf(stderr, "ENGINE_load_rdrand failed, err = 0x%lx\n", err);
abort(); /* failed */
}
rc = ENGINE_init(eng);
err = ERR_get_error();
if(0 == rc) {
fprintf(stderr, "ENGINE_init failed, err = 0x%lx\n", err);
abort(); /* failed */
}
rc = ENGINE_set_default(eng, ENGINE_METHOD_RAND);
err = ERR_get_error();
if(0 == rc) {
fprintf(stderr, "ENGINE_set_default failed, err = 0x%lx\n", err);
abort(); /* failed */
}
/* OK to proceed */
...
ENGINE_finish(eng);
ENGINE_free(eng);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With