Re: [openssl-users] RSA engine is not using the functions mentioned in struct

2017-02-13 Thread khurram ashraf
Respected Mr. Levitte,

I have created the symlink to 
/usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines/librsa_engine.so. During 
encryption and decryption it mentions that "engine "rsa-engine 1" set", but it 
doesnot use the function in the struct and also doesnot output the printf. 
Furthermore, I also tried the method you recomended but still no result.


Best Regards.

Khurram



From: openssl-users  on behalf of Richard 
Levitte 
Sent: Monday, February 13, 2017 11:15 AM
To: openssl-users@openssl.org
Subject: Re: [openssl-users] RSA engine is not using the functions mentioned in 
struct

In message 

 on Mon, 13 Feb 2017 10:57:27 +, khurram ashraf 
 said:

khurramashraf_786> Here the engine loads but when i try to encrypt a text file 
by using
khurramashraf_786> following command
khurramashraf_786>
khurramashraf_786> openssl pkeyutl -encrypt -in message.txt -pubin -inkey 
pubkey-B.pem -engine rsa_engine -out cipher.bin
khurramashraf_786> openssl pkeyutl -decrypt -in cipher.bin -inkey privkey-B.pem 
-engine rsa_engine -out rec.txt
khurramashraf_786>
khurramashraf_786> It seems that it is not using the functions which I defined 
in the
khurramashraf_786> struct_rsa. It is also not giving the output from the printf 
in the
khurramashraf_786> function.

You need to tell it where to find the engine as well.  libcrypto looks
in the standard system places (typically /usr/lib or so) and the path
given by the environment variable OPENSSL_ENGINES.  Try these lines
and see if that makes a difference:

OPENSSL_ENGINES=.
export OPENSSL_ENGINES
openssl pkeyutl -encrypt -in message.txt -pubin -inkey pubkey-B.pem -engine 
rsa_engine -out cipher.bin
openssl pkeyutl -decrypt -in cipher.bin -inkey privkey-B.pem -engine rsa_engine 
-out rec.txt

Cheers,
Richard

--
Richard Levitte levi...@openssl.org
OpenSSL Project http://www.openssl.org/~levitte/
--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users
openssl-users Info Page
mta.openssl.org
This mailing list is for discussion among those using the OpenSSL software. To 
see the collection of prior postings to the list, visit the openssl-users 
Archives


-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


Re: [openssl-users] RSA engine is not using the functions mentioned in struct

2017-02-13 Thread Richard Levitte
In message 

 on Mon, 13 Feb 2017 10:57:27 +, khurram ashraf 
 said:

khurramashraf_786> Here the engine loads but when i try to encrypt a text file 
by using
khurramashraf_786> following command
khurramashraf_786> 
khurramashraf_786> openssl pkeyutl -encrypt -in message.txt -pubin -inkey 
pubkey-B.pem -engine rsa_engine -out cipher.bin
khurramashraf_786> openssl pkeyutl -decrypt -in cipher.bin -inkey privkey-B.pem 
-engine rsa_engine -out rec.txt
khurramashraf_786> 
khurramashraf_786> It seems that it is not using the functions which I defined 
in the
khurramashraf_786> struct_rsa. It is also not giving the output from the printf 
in the
khurramashraf_786> function.

You need to tell it where to find the engine as well.  libcrypto looks
in the standard system places (typically /usr/lib or so) and the path
given by the environment variable OPENSSL_ENGINES.  Try these lines
and see if that makes a difference:

OPENSSL_ENGINES=.
export OPENSSL_ENGINES
openssl pkeyutl -encrypt -in message.txt -pubin -inkey pubkey-B.pem -engine 
rsa_engine -out cipher.bin
openssl pkeyutl -decrypt -in cipher.bin -inkey privkey-B.pem -engine rsa_engine 
-out rec.txt

Cheers,
Richard

-- 
Richard Levitte levi...@openssl.org
OpenSSL Project http://www.openssl.org/~levitte/
-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


[openssl-users] RSA engine is not using the functions mentioned in struct

2017-02-13 Thread khurram ashraf

I am new to making engines in openssl. Basically I want to implement an OpenSSL 
RSA engine that uses the functions I mentioned while encrypting and decrypting. 
My engine compiles and loads but it seems that it is not using the functions I 
want it to use for encryption and decryption.

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static int
eng_rsa_pub_enc (int flen, const unsigned char *from,
 unsigned char *to, RSA * rsa, int padding)
{

printf ("Engine is encrypting using pub key \n");
RSA_public_encrypt (flen, from, to, rsa, RSA_PKCS1_PADDING);
}

static int
eng_rsa_pub_dec (int flen, const unsigned char *from,
 unsigned char *to, RSA * rsa, int padding)
{

   printf ("Engine is decrypting using pub key \n");
   RSA_public_decrypt (flen, from, to, rsa, RSA_PKCS1_PADDING);
}

static int
eng_rsa_priv_enc (int flen, const unsigned char *from, unsigned char *to,
  RSA * rsa, int padding __attribute__ ((unused)))
{
   printf ("Engine is encrypting using priv key \n");
   RSA_private_encrypt (flen, from, to, rsa, RSA_PKCS1_PADDING);
}


static int
eng_rsa_priv_dec (int flen, const unsigned char *from, unsigned char *to,
  RSA * rsa, int padding __attribute__ ((unused)))
{
   printf ("Engine is decrypting using priv key \n");
   RSA_private_decrypt (flen, from, to, rsa, RSA_PKCS1_PADDING);
}

/* Constants used when creating the ENGINE */
static const char *engine_rsa_id = "rsa-engine 1";
static const char *engine_rsa_name = "engine for testing 1";



static RSA_METHOD struct_rsa = {
"RSA engine for demo",
eng_rsa_pub_enc,
eng_rsa_pub_dec,
eng_rsa_priv_enc,
eng_rsa_priv_dec,
NULL,
NULL,
NULL,
NULL,
RSA_FLAG_CACHE_PUBLIC | RSA_FLAG_CACHE_PRIVATE,
NULL,
NULL,
NULL
};

static int bind (ENGINE * e, const char *id)
{
  printf ("%s\n", id);

  if (!ENGINE_set_id (e, engine_rsa_id) ||
  !ENGINE_set_name (e, engine_rsa_name) ||
  !ENGINE_set_RSA (e, _rsa))
  return 0;

  return 1;
}

IMPLEMENT_DYNAMIC_BIND_FN (bind)
IMPLEMENT_DYNAMIC_CHECK_FN ()


I am compiling the code using following command.

gcc -fPIC -c rsa-engine.c
gcc -shared -o librsa_engine.so -lcrypto rsa-engine.o
openssl engine -t -c rsa_engine


Here the engine loads but when i try to encrypt a text file by using following 
command

openssl pkeyutl -encrypt -in message.txt -pubin -inkey pubkey-B.pem -engine 
rsa_engine -out cipher.bin
openssl pkeyutl -decrypt -in cipher.bin -inkey privkey-B.pem -engine rsa_engine 
-out rec.txt


It seems that it is not using the functions which I defined in the struct_rsa. 
It is also not giving the output from the printf in the function.

-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users