some rsa keys only produce 255 bytes when encrypting spaces
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Python-Crypto |
New
|
Undecided
|
Unassigned |
Bug Description
i was writing some tests to help get rid of stray strip()s where they shouldn't be, and ran into this:
def testSpaces(self):
keys = [RSA.generate(
#roughly one in 20 randomly generated keys seem to always return 255 bytes instead of
#256 when encrypting strings consisting only of the space character
#this is one of them cherry picked to make the issue reproducible
RSA.
MIIEpQIBAAKCAQE
b8j8K/9AFjvAdnX
A3iZjW+
HcKmOED3I+
LhPqGIsM8oSQ9/
0XcicTi/
FR1clBL+
+12BmerzYgq6bUn
VHanc1vTPfg329W
Xru5PHS718bxgzW
hYethCFWSlFf6Iu
jc3n+TW5AoGBANF
g7tCnAbC9eIgxwo
sB46SaYBdKoZ+
Qk3wCxJhv+
vQPDDXR9SO1LAPj
BeulfGhkK24XrtM
Mli6V4cAhfiY+
SNyE1pvKMaPH3mx
+VF/q7Qjvw/
yoNlJE5AIHnnST3
v7I8etMfrlWdOFS
XCmxby0CgYEAm1N
X8xkZ2VdQ+
9kJ6RPcK6eMQ/
-----END RSA PRIVATE KEY-----"""),
]
for key in keys:
clear = ' ' * 10
ciphertext = key.encrypt(clear, os.urandom)
self.
self.
turns out it happens with any string, when converting from a python long to bytes any leading null bytes end up missing.
(encrypting any given string with 256 newly generated keys will reliably produce at least one that demonstrates this issue)