1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4from pyelliptic import Cipher, ECC
5from binascii import hexlify, unhexlify
6
7print("TEST: AES-256-CTR")
8ciphername = "aes-256-ctr"
9iv = unhexlify(b"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")
10key = unhexlify(b"603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4")
11plaintext = unhexlify(b"6bc1bee22e409f96e93d7e117393172a")
12
13ctx = Cipher(key, iv, 1, ciphername=ciphername)
14enc = ctx.ciphering(plaintext)
15print(hexlify(enc))
16
17ctx = Cipher(key, iv, 0, ciphername=ciphername)
18assert ctx.ciphering(enc) == plaintext
19
20
21print("\nTEST: AES-256-CFB")
22ciphername = "aes-256-cfb"
23key = unhexlify(b"603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4")
24iv = unhexlify(b"000102030405060708090A0B0C0D0E0F")
25plaintext = unhexlify(b"6bc1bee22e409f96e93d7e117393172a")
26
27ctx = Cipher(key, iv, 1, ciphername=ciphername)
28enc = ctx.ciphering(plaintext)
29print(hexlify(enc))
30
31ctx = Cipher(key, iv, 0, ciphername=ciphername)
32assert ctx.ciphering(enc) == plaintext
33
34
35print("\nTEST: AES-256-CBC")
36ciphername = "aes-256-cbc"
37iv = unhexlify(b"000102030405060708090A0B0C0D0E0F")
38key = unhexlify(b"603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4")
39plaintext = unhexlify(b"6bc1bee22e409f96e93d7e117393172a")
40
41ctx = Cipher(key, iv, 1, ciphername=ciphername)
42enc = ctx.ciphering(plaintext)
43print(hexlify(enc))
44
45ctx = Cipher(key, iv, 0, ciphername=ciphername)
46assert ctx.ciphering(enc) == plaintext
47
48
49print("\nTEST: ECIES")
50alice = ECC()
51plaintext = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
52ciphertext = ECC.encrypt(plaintext, alice.get_pubkey())
53print(hexlify(ciphertext))
54assert alice.decrypt(ciphertext) == plaintext
55
56
57print("\nTEST: ECIES/RC4")
58alice = ECC()
59plaintext = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
60ciphertext = ECC.encrypt(plaintext, alice.get_pubkey(), ciphername="rc4")
61print(hexlify(ciphertext))
62assert alice.decrypt(ciphertext, ciphername="rc4") == plaintext
63