Skip to content

Commit cdd32ab

Browse files
committed
crypt: Allow RC4Ciphers that don't hash the key
It turns out some internal test code is uncleanly accessing the RC4Cipher module, using a key that is already hashed. Allow the caller to decline more hashing.
1 parent d18f9ad commit cdd32ab

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

pynuodb/crypt.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ class RC4CipherNuoDB(BaseCipher):
400400
name = 'RC4-local'
401401
keysize = int(160 / 8)
402402

403-
def __init__(self, _, key):
404-
# type: (bool, bytes) -> None
403+
def __init__(self, _, key, convert=True):
404+
# type: (bool, bytes, bool) -> None
405405
"""Create an RC4 cipher using the given key.
406406
407407
This uses a native Python implementation which is sloooooow.
@@ -410,6 +410,7 @@ def __init__(self, _, key):
410410
411411
:param encrypt: True if encrypting, False if decrypting
412412
:param key: The cipher key.
413+
:param convert: If True hash the key
413414
"""
414415
super(RC4CipherNuoDB, self).__init__()
415416

@@ -419,7 +420,10 @@ def __init__(self, _, key):
419420

420421
state = self.__state
421422

422-
data = bytesToArray(self._convert_key(key))
423+
if convert:
424+
key = self._convert_key(key)
425+
data = bytesToArray(key)
426+
423427
sz = len(data)
424428
j = 0
425429
for i in range(256):
@@ -465,14 +469,17 @@ class RC4CipherCryptography(BaseCipher):
465469
name = 'RC4'
466470
keysize = int(160 / 8)
467471

468-
def __init__(self, encrypt, key):
469-
# type: (bool, bytes) -> None
472+
def __init__(self, encrypt, key, convert=True):
473+
# type: (bool, bytes, bool) -> None
470474
"""Create an RC4 cipher using the given key.
471475
472476
:param encrypt: True if encrypting, False if decrypting
473477
:param key: The key to initialize from.
478+
:param convert: If True hash the key
474479
"""
475-
algo = ARC4(self._convert_key(key))
480+
if convert:
481+
key = self._convert_key(key)
482+
algo = ARC4(key)
476483

477484
# There's a bug in older versions of mypy where they don't infer the
478485
# optionality of mode correctly.

0 commit comments

Comments
 (0)