def testFFXEncrypt1(self): radix = 2 K = FFXInteger('0' * 8, radix=radix, blocksize=128) T = FFXInteger('0' * 8, radix=radix, blocksize=8) M1 = FFXInteger('0' * 8, radix=radix, blocksize=8) ffx = FFX.new(K.to_bytes(16), radix) C = ffx.encrypt(T, M1) M2 = ffx.decrypt(T, C) self.assertEquals(M1, M2)
def main(): parser = argparse.ArgumentParser() parser.add_argument("--radix", type=int, default=2) parser.add_argument("--tweaksize", type=int, default=8) parser.add_argument("--messagesize", type=int, default=32) parser.add_argument("--trials", type=int, default=10, required=False) args = parser.parse_args() radix = args.radix tweaksize = args.tweaksize messagesize = args.messagesize trials = args.trials keysize = 128 K = random.randint(0, 2 ** keysize - 1) K = FFXInteger(K, radix=2, blocksize=keysize) banner = ['RADIX=' + str(radix), 'TWEAKSIZE=' + str(tweaksize), 'MESSAGESIZE=' + str(messagesize), 'KEY=' + hex(K.to_int()) ] print ', '.join(banner) ffx = FFX.new(K.to_bytes(), radix) for i in range(1, trials): T = random.randint(0, radix ** tweaksize - 1) T = FFXInteger(T, radix=radix, blocksize=tweaksize) M1 = random.randint(0, radix ** messagesize - 1) M1 = FFXInteger(M1, radix=radix, blocksize=messagesize) start = time.time() C = ffx.encrypt(T, M1) encrypt_cost = time.time() - start encrypt_cost *= 1000.0 start = time.time() M2 = ffx.decrypt(T, C) decrypt_cost = time.time() - start decrypt_cost *= 1000.0 assert M1 == M2 to_print = ['encrypt_cost=' + str(round(encrypt_cost, 1)) + 'ms', 'decrypt_cost=' + str(round(decrypt_cost, 1)) + 'ms', 'tweak=' + str(T), 'plaintext=' + str(M1), 'ciphertext=' + str(C), ] print 'test #' + string.rjust(str(i), len(str(trials - 1)), '0') + ' SUCCESS: (' + ', '.join(to_print) + ')'
def testVector2(self): # see aes-ffx-vectors.txt radix = 10 K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c', radix=16, blocksize=32) T = 0 # FFXInteger(0, radix=radix, blocksize=2) M1 = FFXInteger('0123456789', radix=radix, blocksize=10) ffx = FFX.new(K.to_bytes(16), radix) C = ffx.encrypt(T, M1) self.assertEquals(C, '2433477484') M2 = ffx.decrypt(T, C) self.assertEquals(M1, M2) print '' print 'TEST VECTOR #2: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C)
def testVector5(self): # see aes-ffx-vectors.txt radix = 36 K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c', radix=16, blocksize=32) T = FFXInteger('TQF9J5QDAGSCSPB1', radix=radix, blocksize=16) M1 = FFXInteger('C4XPWULBM3M863JH', radix=radix, blocksize=16) ffx = FFX.new(K.to_bytes(16), radix) C = ffx.encrypt(T, M1) self.assertEquals(str(C).upper(), 'C8AQ3U846ZWH6QZP') M2 = ffx.decrypt(T, C) self.assertEquals(M1, M2) print '' print 'TEST VECTOR #5: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C)
def testVector4(self): # see aes-ffx-vectors.txt radix = 10 K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c', radix=16, blocksize=32) T = FFXInteger('7777777', radix=radix, blocksize=7) M1 = FFXInteger('999999999', radix=radix, blocksize=9) ffx = FFX.new(K.to_bytes(16), radix) C = ffx.encrypt(T, M1) self.assertEquals(C, '658229573') M2 = ffx.decrypt(T, C) self.assertEquals(M1, M2) print '' print 'TEST VECTOR #4: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C)
def testVector3(self): # see aes-ffx-vectors.txt radix = 10 K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c', radix=16, blocksize=32) T = FFXInteger('2718281828', radix=radix, blocksize=10) M1 = FFXInteger('314159', radix=radix, blocksize=6) ffx = FFX.new(K.to_bytes(16), radix) C = ffx.encrypt(T, M1) self.assertEquals(C, '535005') M2 = ffx.decrypt(T, C) self.assertEquals(M1, M2) print '' print 'TEST VECTOR #3: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C)
def testVector2(self): # see aes-ffx-vectors.txt radix = 10 K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c', radix=16, blocksize=32) T = 0 # FFXInteger(0, radix=radix, blocksize=2) M1 = FFXInteger('0123456789', radix=radix, blocksize=10) ffx = FFX.new(K.to_bytes(16), radix) C = ffx.encrypt(T, M1) self.assertEquals(C, '2433477484') M2 = ffx.decrypt(T, C) self.assertEquals(M1, M2) print '' print 'TEST VECTOR #2: radix=' + str(radix) + ', input=' + str( M1) + ', tweak=' + str(T) + ', encrypted=' + str(C)
def testVector5(self): # see aes-ffx-vectors.txt radix = 36 K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c', radix=16, blocksize=32) T = FFXInteger('TQF9J5QDAGSCSPB1', radix=radix, blocksize=16) M1 = FFXInteger('C4XPWULBM3M863JH', radix=radix, blocksize=16) ffx = FFX.new(K.to_bytes(16), radix) C = ffx.encrypt(T, M1) self.assertEquals(str(C).upper(), 'C8AQ3U846ZWH6QZP') M2 = ffx.decrypt(T, C) self.assertEquals(M1, M2) print '' print 'TEST VECTOR #5: radix=' + str(radix) + ', input=' + str( M1) + ', tweak=' + str(T) + ', encrypted=' + str(C)
def testVector4(self): # see aes-ffx-vectors.txt radix = 10 K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c', radix=16, blocksize=32) T = FFXInteger('7777777', radix=radix, blocksize=7) M1 = FFXInteger('999999999', radix=radix, blocksize=9) ffx = FFX.new(K.to_bytes(16), radix) C = ffx.encrypt(T, M1) self.assertEquals(C, '658229573') M2 = ffx.decrypt(T, C) self.assertEquals(M1, M2) print '' print 'TEST VECTOR #4: radix=' + str(radix) + ', input=' + str( M1) + ', tweak=' + str(T) + ', encrypted=' + str(C)
def testVector3(self): # see aes-ffx-vectors.txt radix = 10 K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c', radix=16, blocksize=32) T = FFXInteger('2718281828', radix=radix, blocksize=10) M1 = FFXInteger('314159', radix=radix, blocksize=6) ffx = FFX.new(K.to_bytes(16), radix) C = ffx.encrypt(T, M1) self.assertEquals(C, '535005') M2 = ffx.decrypt(T, C) self.assertEquals(M1, M2) print '' print 'TEST VECTOR #3: radix=' + str(radix) + ', input=' + str( M1) + ', tweak=' + str(T) + ', encrypted=' + str(C)
#!/usr/bin/env python # -*- coding: utf-8 -*- import FFX radix = 2 blocksize = 2 ** 10 ffx = FFX.new(radix=radix) K = FFX.FFXInteger('0' * 128, radix=radix, blocksize=128) T = FFX.FFXInteger('0' * blocksize, radix=radix, blocksize=blocksize) X = FFX.FFXInteger('0' * blocksize, radix=radix, blocksize=blocksize) C = ffx.encrypt(K, T, X) Y = ffx.decrypt(K, T, C) print X print C print Y
#!/usr/bin/env python # -*- coding: utf-8 -*- import FFX radix = 2 blocksize = 2**10 ffx = FFX.new(radix=radix) K = FFX.FFXInteger('0' * 128, radix=radix, blocksize=128) T = FFX.FFXInteger('0' * blocksize, radix=radix, blocksize=blocksize) X = FFX.FFXInteger('0' * blocksize, radix=radix, blocksize=blocksize) C = ffx.encrypt(K, T, X) Y = ffx.decrypt(K, T, C) print X print C print Y