summaryrefslogtreecommitdiff
path: root/passlib
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2016-06-20 12:00:51 -0400
committerEli Collins <elic@assurancetechnologies.com>2016-06-20 12:00:51 -0400
commit13456ce8d38c05fa5d2db5e52cd79e448e973397 (patch)
treeb0eb492bca620e71dcf8db28864c694bb9558251 /passlib
parent62c6506310c796137f94323d285159131873e353 (diff)
downloadpasslib-13456ce8d38c05fa5d2db5e52cd79e448e973397.tar.gz
cleanup: 'uint4/8' refs incorrectly named, should be 'uint32/64'
Diffstat (limited to 'passlib')
-rw-r--r--passlib/crypto/digest.py14
-rw-r--r--passlib/handlers/argon2.py9
-rw-r--r--passlib/tests/test_crypto_scrypt.py34
-rw-r--r--passlib/tests/test_handlers_argon2.py2
-rw-r--r--passlib/utils/des.py4
5 files changed, 31 insertions, 32 deletions
diff --git a/passlib/crypto/digest.py b/passlib/crypto/digest.py
index 530fba4..c2d7e47 100644
--- a/passlib/crypto/digest.py
+++ b/passlib/crypto/digest.py
@@ -42,10 +42,10 @@ __all__ = [
#=============================================================================
#: max 32-bit value
-MAX_UINT4 = (1<<32)-1
+MAX_UINT32 = (1 << 32) - 1
#: max 64-bit value
-MAX_UINT8 = (1<<64)-1
+MAX_UINT64 = (1 << 64) - 1
#=============================================================================
# hash utils
@@ -560,7 +560,7 @@ def pbkdf1(digest, secret, salt, rounds, keylen=None):
# pbkdf2
#=============================================================================
-_pack_uint4 = Struct(">L").pack
+_pack_uint32 = Struct(">L").pack
def pbkdf2_hmac(digest, secret, salt, rounds, keylen=None):
"""pkcs#5 password-based key derivation v2.0 using HMAC + arbitrary digest.
@@ -628,7 +628,7 @@ def pbkdf2_hmac(digest, secret, salt, rounds, keylen=None):
# get helper to calculate blocks, and return result
calc_block = _get_pbkdf2_looper(digest_size)
return join_bytes(
- calc_block(keyed_hmac, keyed_hmac(salt + _pack_uint4(i)), rounds)
+ calc_block(keyed_hmac, keyed_hmac(salt + _pack_uint32(i)), rounds)
for i in irange(1, block_count + 1)
)[:keylen]
@@ -708,17 +708,17 @@ elif _force_backend in ["any", "unpack", "from_bytes"]:
# figure out most efficient struct format to unpack digest into list of native ints
#
if _have_64_bit and not digest_size & 0x7:
- # digest size multiple of 8, on a 64 bit system -- use array of UINT8
+ # digest size multiple of 8, on a 64 bit system -- use array of UINT64
count = (digest_size >> 3)
fmt = "=%dQ" % count
elif not digest_size & 0x3:
if _have_64_bit:
- # digest size multiple of 4, on a 64 bit system -- use array of UINT8 + 1 UINT4
+ # digest size multiple of 4, on a 64 bit system -- use array of UINT64 + 1 UINT32
count = (digest_size >> 3)
fmt = "=%dQI" % count
count += 1
else:
- # digest size multiple of 4, on a 32 bit system -- use array of UINT4
+ # digest size multiple of 4, on a 32 bit system -- use array of UINT32
count = (digest_size >> 2)
fmt = "=%dI" % count
else:
diff --git a/passlib/handlers/argon2.py b/passlib/handlers/argon2.py
index 5a7fdd2..006eecd 100644
--- a/passlib/handlers/argon2.py
+++ b/passlib/handlers/argon2.py
@@ -27,6 +27,7 @@ _argon2_cffi = None # loaded below
_argon2pure = None # dynamically imported by _load_backend_argon2pure()
# pkg
from passlib import exc
+from passlib.crypto.digest import MAX_UINT32
from passlib.utils import classproperty, to_bytes, b64s_encode, b64s_decode
from passlib.utils.compat import u, bascii_to_str, get_unbound_method_function
import passlib.utils.handlers as uh
@@ -85,8 +86,6 @@ else:
hash_len = 16
_default_version = 0x13
-MAX_UINT4 = (1 << 32) - 1
-
#=============================================================================
# handler
#=============================================================================
@@ -183,7 +182,7 @@ class argon2(uh.ParallelismMixin, uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum
#------------------------
default_salt_size = _default_settings.salt_len
min_salt_size = 8
- max_salt_size = MAX_UINT4
+ max_salt_size = MAX_UINT32
#------------------------
# HasRounds
@@ -192,7 +191,7 @@ class argon2(uh.ParallelismMixin, uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum
#------------------------
default_rounds = _default_settings.time_cost
min_rounds = 1
- max_rounds = MAX_UINT4
+ max_rounds = MAX_UINT32
rounds_cost = "linear"
#------------------------
@@ -271,7 +270,7 @@ class argon2(uh.ParallelismMixin, uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum
if isinstance(digest_size, uh.native_string_types):
digest_size = int(digest_size)
# NOTE: this isn't *really* digest size minimum, but want to enforce secure minimum.
- subcls.checksum_size = uh.norm_integer(subcls, digest_size, min=16, max=MAX_UINT4,
+ subcls.checksum_size = uh.norm_integer(subcls, digest_size, min=16, max=MAX_UINT32,
param="digest_size", relaxed=relaxed)
# set memory cost
diff --git a/passlib/tests/test_crypto_scrypt.py b/passlib/tests/test_crypto_scrypt.py
index 460745f..d7d2b90 100644
--- a/passlib/tests/test_crypto_scrypt.py
+++ b/passlib/tests/test_crypto_scrypt.py
@@ -32,8 +32,8 @@ def hexstr(data):
"""return bytes as hex str"""
return bascii_to_str(hexlify(data))
-def unpack_int4_list(data, check_count=None):
- """unpack bytes as list of uint4 values"""
+def unpack_uint32_list(data, check_count=None):
+ """unpack bytes as list of uint32 values"""
count = len(data) // 4
assert check_count is None or check_count == count
return struct.unpack("<%dI" % count, data)
@@ -97,7 +97,7 @@ class ScryptEngineTest(TestCase):
"""bmix()"""
from passlib.crypto.scrypt._builtin import ScryptEngine
- # NOTE: bmix() call signature currently takes in list of 32*r uint4 elements,
+ # NOTE: bmix() call signature currently takes in list of 32*r uint32 elements,
# and writes to target buffer of same size.
def check_bmix(r, input, output):
@@ -125,9 +125,9 @@ class ScryptEngineTest(TestCase):
# NOTE: this pair corresponds to the first input & output pair
# from the test vector in test_smix(), above.
# NOTE: original reference lists input & output as two separate 64 byte blocks.
- # current internal representation used by bmix() uses single 2*r*16 array of uint4,
+ # current internal representation used by bmix() uses single 2*r*16 array of uint32,
# combining all the B blocks into a single flat array.
- input = unpack_int4_list(hb("""
+ input = unpack_uint32_list(hb("""
f7 ce 0b 65 3d 2d 72 a4 10 8c f5 ab e9 12 ff dd
77 76 16 db bb 27 a7 0e 82 04 f3 ae 2d 0f 6f ad
89 f6 8f 48 11 d1 e8 7b cc 3b d7 40 0a 9f fd 29
@@ -139,7 +139,7 @@ class ScryptEngineTest(TestCase):
7f 4d 1c ad 6a 52 3c da 77 0e 67 bc ea af 7e 89
"""), 32)
- output = unpack_int4_list(hb("""
+ output = unpack_uint32_list(hb("""
a4 1f 85 9c 66 08 cc 99 3b 81 ca cb 02 0c ef 05
04 4b 21 81 a2 fd 33 7d fd 7b 1c 63 96 68 2f 29
b4 39 31 68 e3 c9 e6 bc fe 6b c5 b7 a0 6d 96 ba
@@ -159,9 +159,9 @@ class ScryptEngineTest(TestCase):
#-----------------------------------------------------------------------
r = 2
- input = unpack_int4_list(seed_bytes("bmix with r=2", 128 * r))
+ input = unpack_uint32_list(seed_bytes("bmix with r=2", 128 * r))
- output = unpack_int4_list(hb("""
+ output = unpack_uint32_list(hb("""
ba240854954f4585f3d0573321f10beee96f12acdc1feb498131e40512934fd7
43e8139c17d0743c89d09ac8c3582c273c60ab85db63e410d049a9e17a42c6a1
@@ -183,9 +183,9 @@ class ScryptEngineTest(TestCase):
#-----------------------------------------------------------------------
r = 3
- input = unpack_int4_list(seed_bytes("bmix with r=3", 128 * r))
+ input = unpack_uint32_list(seed_bytes("bmix with r=3", 128 * r))
- output = unpack_int4_list(hb("""
+ output = unpack_uint32_list(hb("""
11ddd8cf60c61f59a6e5b128239bdc77b464101312c88bd1ccf6be6e75461b29
7370d4770c904d0b09c402573cf409bf2db47b91ba87d5a3de469df8fb7a003c
@@ -213,9 +213,9 @@ class ScryptEngineTest(TestCase):
#-----------------------------------------------------------------------
r = 4
- input = unpack_int4_list(seed_bytes("bmix with r=4", 128 * r))
+ input = unpack_uint32_list(seed_bytes("bmix with r=4", 128 * r))
- output = unpack_int4_list(hb("""
+ output = unpack_uint32_list(hb("""
803fcf7362702f30ef43250f20bc6b1b8925bf5c4a0f5a14bbfd90edce545997
3047bd81655f72588ca93f5c2f4128adaea805e0705a35e14417101fdb1c498c
@@ -247,8 +247,8 @@ class ScryptEngineTest(TestCase):
"""salsa20()"""
from passlib.crypto.scrypt._builtin import salsa20
- # NOTE: salsa2() currently operates on lists of 16 uint4 elements,
- # which is what unpack_int4_list(hb(() is for...
+ # NOTE: salsa2() currently operates on lists of 16 uint32 elements,
+ # which is what unpack_uint32_list(hb(() is for...
#-----------------------------------------------------------------------
# test vector from (expired) scrypt rfc draft
@@ -258,14 +258,14 @@ class ScryptEngineTest(TestCase):
# NOTE: this pair corresponds to the first input & output pair
# from the test vector in test_bmix(), above.
- input = unpack_int4_list(hb("""
+ input = unpack_uint32_list(hb("""
7e 87 9a 21 4f 3e c9 86 7c a9 40 e6 41 71 8f 26
ba ee 55 5b 8c 61 c1 b5 0d f8 46 11 6d cd 3b 1d
ee 24 f3 19 df 9b 3d 85 14 12 1e 4b 5a c5 aa 32
76 02 1d 29 09 c7 48 29 ed eb c6 8d b8 b8 c2 5e
"""))
- output = unpack_int4_list(hb("""
+ output = unpack_uint32_list(hb("""
a4 1f 85 9c 66 08 cc 99 3b 81 ca cb 02 0c ef 05
04 4b 21 81 a2 fd 33 7d fd 7b 1c 63 96 68 2f 29
b4 39 31 68 e3 c9 e6 bc fe 6b c5 b7 a0 6d 96 ba
@@ -278,7 +278,7 @@ class ScryptEngineTest(TestCase):
# used to check for salsa20() breakage while optimizing _gen_files output.
#-----------------------------------------------------------------------
input = list(range(16))
- output = unpack_int4_list(hb("""
+ output = unpack_uint32_list(hb("""
f518dd4fb98883e0a87954c05cab867083bb8808552810752285a05822f56c16
9d4a2a0fd2142523d758c60b36411b682d53860514b871d27659042a5afa475d
"""))
diff --git a/passlib/tests/test_handlers_argon2.py b/passlib/tests/test_handlers_argon2.py
index 9204a6a..b31b614 100644
--- a/passlib/tests/test_handlers_argon2.py
+++ b/passlib/tests/test_handlers_argon2.py
@@ -132,7 +132,7 @@ class _base_argon2_test(HandlerCase):
# missing 'm' param
"$argon2i$v=19$t=2,p=4$c29tZXNhbHQAAAAAAAAAAA$QWLzI4TY9HkL2ZTLc8g6SinwdhZewYrzz9zxCo0bkGY",
- # 't' param > 32 bit uint
+ # 't' param > max uint32
"$argon2i$v=19$m=65536,t=8589934592,p=4$c29tZXNhbHQAAAAAAAAAAA$QWLzI4TY9HkL2ZTLc8g6SinwdhZewYrzz9zxCo0bkGY",
# unexpected param
diff --git a/passlib/utils/des.py b/passlib/utils/des.py
index 2eb556b..62adac4 100644
--- a/passlib/utils/des.py
+++ b/passlib/utils/des.py
@@ -30,7 +30,7 @@ des_encrypt_int_block = deprecated_function(deprecated="1.7", removed="1.8",
# deprecated functions -- not carried over to passlib.crypto.des
#=============================================================================
import struct
-_unpack_uint8 = struct.Struct(">Q").unpack
+_unpack_uint64 = struct.Struct(">Q").unpack
@deprecated_function(deprecated="1.6", removed="1.8",
replacement="passlib.crypto.des.des_encrypt_int_block()")
@@ -38,7 +38,7 @@ def mdes_encrypt_int_block(key, input, salt=0, rounds=1): # pragma: no cover --
if isinstance(key, bytes):
if len(key) == 7:
key = expand_des_key(key)
- key = _unpack_uint8(key)[0]
+ key = _unpack_uint64(key)[0]
return des_encrypt_int_block(key, input, salt, rounds)
#=============================================================================