<div dir="ltr">Hello,<br><div>I have installed OpenSSL 1.1.1c. I'm trying to make a custom OpenSSL engine for RSA. The following sample code is copied from the engine <b>e_dasync.c. </b></div><div><br></div><div><br></div><div>Following is a sample code for my RSA engine (<b>rsa-engine.c</b>),</div><div>===================================</div><div><b>/* Engine Id and Name */<br>static const char *engine_rsa_id = "rsa-engine-new";<br>static const char *engine_rsa_name = "RSA engine for testing";<br><br>// data encryption function<br>static int eng_rsa_pub_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding) {<br>    printf("RSA Engine is encrypting using public key\n");<br>    return RSA_meth_get_pub_enc(RSA_PKCS1_OpenSSL())<br>        (flen,from,to,rsa,padding);<br>}<br><br>// signature verify<br>static int eng_rsa_pub_dec(int flen, const unsigned char *from,<br>                          unsigned char *to, RSA *rsa, int padding) {<br>    printf("Signature verification\n");<br>    return 0;<br>}<br><br><br>// signature<br>static int eng_rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding){<br>    printf("Signature method:\n");<br>    return 0;<br>}<br><br><br>// data decryption<br>static int eng_rsa_priv_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding){<br>   printf("decryption method:\n");<br>   return 0;        <br>}<br><br><br>static RSA_METHOD *test_rsa_method = NULL;<br><br><br>static int bind_dasync(ENGINE *e){<br>    /* Setup RSA_METHOD */<br>    if ((test_rsa_method = RSA_meth_new("Test RSA Engine", 0)) == NULL<br>        || RSA_meth_set_pub_enc(test_rsa_method, eng_rsa_pub_enc) == 0<br>        || RSA_meth_set_pub_dec(test_rsa_method, eng_rsa_pub_dec) == 0<br>        || RSA_meth_set_priv_enc(test_rsa_method, eng_rsa_priv_enc) == 0<br>        || RSA_meth_set_priv_dec(test_rsa_method, eng_rsa_priv_dec) == 0<br>            ) {<br><br>        return 0;<br>    }<br><br>    /* Ensure the dasync error handling is set up */<br><br>    if (!ENGINE_set_id(e, engine_rsa_id)<br>        || !ENGINE_set_name(e, engine_rsa_name)<br>        || !ENGINE_set_RSA(e, test_rsa_method)<br>            ) {<br>        return 0;<br>    }<br>    return 1;<br>}<br><br>static int bind_helper(ENGINE *e, const char *id){<br>    if (!bind_dasync(e)){<br>        printf("2_Error: Inside Bind helper\n");<br>        return 0;<br>    }<br>    return 1;<br>}<br><br>IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)<br>IMPLEMENT_DYNAMIC_CHECK_FN()</b></div><div>===================================</div><div><br></div><div>My <b>Makefile </b>looks like the following,</div><div>===================================</div><div><b>rsa-engine:<br>        gcc -g -fPIC -c rsa-engine.c<br>  gcc -g -shared -o librsa_engine.so -L./libdune rsa-engine.o -Bdynamic -lcrypto -lpthread<br>      mv librsa_engine.so rsa-engine-new.so<br> sudo cp rsa-engine-new.so /opt/openssl/lib/engines-1.1/<br><br>clean: <br>    rm -f *.o *.d *.so rsa-engine</b></div><div>=================================== </div><div><br></div><div>My code compiles. When I try to do encryption using the following command,</div><div>=========================</div><div><b>openssl rsautl -encrypt -inkey public.pem -pubin -in msg.txt -out msg.enc -engine rsa-engine-new</b><br></div><div>=========================</div><div><br></div><div>I get a segmentation fault,</div><div>================================</div><div><b>engine "rsa-engine-new" set.<br>RSA Engine is encrypting using public key<br>Segmentation fault (core dumped)</b><br></div><div>================================</div><div><br></div><div>Do I need to Compile this sample engine with the OpenSSL in order for it to work? </div><div><br></div><div>Regards,</div><div>Shariful Alam</div><div><br></div><div><br></div></div>