[pycrypto] Crypto.PublicKey.RSA and number.py

Mads Kiilerich mads at kiilerich.com
Thu Mar 12 20:33:59 CST 2009


Anthony Honstain wrote, On 03/12/2009 06:47 AM:
> I am working towards using the Crypto.PublicKey.RSA encryption and
> eventually padding like PKCS#1. I have observed that the leading
> '\000' are removed. Is this the desired behavior of bytes_to_long and
> long_to_bytes? Or is this not an issue once a good padding scheme is
> implemented?
>   

Yes, kind of.

RSA basically uses big numbers. The numbers are often encoded as byte 
strings, and any (not too long) string can be interpreted as a number. 
But just like in decimal numbers the leading zeroes doesn't matter; you 
can't see from the value how many leading zeroes it was written with, 
and an arbitrary number of leading zeroes can be added without changing 
the value.

Yes, a good padding scheme will "fix" that; not so much in order to 
preserve a string length, but more in order to ensure that the number is 
big enough to preserve the assumed computational complexity of RSA.

/Mads

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3435 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.dlitz.net/pipermail/pycrypto/attachments/20090313/a0d0891b/attachment.bin 


More information about the pycrypto mailing list