1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/usr/bin/python
# coding=utf8
# =============================================================================
# Python PRIDE implementation test vectors
# Version: 1.0
# Date: 23/04/2015
#
# =============================================================================
#
# Python implementation of the PRIDE cipher; test vectors
# Copyright (C) 2015 Camil Staps (info@camilstaps.nl)
#
# =============================================================================
#
# These are the test vectors from appendix J of Block Ciphers -- Focus On The
# Linear Layer (feat. PRIDE); Martin R. Albrecht, Benedikt Driessen, Elif Bilge
# Kavun, Gregor Leander, Christof Paar, Tolga Yalçın:
# https://eprint.iacr.org/2014/453
#
# =============================================================================
from pypride import Pride
import time
test_vectors = [
{'key': "00000000000000000000000000000000", 'plaintext': "0000000000000000", 'ciphertext': "82b4109fcc70bd1f"},
{'key': "00000000000000000000000000000000", 'plaintext': "ffffffffffffffff", 'ciphertext': "d70e60680a17b956"},
{'key': "ffffffffffffffff0000000000000000", 'plaintext': "0000000000000000", 'ciphertext': "28f19f97f5e846a9"},
{'key': "0000000000000000ffffffffffffffff", 'plaintext': "0000000000000000", 'ciphertext': "d123ebaf368fce62"},
{'key': "0000000000000000fedcba9876543210", 'plaintext': "0123456789abcdef", 'ciphertext': "d1372929712d336e"}
]
time_cipher = 0
time_encrypt = 0
time_decrypt = 0
all_passed = True
for v_i, vector in enumerate(test_vectors):
key = vector['key'].decode('hex')
start = time.time()
cipher = Pride(key)
time_cipher += time.time() - start
plaintext = vector['plaintext'].decode('hex')
start = time.time()
encryption = cipher.encrypt(plaintext)
time_encrypt += time.time() - start
ciphertext = vector['ciphertext'].decode('hex')
start = time.time()
decryption = cipher.decrypt(ciphertext)
time_decrypt += time.time() - start
if encryption != vector['ciphertext'].decode('hex'):
print "Encryption for vector", v_i, "failed: was", encryption.encode('hex'), "; should have been", vector['ciphertext']
all_passed = False
if decryption != vector['plaintext'].decode('hex'):
print "Decryption for vector", v_i, "failed: was", decryption.encode('hex'), "; should have been", vector['plaintext']
all_passed = False
if all_passed:
print "All tests passed."
print "Generating round keys:", str(time_cipher) + "s"
print "Encryption: ", str(time_encrypt) + "s"
print "Decryption: ", str(time_decrypt) + "s"
|