Hello,
I have the following simple RSA engine code from e_dasync.c. Following code compiles and works. Until now, I was under the impression that if I do not supply an alternative method in function bind_dasync(), the engine will use the default method. However, it doesn't seem to be the case. If I comment out line 37 and try to perform an encryption operation with the following command,
"openssl rsautl -encrypt -inkey public.pem -pubin -in msg.txt -out msg.enc -engine rsa-engine-new"
I get segmentation errors.
Can anyone please tell me why this is happening?
==============================================================================
- /* Engine Id and Name */
- static const char *engine_rsa_id = "rsa-engine-new";
- static const char *engine_rsa_name = "RSA engine for testing";
- // data encryption function
- static int eng_rsa_pub_enc(int flen, const unsigned char *from,
- unsigned char *to, RSA *rsa, int padding) {
- printf("Encryption\n");
- return 0;
- }
- // signature verify
- static int eng_rsa_pub_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding){
- printf("Signature verify:\n");
- return 0;
- }
- // signature
- static int eng_rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding){
- printf("Signature:\n");
- return 0;
- }
- // data decryption
- static int eng_rsa_priv_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding){
- printf("Decryption\n");
- return 0;
- }
- static RSA_METHOD *test_rsa_method = NULL;
- static int bind_dasync(ENGINE *e){
- /* Setup RSA_METHOD */
- if ((test_rsa_method = RSA_meth_new("Test RSA method", 0)) == NULL
- // || RSA_meth_set_pub_enc(test_rsa_method, eng_rsa_pub_enc) == 0
- || RSA_meth_set_pub_dec(test_rsa_method, eng_rsa_pub_dec) == 0
- || RSA_meth_set_priv_enc(test_rsa_method, eng_rsa_priv_enc) == 0
- || RSA_meth_set_priv_dec(test_rsa_method, eng_rsa_priv_dec) == 0
- ) {
- return 0;
- }
- /* Ensure the dasync error handling is set up */
- if (!ENGINE_set_id(e, engine_rsa_id)
- || !ENGINE_set_name(e, engine_rsa_name)
- || !ENGINE_set_RSA(e, test_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()
==============================================================================
Regards,
Shariful Alam