Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

rsa_publiic_encrypt problem

0 views
Skip to first unread message

Chris Rutherford

unread,
Sep 19, 2005, 12:52:58 PM9/19/05
to
Hi All,

I have a strange problem with RSA_Public_Encrypt. Basically it only
produces decipherable information about 50% of the time, but with the
same clear text string. i.e. I have an RSA encrypt decrypt benchmark
program using a static clear text char string. sometimes it works,
but other times it produces a padding error when I decrypt, but using
the same clear text. Is this some kind of seeding problem? How else
could it work about 50% of the time with the same clear text?

Thanks

Chris R


______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openss...@openssl.org
Automated List Manager majo...@openssl.org

Steven Reddie

unread,
Sep 19, 2005, 9:26:27 PM9/19/05
to
It sounds like a padding issue. Which padding mode are you specifying, what
is the key length, and what is the length of the plaintext? To be clear,
the encrypt succeeds all of the time, but the decrypt fails half of the
time?

Dr. Stephen Henson

unread,
Sep 19, 2005, 10:19:57 PM9/19/05
to
On Mon, Sep 19, 2005, Chris Rutherford wrote:

> Hi All,
>
> I have a strange problem with RSA_Public_Encrypt. Basically it only
> produces decipherable information about 50% of the time, but with the
> same clear text string. i.e. I have an RSA encrypt decrypt benchmark
> program using a static clear text char string. sometimes it works,
> but other times it produces a padding error when I decrypt, but using
> the same clear text. Is this some kind of seeding problem? How else
> could it work about 50% of the time with the same clear text?
>

I did answer this before but it doesn't seem to have made it to the list. Are
you assuming the result is a text string and using/copying it with something
like strlen()? If so that will fail if the result contains an embedded null.

RSA_public_encrypt() with PKCS#1 padding contains a random element so you will
get different results for the same plaintext.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Funding needed! Details on homepage.
Homepage: http://www.drh-consultancy.demon.co.uk

Chris Rutherford

unread,
Sep 20, 2005, 12:42:56 PM9/20/05
to
Hi Steve,

I've just solved the problem, as you correctly guessed, I was using
strlen(buffer) as the length of the string to decrypt. The fact that
it was sometimes working would be the case where the random element
would not result in an embedded null being produced. I suppose this
problem is why people use the bp bio structure. i.e. this contains
both data and datalen parameters.

Thanks

Chris R

0 new messages