diff options
Diffstat (limited to 'passlib/crypto/des.py')
-rw-r--r-- | passlib/crypto/des.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/passlib/crypto/des.py b/passlib/crypto/des.py index 3f87aef..fc63ee0 100644 --- a/passlib/crypto/des.py +++ b/passlib/crypto/des.py @@ -47,8 +47,6 @@ The netbsd des-crypt implementation has some nice notes on how this all works - import struct # pkg from passlib import exc -from passlib.utils.compat import join_byte_values, byte_elem_value, \ - irange, irange, int_types # local __all__ = [ "expand_des_key", @@ -606,14 +604,14 @@ def _unpack56(value): ## assert 0 <= value < 0x80, "value out of range" ## return (value<<1) | (0x9669 >> ((value ^ (value >> 4)) & 0xf)) & 1 -_EXPAND_ITER = irange(49,-7,-7) +_EXPAND_ITER = range(49, -7, -7) def expand_des_key(key): """convert DES from 7 bytes to 8 bytes (by inserting empty parity bits)""" if isinstance(key, bytes): if len(key) != 7: raise ValueError("key must be 7 bytes in size") - elif isinstance(key, int_types): + elif isinstance(key, int): if key < 0 or key > INT_56_MASK: raise ValueError("key must be 56-bit non-negative integer") return _unpack64(expand_des_key(_pack56(key))) @@ -624,9 +622,8 @@ def expand_des_key(key): # but the parity bit would just be ignored in des_encrypt_block(), # so not bothering to use it. # XXX: could make parity-restoring optionally available via flag - ##return join_byte_values(expand_7bit((key >> shift) & 0x7f) - ## for shift in _EXPAND_ITER) - return join_byte_values(((key>>shift) & 0x7f)<<1 for shift in _EXPAND_ITER) + ##return bytes(expand_7bit((key >> shift) & 0x7f) for shift in _EXPAND_ITER) + return bytes(((key >> shift) & 0x7f) << 1 for shift in _EXPAND_ITER) def shrink_des_key(key): """convert DES key from 8 bytes to 7 bytes (by discarding the parity bits)""" @@ -634,7 +631,7 @@ def shrink_des_key(key): if len(key) != 8: raise ValueError("key must be 8 bytes in size") return _pack56(shrink_des_key(_unpack64(key))) - elif isinstance(key, int_types): + elif isinstance(key, int): if key < 0 or key > INT_64_MASK: raise ValueError("key must be 64-bit non-negative integer") else: @@ -748,13 +745,13 @@ def des_encrypt_int_block(key, input, salt=0, rounds=1): raise ValueError("salt must be 24-bit non-negative integer") # validate & unpack key - if not isinstance(key, int_types): + if not isinstance(key, int): raise exc.ExpectedTypeError(key, "int", "key") elif key < 0 or key > INT_64_MASK: raise ValueError("key must be 64-bit non-negative integer") # validate & unpack input - if not isinstance(input, int_types): + if not isinstance(input, int): raise exc.ExpectedTypeError(input, "int", "input") elif input < 0 or input > INT_64_MASK: raise ValueError("input must be 64-bit non-negative integer") |