def test_pbkdf2(password, salt, rounds, hash_length, expected_hashes, run_fast): if rounds > 100000 and run_fast: pytest.skip(u"too slow for --fast") for method, expected_hash in expected_hashes.items(): try: hash = hexlify(_commoncrypto._pbkdf2( password, salt, rounds, hash_length, method )) assert hash == expected_hash except NotImplementedError: assert method not in _commoncrypto.METHODS
def pbkdf2(password, salt, rounds, hash_length, method="hmac-sha1"): if not (rounds >= 1): raise ValueError("rounds has to be >= 1, is %d" % rounds) if not (hash_length >= 1): raise ValueError("hash_length has to be >= 1, is %d" % hash_length) return _pbkdf2(password, salt, rounds, hash_length, method)