wohaph / keyczar

Automatically exported from code.google.com/p/keyczar
0 stars 0 forks source link

OAEP Pading Error in Python #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
after few iterations this simple program

from keyczar import keyczar, keys
key = keys.RsaPrivateKey.Generate()
msg = "ciao"

for i in range(100):
    key.Decrypt(key.Encrypt(msg))

fails with the folloring exception:

Traceback (most recent call last):
  File "hello2.py", line 9, in <module>
    key.Decrypt(key.Encrypt(msg))
  File "/home/sciasbat/tmp/Keyczar-Python/keyczar/keys.py", line 563,
in Decrypt
    return self.__Decode(decrypted)
  File "/home/sciasbat/tmp/Keyczar-Python/keyczar/keys.py", line 478,
in __Decode
    raise errors.KeyczarError("OAEP Decoding Error")
keyczar.errors.KeyczarError: OAEP Decoding Error 

Original issue reported on code.google.com by stevew...@gmail.com on 3 Dec 2008 at 7:29

GoogleCodeExporter commented 9 years ago
This has been fixed in http://code.google.com/p/keyczar/source/detail?r=374

There were two problems, both due to leading zero bytes being mistakenly 
dropped from
encoded data. The first was an unnecessary TrimBytes() call in Util.Xor.

The second was due to PyCrypto trimming off leading zeros. The first OAEP 
decrypted
byte is expected to be a zero and we anticipated it being dropped. However, if 
more
leading bytes happened to be be zero, they were dropped as well. The fix was to 
check
the decrypted OAEP ciphertext size and add the leading zeros back. 

Original comment by stevew...@gmail.com on 16 Dec 2008 at 1:54