예제 #1
0
 def test_decrypt(self):
     des = DES(b"PASSWORD")
     expected = b"abcdefgh"
     actual = des.decrypt(b"\x15\x14\x4f\x75\x8c\x83\xd0\x34")
     assert actual == expected
예제 #2
0
 def test_encrypt_block(self):
     with pytest.raises(ValueError) as exc:
         DES.key56_to_key64(b"\x00")
     assert str(exc.value) == \
         "DES 7-byte key is not 7 bytes in length, actual: 1"
예제 #3
0
 def test_encrypt_large_bytes_fail_no_padding(self):
     with pytest.raises(ValueError) as exc:
         des = DES(b"PASSWORD")
         des.encrypt(b"abcdefghijklmnopqrstuvwxyz", pad=False)
     assert str(exc.value) == "DES encryption must be a multiple of 8 bytes"
예제 #4
0
    def _calc_resp(password_hash, server_challenge):
        """
        Generate the LM response given a 16-byte password hash and the
        challenge from the CHALLENGE_MESSAGE

        :param password_hash: A 16-byte password hash
        :param server_challenge: A random 8-byte response generated by the
            server in the CHALLENGE_MESSAGE
        :return res: A 24-byte buffer to contain the LM response upon return
        """
        # padding with zeros to make the hash 21 bytes long
        password_hash += b'\x00' * (21 - len(password_hash))

        res = b''
        dobj = DES(DES.key56_to_key64(password_hash[0:7]))
        res = res + dobj.encrypt(server_challenge[0:8])

        dobj = DES(DES.key56_to_key64(password_hash[7:14]))
        res = res + dobj.encrypt(server_challenge[0:8])

        dobj = DES(DES.key56_to_key64(password_hash[14:21]))
        res = res + dobj.encrypt(server_challenge[0:8])
        return res