summaryrefslogtreecommitdiff
path: root/rsa
diff options
context:
space:
mode:
authorYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-13 05:33:00 +0530
committerYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-13 05:33:00 +0530
commite4499dbd73502f251e7b29d551bae7b333455114 (patch)
tree352dc00c48922c03d02370eb6ad22a16e4378f7b /rsa
parent3f2a76b70815816b135c96cdfe4966fab4952214 (diff)
downloadrsa-e4499dbd73502f251e7b29d551bae7b333455114.tar.gz
Finally tracked down the bug to incorrect padding. Now all tests should pass
for the new int2bytes.
Diffstat (limited to 'rsa')
-rw-r--r--rsa/transform.py17
1 files changed, 3 insertions, 14 deletions
diff --git a/rsa/transform.py b/rsa/transform.py
index c0f458e..396493e 100644
--- a/rsa/transform.py
+++ b/rsa/transform.py
@@ -153,14 +153,6 @@ def int2bytes(number, chunk_size=0,
``OverflowError`` when block_size is given and the number takes up more
bytes than fit into the block.
"""
- # Machine word-aligned implementation.
- # ~19x faster than naive implementation on 32-bit processors.
- # ~33x faster than naive implementation on 64-bit processors.
- # ~50x faster on 64-bit pypy 1.5
-
- # Don't need to raise TypeError ourselves. The code does that already
- # if a bad type is passed in as argument.
-
if number < 0:
raise ValueError('Number must be unsigned integer: %d' % number)
@@ -182,24 +174,21 @@ def int2bytes(number, chunk_size=0,
for zero_leading, x in enumerate(raw_bytes):
if x != _zero_byte[0]:
break
+ raw_bytes = raw_bytes[zero_leading:]
if chunk_size > 0:
# Bounds checking. We're not doing this up-front because the
# most common use case is not specifying a chunk size. In the worst
# case, the number will already have been converted to bytes above.
- #length = count * word_bytes
length = len(raw_bytes)
- bytes_needed = length - zero_leading
- if bytes_needed > chunk_size:
+ if length > chunk_size:
raise OverflowError(
"Need %d bytes for number, but chunk size is %d" %
- (bytes_needed, chunk_size)
+ (length, chunk_size)
)
remainder = length % chunk_size
if remainder:
raw_bytes = (chunk_size - remainder) * _zero_byte + raw_bytes
- else:
- raw_bytes = raw_bytes[zero_leading:]
return raw_bytes