コード例 #1
0
ファイル: test_crypto.py プロジェクト: zgreat/TumbleBit
    def test_chacha_256bit_key(self):
        msg2 = unhexlify("12345678901234567890123456")
        key2 = "z" * 32  # 256-bit key
        iv2 = "b" * 8
        ciphertext2 = chacha(key2, iv2, msg2)

        assert hexlify(ciphertext2) == b"5b7e78078d16c5efb7c46aa2a3"
        assert chacha(key2, iv2, ciphertext2) == msg2
コード例 #2
0
ファイル: test_crypto.py プロジェクト: zgreat/TumbleBit
    def test_chacha_128bit_key(self):
        msg1 = unhexlify("12345678901234567890123456")
        key1 = "x" * 16  # 128-bit key
        iv1 = "a" * 8
        ciphertext1 = chacha(key1, iv1, msg1)

        assert hexlify(ciphertext1) == b"f4d00b7237791f237a2ddebd20"
        assert chacha(key1, iv1, ciphertext1) == msg1
コード例 #3
0
    def decrypt(key, cipher):
        """Decrypts the msg using chacha20

        Args:
            key (str): A 16 byte key that will be used for decryption.
            cipher (str): A message to be decrypted

        Returns:
            str: The decrypted msg

        Raises:
            ValueError: If `key` is not 16 bytes
        """
        if len(key) != 16:
            raise ValueError('key must be 16 bytes')

        iv = cipher[:8]
        msg = chacha(key, iv, cipher[8:])
        return msg
コード例 #4
0
    def encrypt(key, msg):
        """Encrypts the msg using chacha20

        Args:
            key (bytes): A 16 byte key that will be used for encryption.
            msg (bytes): A message to be encrypted

        Returns:
            str: A string where the first 8 bytes represent the iv
                 used in the encryption process then followed by
                 the encrypted msg.

        Raises:
            ValueError: If `key` is not 16 bytes
        """
        if len(key) != 16:
            raise ValueError('key must be 16 bytes')

        iv = PuzzleSolver.compute_rand(64)  # 8 byte iv
        cipher = chacha(key, iv, msg)
        return iv + cipher
コード例 #5
0
ファイル: puzzle_solver.py プロジェクト: skbodwell/TumbleBit
 def decrypt(key, cipher):
     iv = cipher[:8]
     msg = chacha(key, iv, cipher[8:])
     return msg
コード例 #6
0
ファイル: puzzle_solver.py プロジェクト: skbodwell/TumbleBit
 def encrypt(key, msg):
     iv = Puzzle_Solver.compute_rand(64)  # 8 byte iv
     cipher = chacha(key, iv, msg)
     return iv + cipher