<div dir="ltr">Mr, Matt,<div>Thanks for the link. It was helpful. However, I'm encountering some weird issues while compiling. </div><div>I have two machines. In one machine The following code is compiling and working file whereas in another machine I'm receiving <b>"warning: implicit declaration of function ‘RSA_meth_new’" </b>during compilation. Both of my machine is running </div><div><ul><li><b>Linux 4.15.0-140-generic,</b></li><li><b>gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609</b></li><li><b>OpenSSL 1.1.1c 28 May 2019</b></li></ul><div><b><br></b></div></div><div>My simple code is below.</div><div><br></div><div>//rsa-engine.c<br></div><div>===================================</div><div>#include <stdio.h><br>#include <string.h><br><br>#include <openssl/engine.h><br>#include <openssl/sha.h><br>#include <openssl/aes.h><br>#include <openssl/rsa.h><br>#include <openssl/evp.h><br>#include <openssl/async.h><br>#include <openssl/bn.h><br>#include <openssl/crypto.h><br>#include <openssl/ssl.h><br>#include <openssl/modes.h><br><br>/* Engine Id and Name */<br>static const char *engine_dasync_id = "dasync";<br>static const char *engine_dasync_name = "Dummy Async engine support";<br><br>static int dasync_pub_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding) {<br> printf("dasync_pub_enc\n");<br> return 0;<br>}<br><br>static int dasync_pub_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding) {<br> printf("dasync_pub_dec\n");<br> return 0;<br>}<br><br>static int dasync_rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding){<br> printf("dasync_rsa_priv_enc\n");<br> return 0;<br>}<br><br>static int dasync_rsa_priv_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding){<br> printf("dasync_rsa_priv_dec\n");<br> return 0;<br>}<br><br></div><div>static RSA_METHOD *dasync_rsa_method = NULL;<br>static int bind_dasync(ENGINE *e){<br> /* Setup RSA_METHOD */<br> if ((dasync_rsa_method = RSA_meth_new("Dummy Async RSA method", 0)) == NULL<br> || RSA_meth_set_pub_enc(dasync_rsa_method, dasync_pub_enc) == 0<br> || RSA_meth_set_pub_dec(dasync_rsa_method, dasync_pub_dec) == 0<br> || RSA_meth_set_priv_enc(dasync_rsa_method, dasync_rsa_priv_enc) == 0<br> || RSA_meth_set_priv_dec(dasync_rsa_method, dasync_rsa_priv_dec) == 0<br> ) {<br> return 0;<br> }<br><br> if (!ENGINE_set_id(e, engine_dasync_id)<br> || !ENGINE_set_name(e, engine_dasync_name)<br> || !ENGINE_set_RSA(e, dasync_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()<br><br><br></div><div>===================================</div><div><br></div><div>In the machine where this engine is working, I use the following command to compile my code,</div><div><ul><li><b>gcc -fPIC -c rsa-engine.c<br></b></li><li><b>gcc -shared -o librsa_engine.so -lcrypto rsa-engine.o</b></li></ul><div>And Following command to load my engine,</div></div><div><ul><li><b>openssl engine -t -c `pwd`/librsa_engine.so</b><br></li></ul><div><br></div></div><div>The same code on the other machine upon running, <b>gcc -fPIC -c rsa-engine.c, </b>I get the following warning,</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>ss@ss:~/Downloads/test_engine$ gcc -fPIC -c rsa-engine.c<br>rsa-engine.c: In function ‘bind_dasync’:<br>rsa-engine.c:64:30: warning: implicit declaration of function ‘RSA_meth_new’ [-Wimplicit-function-declaration]<br> if ((dasync_rsa_method = RSA_meth_new("Dummy Async RSA method", 0)) == NULL<br> ^<br>rsa-engine.c:64:28: warning: assignment makes pointer from integer without a cast [-Wint-conversion]<br> if ((dasync_rsa_method = RSA_meth_new("Dummy Async RSA method", 0)) == NULL<br> ^<br>rsa-engine.c:65:12: warning: implicit declaration of function ‘RSA_meth_set_pub_enc’ [-Wimplicit-function-declaration]<br> || RSA_meth_set_pub_enc(dasync_rsa_method, dasync_pub_enc) == 0<br> ^<br>rsa-engine.c:66:12: warning: implicit declaration of function ‘RSA_meth_set_pub_dec’ [-Wimplicit-function-declaration]<br> || RSA_meth_set_pub_dec(dasync_rsa_method, dasync_pub_dec) == 0<br> ^<br>rsa-engine.c:67:12: warning: implicit declaration of function ‘RSA_meth_set_priv_enc’ [-Wimplicit-function-declaration]<br> || RSA_meth_set_priv_enc(dasync_rsa_method, dasync_rsa_priv_enc) == 0<br> ^<br>rsa-engine.c:68:12: warning: implicit declaration of function ‘RSA_meth_set_priv_dec’ [-Wimplicit-function-declaration]<br> || RSA_meth_set_priv_dec(dasync_rsa_method, dasync_rsa_priv_dec) == 0<br></div></blockquote></div><div><br></div><div><b><br></b></div><div>can you please tell me why the same code is throwing two different results in different machines?</div><div><br></div><div><br></div><div>Regards,</div><div>Shariful Alam </div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 12, 2021 at 10:42 AM Matt Caswell <<a href="mailto:matt@openssl.org">matt@openssl.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">You can look at the dummy async engine which wraps the standard RSA <br>
functions inside an engine (as well as various other crypto primitives). <br>
You can see it here:<br>
<br>
<a href="https://github.com/openssl/openssl/blob/OpenSSL_1_1_1-stable/engines/e_dasync.c" rel="noreferrer" target="_blank">https://github.com/openssl/openssl/blob/OpenSSL_1_1_1-stable/engines/e_dasync.c</a><br>
<br>
Matt<br>
<br>
On 12/04/2021 17:32, Shariful Alam wrote:<br>
> Dr. Pauli,<br>
> Goodmorning. Thank you for replying. I found the documentation a bit <br>
> difficult for me to understand. I was wondering if you can direct me to <br>
> a sample skeleton code for creating a custom RSA engine.<br>
> <br>
> Regards,<br>
> Shariful Alam<br>
> <br>
> On Sun, Apr 11, 2021 at 6:00 PM Dr Paul Dale <<a href="mailto:pauli@openssl.org" target="_blank">pauli@openssl.org</a> <br>
> <mailto:<a href="mailto:pauli@openssl.org" target="_blank">pauli@openssl.org</a>>> wrote:<br>
> <br>
> You shouldn't be accessing the internal of a private structure. That<br>
> structure was made private for a reason and duplicating it in your<br>
> engine will break when we change the structure's contents.<br>
> <br>
> Your engine should be using the EVP_PKEY_meth_set_* function to do<br>
> what you want (for 1.1.1). For 3.0, you should be writing a<br>
> provider instead.<br>
> <br>
> <br>
> Pauli<br>
> <br>
> On 12/4/21 5:04 am, Shariful Alam wrote:<br>
>> Hello,<br>
>> Hope you guys are doing well. I'm trying to develop an RSA engine.<br>
>> My engine was somewhat working until I try to integrate my engine<br>
>> with an apache httpd server. After installing the httpd from the<br>
>> source code, it turns out that, I can't compile my engine anymore.<br>
>> I get the following error while I try to compile (it was compiling<br>
>> before and I did not make any changes to my engine code).<br>
>><br>
>> ==============================<br>
>><br>
>> *$gcc -fPIC -c r_engine.c*<br>
>> *r_engine.c:29:8: error: redefinition of ‘struct rsa_meth_st’<br>
>> struct rsa_meth_st {<br>
>> ^<br>
>> In file included from /usr/include/openssl/crypto.h:131:0,<br>
>> from r_engine.c:7:<br>
>> /usr/include/openssl/ossl_typ.h:147:16: note: originally defined here<br>
>> typedef struct rsa_meth_st RSA_METHOD;*<br>
>><br>
>> =============================<br>
>><br>
>> and my *struct rsa_meth_st *looks like the following,<br>
>><br>
>> ================================================================================<br>
>><br>
>> *struct rsa_meth_st {<br>
>><br>
>> const char *name;<br>
>> int (*rsa_pub_enc) (int flen, const unsigned char *from,<br>
>> unsigned char *to, RSA *rsa, int padding);<br>
>> int (*rsa_pub_dec) (int flen, const unsigned char *from,<br>
>> unsigned char *to, RSA *rsa, int padding);<br>
>> int (*rsa_priv_enc) (int flen, const unsigned char *from,<br>
>> unsigned char *to, RSA *rsa, int padding);<br>
>> int (*rsa_priv_dec) (int flen, const unsigned char *from,<br>
>> unsigned char *to, RSA *rsa, int padding);<br>
>><br>
>> int (*rsa_mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa,<br>
>> BN_CTX *ctx);<br>
>><br>
>> int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM<br>
>> *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);<br>
>><br>
>> int (*init) (RSA *rsa);<br>
>><br>
>> int (*finish) (RSA *rsa);<br>
>><br>
>> int flags;<br>
>><br>
>> char *app_data;<br>
>><br>
>> int (*rsa_sign) (int type, const unsigned char *m, unsigned<br>
>> int m_length, unsigned char *sigret, unsigned int *siglen, const<br>
>> RSA *rsa);<br>
>><br>
>> int (*rsa_verify) (int dtype, const unsigned char *m, unsigned<br>
>> int m_length, const unsigned char *sigbuf, unsigned int siglen,<br>
>> const RSA *rsa);<br>
>><br>
>> int (*rsa_keygen) (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);<br>
>><br>
>> };<br>
>> *<br>
>><br>
>> =================================================================================<br>
>><br>
>> My sample skeleton code is here <a href="https://pastebin.com/uNXYknEA" rel="noreferrer" target="_blank">https://pastebin.com/uNXYknEA</a><br>
>> <<a href="https://pastebin.com/uNXYknEA" rel="noreferrer" target="_blank">https://pastebin.com/uNXYknEA</a>><br>
>><br>
>> Can anyone please tell me what I'm I doing wrong?<br>
>><br>
>> Regards,<br>
>> Shariful Alam<br>
> <br>
</blockquote></div>