[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openssl-users
Subject:    problem on RSA_public_decrypt()
From:       ç <luxiang527 () gmail ! com>
Date:       2010-06-28 5:46:47
Message-ID: AANLkTinz9cbSm8dwqLbsNioiHonyMZ6jmm6Fs6-9L9ll () mail ! gmail ! com
[Download RAW message or body]

Dear all,

I am sorry for the bad email formation. Here is another post.

I am programming to achieve the RSA PSS sign for the messages. For the
signature, I think the result is correct by the information in gdb. However,
for the verification, the RSA_public_decrypt() always fails to put the
decrypted signature into the designed buffer, which makes the verification
process fails. I would like to post my code segment and solicit your
suggestions for my code. I really appreciate your help. Thank you so much.

/*Sig function*/
unsigned char* sign(unsigned char *apdu_dig, RSA *pKey)
{
  unsigned char sig[128];
  unsigned char pad[128];

  RSA_padding_add_PKCS1_PSS(pKey, pad, apdu_dig, EVP_sha256(), -2);

  RSA_private_encrypt(128, pad, sig, pKey, RSA_NO_PADDING);
 retrurn goose_sig;
}

/*Veri function*/
int verification (unsigned char *apdu_data, unsigned char *signature, int
data_len, int sig_len, RSA *pKey)
{
  unsigned char decrypted_sig[128];
  unsigned char *apdu_dig;
  int ret;

  apdu_dig = digest(apdu_data, data_len); //This function works fine.

    RSA_public_decrypt(128, signature, decrypted_sig, pKey, RSA_NO_PADDING);

  ret = RSA_verify_PKCS1_PSS(pKey, apdu_dig, EVP_sha256(), decrypted_sig,
-2);

  return ret;
}

FYI, the RSA *pKey is generated by RSA_generate_key(1024, RSA_F4, NULL,
NULL).


Thank you so much.

Best Regards,
Xiang

[Attachment #3 (text/html)]

<font class="Apple-style-span" face="arial, sans-serif"><span \
class="Apple-style-span" style="border-collapse: collapse;"><span \
class="Apple-style-span" style="border-collapse: separate; font-family: Tahoma, \
Verdana, Arial, sans-serif; font-size: 13px; color: rgb(68, 68, 68); ">Dear all,<div \
style="text-indent: 0in !important; "> <br></div><div style="text-indent: 0in \
!important; ">I am sorry for the bad email formation. Here is another post.</div><div \
style="text-indent: 0in !important; "><br></div><div style="text-indent: 0in \
!important; ">I am programming to achieve the RSA PSS sign for the messages. For the \
signature, I think the result is correct by the information in gdb. However, for the \
verification, the RSA_public_decrypt() always fails to put the decrypted signature \
into the designed buffer, which makes the verification process fails. I would like to \
post my code segment and solicit your suggestions for my code. I really appreciate \
your help. Thank you so much.</div> <div style="text-indent: 0in !important; "><br \
style="text-indent: 0in !important; "></div><div style="text-indent: 0in !important; \
">/*Sig function*/</div><div style="text-indent: 0in !important; ">unsigned char* \
sign(unsigned char *apdu_dig, RSA *pKey)</div> <div style="text-indent: 0in \
!important; ">{</div><div style="text-indent: 0in !important; "><span \
class="Apple-style-span" style="white-space: pre;">     </span>unsigned char \
sig[128];</div><div style="text-indent: 0in !important; "> <span \
class="Apple-style-span" style="white-space: pre;">     </span>unsigned char \
pad[128];</div><div style="text-indent: 0in !important; "><br style="text-indent: 0in \
!important; "></div><div style="text-indent: 0in !important; "> <span \
class="Apple-style-span" style="white-space: pre;">     \
</span>RSA_padding_add_PKCS1_PSS(pKey, pad, apdu_dig, EVP_sha256(), -2);</div><div \
style="text-indent: 0in !important; "><br style="text-indent: 0in !important; "> \
</div><div style="text-indent: 0in !important; "><span class="Apple-style-span" \
style="white-space: pre;">     </span>RSA_private_encrypt(128, pad, sig, pKey, \
RSA_NO_PADDING);</div><div style="text-indent: 0in !important; "> <span \
class="ecxApple-tab-span" style="text-indent: 0in !important; white-space: pre; \
">	</span></div><div style="text-indent: 0in !important; "><span \
class="ecxApple-tab-span" style="text-indent: 0in !important; white-space: pre; ">    \
r</span>etrurn goose_sig;</div> <div style="text-indent: 0in !important; \
">}</div><div style="text-indent: 0in !important; "><br style="text-indent: 0in \
!important; "></div><div style="text-indent: 0in !important; ">/*Veri \
function*/</div><div style="text-indent: 0in !important; "> int verification \
(unsigned char *apdu_data, unsigned char *signature, int data_len, int sig_len, RSA \
*pKey)</div><div style="text-indent: 0in !important; ">{</div><div \
style="text-indent: 0in !important; "><span class="Apple-style-span" \
style="white-space: pre;">     </span>unsigned char decrypted_sig[128];</div> <div \
style="text-indent: 0in !important; "><span class="Apple-style-span" \
style="white-space: pre;">     </span>unsigned char *apdu_dig;</div><div \
style="text-indent: 0in !important; "><span class="Apple-style-span" \
style="white-space: pre;">     </span>int ret;</div> <div style="text-indent: 0in \
!important; "><br style="text-indent: 0in !important; "></div><div \
style="text-indent: 0in !important; "><span class="Apple-style-span" \
style="white-space: pre;">     </span>apdu_dig = digest(apdu_data, data_len); //This \
function works fine.</div> <div style="text-indent: 0in !important; "><br></div><div \
style="text-indent: 0in !important; ">       RSA_public_decrypt(128, signature, \
decrypted_sig, pKey, RSA_NO_PADDING);</div><div style="text-indent: 0in !important; \
"> <br style="text-indent: 0in !important; "></div><div style="text-indent: 0in \
!important; "><span class="Apple-style-span" style="white-space: pre;">     \
</span>ret = RSA_verify_PKCS1_PSS(pKey, apdu_dig, EVP_sha256(), decrypted_sig, \
-2);</div> <div style="text-indent: 0in !important; "><br style="text-indent: 0in \
!important; "></div><div style="text-indent: 0in !important; "><span \
class="Apple-style-span" style="white-space: pre;">     </span>return ret;</div><div \
style="text-indent: 0in !important; "> }</div><div style="text-indent: 0in \
!important; "><br style="text-indent: 0in !important; "></div><div \
style="text-indent: 0in !important; ">FYI, the RSA *pKey is generated by \
RSA_generate_key(1024, RSA_F4, NULL, NULL).</div> <div style="text-indent: 0in \
!important; "><br style="text-indent: 0in !important; "></div><div \
style="text-indent: 0in !important; "><br style="text-indent: 0in !important; \
"></div><div style="text-indent: 0in !important; "> Thank you so much.</div><div \
style="text-indent: 0in !important; "><br style="text-indent: 0in !important; \
"></div><div style="text-indent: 0in !important; ">Best Regards,</div><div \
style="text-indent: 0in !important; ">Xiang</div> </span></span></font>


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majordomo@openssl.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic