# Path: DPAPI/Core/crypto.py
# class CryptoAlgo(object):
#     class Algo(object):
#         def __init__(self, data):
#         def __getattr__(self, attr):
#     def add_algo(cls, algnum, **kargs):
#     def get_algo(cls, algnum):
#     def __init__(self, i):
#     def do_fixup_key(self, key):
#     def __repr__(self):
# def des_set_odd_parity(key):
# def CryptSessionKeyXP(masterkey, nonce, hashAlgo, entropy=None, strongPassword=None, verifBlob=None):
# def CryptSessionKeyWin7(masterkey, nonce, hashAlgo, entropy=None, strongPassword=None, verifBlob=None):
# def CryptDeriveKey(h, cipherAlgo, hashAlgo):
# def decrypt_lsa_key_nt5(lsakey, syskey):
# def decrypt_lsa_key_nt6(lsakey, syskey):
# def SystemFunction005(secret, key):
# def decrypt_lsa_secret(secret, lsa_keys):
# def pbkdf2(passphrase, salt, keylen, iterations, digest='sha1'):
# def derivePwdHash(pwdhash, userSID, digest='sha1'):
# def dataDecrypt(cipherAlgo, hashAlgo, raw, encKey, iv, rounds):
# def DPAPIHmac(hashAlgo, pwdhash, hmacSalt, value):
#         U = salt + struct.pack("!L", i)


import unittest
from DPAPI.Core import crypto

    def test_pbkdf2_5600round_sha512(self):
        # win7
        p = "84e40ab5bab2c5a2965fd185d60cf92fe2c1c9d2".decode("hex")
        s = "1f63ff38751365ec54748b13d962698e".decode("hex")
        i = 5600
        r = ("38d34e6a81f8d5f650403d01407e3127"
             "f987f986328ed9c1aacd527811dd53ac"
             "5a7b8d298e37e377daa03a3ee209e638").decode("hex")
        self.assertEquals(crypto.pbkdf2(p, s, len(r), i, 'sha512'), r)

    def test_derivePwdHash(self):
        self.assertEquals(crypto.derivePwdHash(self.hashpwd, self.sid), self.expected)

    def test_dataDecrypt_aes256_sha512(self):
        r = ("ac23e4d5efcb8979f05fbcb275832a8d"
             "ee9576fbaae76a4de7ead2f313e84bf7"
             "e4be7940b49319463c8cd25a1b4a67c1"
             "5adfbb02e2bbe42c24cd44bec3b9740b"
             "45ebcce3a2ef2788867c28168bf93ea0"
             "48844897f2854df5ac4eb000f72c3a6f"
             "25c65d5347e73c77120cfc3150c87e57"
             "52a017510c1486e71a9d0c32b79f333f"
             "2d0cda0ecc20774cbed8ca071aab9768").decode("hex")
        e = "84e40ab5bab2c5a2965fd185d60cf92fe2c1c9d2".decode("hex")
        iv = "1f63ff38751365ec54748b13d962698e".decode("hex")
        c = ("d23ad4bb1e254c67e2ff2902de8683b3"
             "ca5dc108b821333e2d5059ac6f26db1a"
             "7826abdc93feadcf76aa4db9c0ce32ed"
             "0b261f95f6960a81195231b91a9dd20b"

# Path: DPAPI/Core/crypto.py
# class CryptoAlgo(object):
#     class Algo(object):
#         def __init__(self, data):
#         def __getattr__(self, attr):
#     def add_algo(cls, algnum, **kargs):
#     def get_algo(cls, algnum):
#     def __init__(self, i):
#     def do_fixup_key(self, key):
#     def __repr__(self):
# def des_set_odd_parity(key):
# def CryptSessionKeyXP(masterkey, nonce, hashAlgo, entropy=None, strongPassword=None, verifBlob=None):
# def CryptSessionKeyWin7(masterkey, nonce, hashAlgo, entropy=None, strongPassword=None, verifBlob=None):
# def CryptDeriveKey(h, cipherAlgo, hashAlgo):
# def decrypt_lsa_key_nt5(lsakey, syskey):
# def decrypt_lsa_key_nt6(lsakey, syskey):
# def SystemFunction005(secret, key):
# def decrypt_lsa_secret(secret, lsa_keys):
# def pbkdf2(passphrase, salt, keylen, iterations, digest='sha1'):
# def derivePwdHash(pwdhash, userSID, digest='sha1'):
# def dataDecrypt(cipherAlgo, hashAlgo, raw, encKey, iv, rounds):
# def DPAPIHmac(hashAlgo, pwdhash, hmacSalt, value):
#         U = salt + struct.pack("!L", i)


# Path: tests/crypto.py
import unittest
from DPAPI.Core import crypto


    def test_pbkdf2_5600round_sha512(self):
        # win7
        p = "84e40ab5bab2c5a2965fd185d60cf92fe2c1c9d2".decode("hex")
        s = "1f63ff38751365ec54748b13d962698e".decode("hex")
        i = 5600
        r = ("38d34e6a81f8d5f650403d01407e3127"
             "f987f986328ed9c1aacd527811dd53ac"
             "5a7b8d298e37e377daa03a3ee209e638").decode("hex")
        self.assertEquals(crypto.pbkdf2(p, s, len(r), i, 'sha512'), r)

    def test_derivePwdHash(self):
        self.assertEquals(crypto.derivePwdHash(self.hashpwd, self.sid), self.expected)

    def test_dataDecrypt_aes256_sha512(self):
        r = ("ac23e4d5efcb8979f05fbcb275832a8d"
             "ee9576fbaae76a4de7ead2f313e84bf7"
             "e4be7940b49319463c8cd25a1b4a67c1"
             "5adfbb02e2bbe42c24cd44bec3b9740b"
             "45ebcce3a2ef2788867c28168bf93ea0"
             "48844897f2854df5ac4eb000f72c3a6f"
             "25c65d5347e73c77120cfc3150c87e57"
             "52a017510c1486e71a9d0c32b79f333f"
             "2d0cda0ecc20774cbed8ca071aab9768").decode("hex")
        e = "84e40ab5bab2c5a2965fd185d60cf92fe2c1c9d2".decode("hex")
        iv = "1f63ff38751365ec54748b13d962698e".decode("hex")
        c = ("d23ad4bb1e254c67e2ff2902de8683b3"
             "ca5dc108b821333e2d5059ac6f26db1a"
             "7826abdc93feadcf76aa4db9c0ce32ed"
             "0b261f95f6960a81195231b91a9dd20b"

             "d6a6c5fb8aa6a008b11992d5c191d0b0"