def test_backend(self): scrypt_mod.backend = None scrypt_mod._scrypt = None self.assertRaises(TypeError, scrypt_mod.scrypt, 's', 's', 2, 2, 2, 16) scrypt_mod._set_backend(self.backend) self.assertEqual(scrypt_mod.backend, self.backend) scrypt_mod.scrypt('s', 's', 2, 2, 2, 16) self.assertRaises(ValueError, scrypt_mod._set_backend, 'xxx') self.assertEqual(scrypt_mod.backend, self.backend) return
def _calc_checksum(self, secret): secret = to_bytes(secret, param='secret') return _scrypt.scrypt(secret, self.salt, n=1 << self.rounds, r=self.block_size, p=self.parallelism, keylen=self.checksum_size)
def test_reference_vectors(self): for secret, salt, n, r, p, keylen, result in self.reference_vectors: if n >= 1024 and TEST_MODE(max='default'): continue if n > 16384 and self.backend == 'builtin': continue log.debug('scrypt reference vector: %r %r n=%r r=%r p=%r', secret, salt, n, r, p) self.assertEqual(scrypt_mod.scrypt(secret, salt, n, r, p, keylen), result)
def test_other_backends(self): if self._already_tested_others: raise self.skipTest('already run under %r backend test' % self._already_tested_others) self._already_tested_others = self.backend rng = self.getRandom() orig = scrypt_mod.backend available = set(name for name in scrypt_mod.backend_values if scrypt_mod._has_backend(name)) scrypt_mod._set_backend(orig) available.discard(self.backend) if not available: raise self.skipTest('no other backends found') warnings.filterwarnings('ignore', '(?i)using builtin scrypt backend', category=exc.PasslibSecurityWarning) for _ in range(10): secret = getrandbytes(rng, rng.randint(0, 64)) salt = getrandbytes(rng, rng.randint(0, 64)) n = 1 << rng.randint(1, 10) r = rng.randint(1, 8) p = rng.randint(1, 3) ks = rng.randint(1, 64) previous = None backends = set() for name in available: scrypt_mod._set_backend(name) self.assertNotIn(scrypt_mod._scrypt, backends) backends.add(scrypt_mod._scrypt) result = hexstr(scrypt_mod.scrypt(secret, salt, n, r, p, ks)) self.assertEqual(len(result), 2 * ks) if previous is not None: self.assertEqual( result, previous, msg='%r output differs from others %r: %r' % (name, available, [secret, salt, n, r, p, ks])) return
def run_scrypt(keylen): return hexstr(scrypt_mod.scrypt('secret', 'salt', 2, 2, 2, keylen))
def run_scrypt(p, n=2, r=2): return hexstr(scrypt_mod.scrypt('secret', 'salt', n, r, p, 16))
def run_scrypt(n): return hexstr(scrypt_mod.scrypt('secret', 'salt', n, 2, 2, 16))
def run_scrypt(salt): return hexstr(scrypt_mod.scrypt('secret', salt, 2, 2, 2, 16))
def run_scrypt(secret): return hexstr(scrypt_mod.scrypt(secret, 'salt', 2, 2, 2, 16))