# 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

class CryptoTest(unittest.TestCase):
    def setUp(self):
        self.pwd = "tutu"
        self.sid = "S-1-5-21-583907252-1547161642-682003330-1001"
        self.expected = "732f73394364c930ba285063e5ff1ae49ebb3332".decode("hex")
        self.hashpwd = "8fd090d6121b0f67ebb58bce562bf02b3f1e6bb4".decode("hex")

    def test_CryptSessionKeyXP(self):
        m = ("f1cd9c3915428d12c0e9bf5ac0c44dda"
             "647e6e387118c09eb00a294e485a3f6e"
             "fe47f16686ad5f60fbd740164de87711"
             "6eb70d35445b22ddebdb02b0d55ee613").decode("hex")
        n = "55d9d46709e463db53c783ec1edd69dc".decode("hex")
        h = crypto.CryptoAlgo(0x8004)
        r = "397ec5c4dc5d5733b7dadd94178f827951b5ea66".decode("hex")

        self.assertEquals(crypto.CryptSessionKeyXP(m, n, h), r)
        self.assertEquals(crypto.CryptSessionKeyWin7(m, n, h), r)

    def test_CryptSessionKeyXPEntropy(self):
        m = ("d0c624a61e4080ac28ec07f33466581e"
             "c04980f26953aa940258dc4ced7fd545"
             "251208d88d6bac5c64b5cd69b4e21400"
             "93174f51ab07f0f5fb7a45462a2c00e4").decode("hex")
        n = "0c1e54f10d3ac713ef4c19dbc440e4a7".decode("hex")
        h = crypto.CryptoAlgo(0x8004)
        e = "746f746f313233".decode("hex")
        r = "9e0ee9a096bcd43c315a211dc7fdb1fd1a01cbec".decode("hex")


# 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


class CryptoTest(unittest.TestCase):
    def setUp(self):
        self.pwd = "tutu"
        self.sid = "S-1-5-21-583907252-1547161642-682003330-1001"
        self.expected = "732f73394364c930ba285063e5ff1ae49ebb3332".decode("hex")
        self.hashpwd = "8fd090d6121b0f67ebb58bce562bf02b3f1e6bb4".decode("hex")

    def test_CryptSessionKeyXP(self):
        m = ("f1cd9c3915428d12c0e9bf5ac0c44dda"
             "647e6e387118c09eb00a294e485a3f6e"
             "fe47f16686ad5f60fbd740164de87711"
             "6eb70d35445b22ddebdb02b0d55ee613").decode("hex")
        n = "55d9d46709e463db53c783ec1edd69dc".decode("hex")
        h = crypto.CryptoAlgo(0x8004)
        r = "397ec5c4dc5d5733b7dadd94178f827951b5ea66".decode("hex")

        self.assertEquals(crypto.CryptSessionKeyXP(m, n, h), r)
        self.assertEquals(crypto.CryptSessionKeyWin7(m, n, h), r)

    def test_CryptSessionKeyXPEntropy(self):
        m = ("d0c624a61e4080ac28ec07f33466581e"
             "c04980f26953aa940258dc4ced7fd545"
             "251208d88d6bac5c64b5cd69b4e21400"
             "93174f51ab07f0f5fb7a45462a2c00e4").decode("hex")
        n = "0c1e54f10d3ac713ef4c19dbc440e4a7".decode("hex")
        h = crypto.CryptoAlgo(0x8004)
        e = "746f746f313233".decode("hex")
        r = "9e0ee9a096bcd43c315a211dc7fdb1fd1a01cbec".decode("hex")


        self.assertEquals(crypto.CryptSessionKeyXP(m, n, h, e), r)