Dear all,

My code segment is to get a private key from a pem file for the data
signing. The code is as the following:

1    BIO *priv_pem;

2    OpenSSL_add_all_algorithms();

3    priv_pem = BIO_new_file("privkey.pem", "rb");

 4   pKey_priv = RSA_new();

 5   pKey_priv = PEM_read_bio_RSAPrivateKey(priv_pem, &pKey_priv, NULL,
"3042");

 6   BIO_free(priv_pem);

  7  data_generator(data_len, raw_apdu);

  8  hdr_generator(p_h);

   As you see, the first six lines are to get the private key, and the last
two lines are to generate the data. My problem is that all the code below
the line 6 are optimized out in gcc with the optimization option "-O2". The
problem disappears when the option is set to "-O0", that means shut down the
code optimization in gcc. In addition, when "-O2", the order of the code
execution is strange when using gdb for debugging.

   I am not sure about the source of this problem. I guess that I made some
mistakes when I used the function "PEM_read_bio_RSAPrivateKey()". Could
anybody please tell me the method for me to use the function? Or, could you
please help me to fix this problem. Thank you so much.

Best Regards,
Xiang

Reply via email to