|
97 | 97 | cipher.decrypt_into(cyphertext[i : i + 16], output)
|
98 | 98 | print(str(hexlify(output), ""))
|
99 | 99 | print()
|
| 100 | + |
| 101 | +print("truncated-CTR-1") |
| 102 | +## Truncated CTR test case |
| 103 | +plaintext = unhexlify("6bc1bee22e409f96e93d7e117393172a" "ae2d") |
| 104 | + |
| 105 | +key = unhexlify("2b7e151628aed2a6abf7158809cf4f3c") |
| 106 | +counter = unhexlify("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff") |
| 107 | +cyphertext = bytearray(len(plaintext)) |
| 108 | +cipher = aesio.AES(key, aesio.MODE_CTR, IV=counter) |
| 109 | +for i in range(0, len(plaintext), 16): |
| 110 | + output = memoryview(cyphertext)[i : i + 16] |
| 111 | + cipher.encrypt_into(plaintext[i : i + 16], output) |
| 112 | + print(str(hexlify(output), "")) |
| 113 | +print() |
| 114 | + |
| 115 | +plaintext = bytearray(len(plaintext)) |
| 116 | +cipher = aesio.AES(key, aesio.MODE_CTR, IV=counter) |
| 117 | +for i in range(0, len(plaintext), 16): |
| 118 | + output = memoryview(plaintext)[i : i + 16] |
| 119 | + cipher.decrypt_into(cyphertext[i : i + 16], output) |
| 120 | + print(str(hexlify(output), "")) |
| 121 | +print() |
| 122 | + |
| 123 | +print("truncated-CTR-2") |
| 124 | +## Truncated CTR test case #2 |
| 125 | +plaintext = unhexlify("6bc1bee22e409f96e93d7e117393172a" "ae") |
| 126 | + |
| 127 | +key = unhexlify("2b7e151628aed2a6abf7158809cf4f3c") |
| 128 | +counter = unhexlify("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff") |
| 129 | +cyphertext = bytearray(len(plaintext)) |
| 130 | +cipher = aesio.AES(key, aesio.MODE_CTR, IV=counter) |
| 131 | +cipher.encrypt_into(plaintext, cyphertext) |
| 132 | +for i in range(0, len(plaintext), 16): |
| 133 | + output = memoryview(cyphertext)[i : i + 16] |
| 134 | + print(str(hexlify(output), "")) |
| 135 | +print() |
| 136 | + |
| 137 | +plaintext = bytearray(len(plaintext)) |
| 138 | +cipher = aesio.AES(key, aesio.MODE_CTR, IV=counter) |
| 139 | +cipher.decrypt_into(cyphertext, plaintext) |
| 140 | +for i in range(0, len(plaintext), 16): |
| 141 | + output = memoryview(plaintext)[i : i + 16] |
| 142 | + print(str(hexlify(output), "")) |
| 143 | +print() |
0 commit comments