Simon Edwards <[EMAIL PROTECTED]>:

> I'm having problems using the RSA routines from openssl 0.9.4.  I've got
> a very simple C program which generates and RSA key (I'm not worried
> about the randomness of the key at this stage) and then proceeds to
> read data from a file encrypting the data and then decrypting it and
> comparing the output with the original text. (See attached C file)
> 
> Whenever I pass straight ASCII text to the program it works fine and all
> the output matches the input.  However, when I pass a binary file the
> first dozen or so blocks encrypt and decrypt fine, but after that I get
> *some* blocks (on some files it can be most blocks but not all) that
> don't decrypt back to the original data.  

You are not using RSA properly.  Read in some cryptography FAQ or
textbook about padding.  What is happening in your program is that
after decryption you have the original data block modulo  n,  which
means no change when it is pure ASCII (and  n's  size in bits is
a multiple of 8), but can lead to corrupt data when the first byte
has the MSB set: then possibly the plaintext block  P  is  >= n,
and the decryption result is  P - n  instead of  P.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to