Exemplo n.º 1
0
 def test_aead_chacha20poly1305_detached(self):
     if not pysodium.sodium_version_check(1, 0, 9): return
     key = binascii.unhexlify(b"4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd1100a1007")
     input_ = binascii.unhexlify(b"86d09974840bded2a5ca")
     nonce = binascii.unhexlify(b"cd7cf67be39c794a")
     ad = binascii.unhexlify(b"87e229d4500845a079c0")
     output, mac = pysodium.crypto_aead_chacha20poly1305_encrypt_detached(input_, ad, nonce, key)
     self.assertEqual(binascii.unhexlify(b"e3e446f7ede9a19b62a4"), output)
     self.assertEqual(binascii.unhexlify(b"677dabf4e3d24b876bb284753896e1d6"), mac)
     output = pysodium.crypto_aead_chacha20poly1305_decrypt_detached(output, mac, ad, nonce, key)
     self.assertEqual(output, input_)
Exemplo n.º 2
0
 def test_aead_chacha20poly1305_detached(self):
     if not pysodium.sodium_version_check(1, 0, 9): return
     key = binascii.unhexlify(b"4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd1100a1007")
     input_ = binascii.unhexlify(b"86d09974840bded2a5ca")
     nonce = binascii.unhexlify(b"cd7cf67be39c794a")
     for ad, ct in [
             (binascii.unhexlify(b"87e229d4500845a079c0"), b"677dabf4e3d24b876bb284753896e1d6"),
             (None,                                        b"69e7789bcd954e658ed38423e23161dc"),
     ]:
         output, mac = pysodium.crypto_aead_chacha20poly1305_encrypt_detached(input_, ad, nonce, key)
         self.assertEqual(binascii.unhexlify(b"e3e446f7ede9a19b62a4"), output)
         self.assertEqual(binascii.unhexlify(ct), mac)
         output = pysodium.crypto_aead_chacha20poly1305_decrypt_detached(output, mac, ad, nonce, key)
         self.assertEqual(output, input_)