#!/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 # # ============================================================================= # # The MIT License (MIT) # # Copyright 2015 Camil Staps (info@camilstaps.nl) # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from pypride import Pride import time import binascii def test(): 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 _ in range(100): for v_i, vector in enumerate(test_vectors): key = binascii.unhexlify(vector['key']) start = time.time() cipher = Pride(key) time_cipher += time.time() - start plaintext = binascii.unhexlify(vector['plaintext']) start = time.time() encryption = cipher.encrypt(plaintext) time_encrypt += time.time() - start ciphertext = binascii.unhexlify(vector['ciphertext']) start = time.time() decryption = cipher.decrypt(ciphertext) time_decrypt += time.time() - start if encryption != binascii.unhexlify(vector['ciphertext']): print('Encryption for vector ' + str(v_i) + ' failed: was ' + str(binascii.hexlify(encryption)) + '; should have been ' + vector['ciphertext']) all_passed = False if decryption != binascii.unhexlify(vector['plaintext']): print('Decryption for vector ' + str(v_i) + ' failed: was ' + str(binascii.hexlify(decryption)) + '; 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') import profile profile.run('test()')