Exemplo n.º 1
0
def pbkdf2(secret, salt, rounds, keylen=None, prf='hmac-sha1'):
    if callable(prf) or isinstance(
            prf, native_string_types) and not prf.startswith(_HMAC_PREFIXES):
        raise NotImplementedError(
            'non-HMAC prfs are not supported as of Passlib 1.7')
    digest = prf[5:]
    return pbkdf2_hmac(digest, secret, salt, rounds, keylen)
Exemplo n.º 2
0
 def _cipher_aes_key(value, secret, salt, cost, decrypt=False):
     if _cg_ciphers is None:
         raise RuntimeError(
             "TOTP encryption requires 'cryptography' package (https://cryptography.io)"
         )
     keyiv = pbkdf2_hmac('sha256',
                         secret,
                         salt=salt,
                         rounds=1 << cost,
                         keylen=48)
     cipher = _cg_ciphers.Cipher(_cg_ciphers.algorithms.AES(keyiv[:32]),
                                 _cg_ciphers.modes.CTR(keyiv[32:]),
                                 _cg_default_backend())
     ctx = cipher.decryptor() if decrypt else cipher.encryptor()
     return ctx.update(value) + ctx.finalize()
Exemplo n.º 3
0
 def raw(cls, secret, user):
     from otp.ai.passlib.crypto.digest import pbkdf2_hmac
     secret = to_unicode(secret, 'utf-8', param='secret').encode('utf-16-le')
     user = to_unicode(user, 'utf-8', param='user').lower().encode('utf-16-le')
     tmp = md4(md4(secret).digest() + user).digest()
     return pbkdf2_hmac('sha1', tmp, user, 10240, 16)
Exemplo n.º 4
0
 def helper(secret='password',
            salt='salt',
            rounds=1,
            keylen=None,
            digest='sha1'):
     return pbkdf2_hmac(digest, secret, salt, rounds, keylen)
Exemplo n.º 5
0
 def derive_digest(cls, password, salt, rounds, alg):
     if isinstance(password, bytes):
         password = password.decode('utf-8')
     return pbkdf2_hmac(alg, saslprep(password), salt, rounds)
Exemplo n.º 6
0
 def test_known(self):
     for row in self.pbkdf2_test_vectors:
         correct, secret, salt, rounds, keylen = row[:5]
         digest = row[5] if len(row) == 6 else 'sha1'
         result = pbkdf2_hmac(digest, secret, salt, rounds, keylen)
         self.assertEqual(result, correct)
Exemplo n.º 7
0
 def _calc_checksum(self, secret):
     hash = pbkdf2_hmac(self._digest, secret, self.salt, self.rounds)
     return b64encode(hash).rstrip().decode('ascii')
Exemplo n.º 8
0
 def _calc_checksum(self, secret):
     return pbkdf2_hmac(self._digest, secret, self.salt, self.rounds,
                        self.checksum_size)
Exemplo n.º 9
0
 def _calc_checksum(self, secret):
     return pbkdf2_hmac('sha512', secret, self.salt, self.rounds, 64)
Exemplo n.º 10
0
 def _calc_checksum(self, secret):
     return pbkdf2_hmac('sha1', secret, self.salt, 10000, 32)
Exemplo n.º 11
0
 def _calc_checksum(self, secret):
     salt = self._get_config()
     result = pbkdf2_hmac('sha1', secret, salt, self.rounds, 24)
     return ab64_encode(result).decode('ascii')