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