Пример #1
0
    def _openssl_kdf(cls, algo, pwd, salt, key_size, iv_size):


        print('PWD=' + binascii.hexlify(pwd).decode('ascii').upper())

        if algo == 'md5':
            temp = pbkdf1(pwd, salt, 1, 16, 'md5')
        else:
            temp = b''

        print('FD=' + binascii.hexlify(temp).decode('ascii').upper())

        fd = temp
        while len(fd) < key_size + iv_size:
            temp = cls._hasher(algo, temp + pwd + salt)
            fd += temp

        key = fd[0:key_size]
        iv = fd[key_size:key_size+iv_size]

        print('salt=' + binascii.hexlify(salt).decode('ascii').upper())
        print('key=' + binascii.hexlify(key).decode('ascii').upper())
        print('iv=' + binascii.hexlify(iv).decode('ascii').upper())

        return key, iv
Пример #2
0
    def test_known(self):
        "test reference vectors"
        from passlib.utils.pbkdf2 import pbkdf1

        for secret, salt, rounds, keylen, digest, correct in self.pbkdf1_tests:
            result = pbkdf1(secret, salt, rounds, keylen, digest)
            self.assertEqual(result, correct)
Пример #3
0
 def test_pbkdf1(self):
     "test pbkdf1"
     for secret, salt, rounds, klen, hash, correct in [
             #http://www.di-mgt.com.au/cryptoKDFs.html
         (b('password'), hb('78578E5A5D63CB06'), 1000, 16, 'sha1',
          hb('dc19847e05c64d2faf10ebfb4a3d2a20')),
     ]:
         result = pbkdf2.pbkdf1(secret, salt, rounds, klen, hash)
         self.assertEqual(result, correct)
Пример #4
0
 def test_pbkdf1(self):
     "test pbkdf1"
     for secret, salt, rounds, klen, hash, correct in [
         #http://www.di-mgt.com.au/cryptoKDFs.html
         (b('password'), hb('78578E5A5D63CB06'), 1000, 16, 'sha1',
             hb('dc19847e05c64d2faf10ebfb4a3d2a20')),
     ]:
         result = pbkdf2.pbkdf1(secret, salt, rounds, klen, hash)
         self.assertEqual(result, correct)
Пример #5
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     # NOTE: for some reason, FSHP uses pbkdf1 with password & salt reversed.
     #       this has only a minimal impact on security,
     #       but it is worth noting this deviation.
     return pbkdf1(
         secret=self.salt, salt=secret, rounds=self.rounds, keylen=self.checksum_size, hash=self.checksum_alg
     )
Пример #6
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     # NOTE: for some reason, FSHP uses pbkdf1 with password & salt reversed.
     #       this has only a minimal impact on security,
     #       but it is worth noting this deviation.
     return pbkdf1(
         secret=self.salt,
         salt=secret,
         rounds=self.rounds,
         keylen=self.checksum_size,
         hash=self.checksum_alg,
     )
Пример #7
0
def _openssl_kdf(algo, pwd, salt, key_size, iv_size):
    if algo == 'md5':
        temp = pbkdf1(pwd, salt, 1, 16, 'md5')
    else:
        temp = b''

    fd = temp
    while len(fd) < key_size + iv_size:
        temp = _hasher(algo, temp + pwd + salt)
        fd += temp

    key = fd[0:key_size]
    iv = fd[key_size:key_size+iv_size]

    return key, iv
Пример #8
0
def openssl_kdf(algo, pwd, salt, key_size, iv_size):
    if algo == 'md5':
        temp = pbkdf1(pwd, salt, 1, 16, 'md5')
    else:
        temp = b''

    fd = temp

    while len(fd) < key_size + iv_size:
        con = temp + pwd + salt
        temp = hasher(algo, con)
        print('temp:' + binascii.hexlify(temp).decode('ascii').upper())
        print('con :' + con)
        fd += temp

    key = fd[0:key_size]
    iv = fd[key_size:key_size + iv_size]

    print('salt=' + binascii.hexlify(salt).decode('ascii').upper())
    print('key=' + binascii.hexlify(key).decode('ascii').upper())
    print('iv=' + binascii.hexlify(iv).decode('ascii').upper())

    return key, iv
Пример #9
0
 def helper(secret=b("secret"), salt=b("salt"), rounds=1, keylen=1, hash="md5"):
     return pbkdf1(secret, salt, rounds, keylen, hash)
Пример #10
0
 def helper(secret=b'secret', salt=b'salt', rounds=1, keylen=1, hash='md5'):
     return pbkdf1(secret, salt, rounds, keylen, hash)
Пример #11
0
 def test_known(self):
     """test reference vectors"""
     from passlib.utils.pbkdf2 import pbkdf1
     for secret, salt, rounds, keylen, digest, correct in self.pbkdf1_tests:
         result = pbkdf1(secret, salt, rounds, keylen, digest)
         self.assertEqual(result, correct)
Пример #12
0
 def helper(secret=b'secret', salt=b'salt', rounds=1, keylen=1, hash='md5'):
     return pbkdf1(secret, salt, rounds, keylen, hash)