diff options
author | Yesudeep Mangalapilly <yesudeep@gmail.com> | 2011-08-13 05:33:00 +0530 |
---|---|---|
committer | Yesudeep Mangalapilly <yesudeep@gmail.com> | 2011-08-13 05:33:00 +0530 |
commit | 8d6bdf412f353040a2e7383d2dcc7eb36453fbc1 (patch) | |
tree | 352dc00c48922c03d02370eb6ad22a16e4378f7b | |
parent | ce4ede758d0c0a35925e4c1f4184ca06027baa91 (diff) | |
download | rsa-git-8d6bdf412f353040a2e7383d2dcc7eb36453fbc1.tar.gz |
Finally tracked down the bug to incorrect padding. Now all tests should pass
for the new int2bytes.
-rw-r--r-- | rsa/transform.py | 17 |
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 |