1#!/usr/local/bin/python2
2#
3# Copyright (c) 2014 The FreeBSD Foundation
4# Copyright 2014 John-Mark Gurney
5# All rights reserved.
6#
7# This software was developed by John-Mark Gurney under
8# the sponsorship from the FreeBSD Foundation.
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1.  Redistributions of source code must retain the above copyright
13#     notice, this list of conditions and the following disclaimer.
14# 2.  Redistributions in binary form must reproduce the above copyright
15#     notice, this list of conditions and the following disclaimer in the
16#     documentation and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28# SUCH DAMAGE.
29#
30# $FreeBSD$
31#
32
33from __future__ import print_function
34import array
35import dpkt
36from fcntl import ioctl
37import os
38import signal
39from struct import pack as _pack
40
41from cryptodevh import *
42
43__all__ = [ 'Crypto', 'MismatchError', ]
44
45class FindOp(dpkt.Packet):
46	__byte_order__ = '@'
47	__hdr__ = ( ('crid', 'i', 0),
48		('name', '32s', 0),
49	)
50
51class SessionOp(dpkt.Packet):
52	__byte_order__ = '@'
53	__hdr__ = ( ('cipher', 'I', 0),
54		('mac', 'I', 0),
55		('keylen', 'I', 0),
56		('key', 'P', 0),
57		('mackeylen', 'i', 0),
58		('mackey', 'P', 0),
59		('ses', 'I', 0),
60	)
61
62class SessionOp2(dpkt.Packet):
63	__byte_order__ = '@'
64	__hdr__ = ( ('cipher', 'I', 0),
65		('mac', 'I', 0),
66		('keylen', 'I', 0),
67		('key', 'P', 0),
68		('mackeylen', 'i', 0),
69		('mackey', 'P', 0),
70		('ses', 'I', 0),
71		('crid', 'i', 0),
72		('pad0', 'i', 0),
73		('pad1', 'i', 0),
74		('pad2', 'i', 0),
75		('pad3', 'i', 0),
76	)
77
78class CryptOp(dpkt.Packet):
79	__byte_order__ = '@'
80	__hdr__ = ( ('ses', 'I', 0),
81		('op', 'H', 0),
82		('flags', 'H', 0),
83		('len', 'I', 0),
84		('src', 'P', 0),
85		('dst', 'P', 0),
86		('mac', 'P', 0),
87		('iv', 'P', 0),
88	)
89
90class CryptAEAD(dpkt.Packet):
91	__byte_order__ = '@'
92	__hdr__ = (
93		('ses',		'I', 0),
94		('op',		'H', 0),
95		('flags',	'H', 0),
96		('len',		'I', 0),
97		('aadlen',	'I', 0),
98		('ivlen',	'I', 0),
99		('src',		'P', 0),
100		('dst',		'P', 0),
101		('aad',		'P', 0),
102		('tag',		'P', 0),
103		('iv',		'P', 0),
104	)
105
106# h2py.py can't handle multiarg macros
107CRIOGET = 3221513060
108CIOCGSESSION = 3224396645
109CIOCGSESSION2 = 3225445226
110CIOCFSESSION = 2147771238
111CIOCCRYPT = 3224396647
112CIOCKEY = 3230688104
113CIOCASYMFEAT = 1074029417
114CIOCKEY2 = 3230688107
115CIOCFINDDEV = 3223610220
116CIOCCRYPTAEAD = 3225445229
117
118def _getdev():
119	fd = os.open('/dev/crypto', os.O_RDWR)
120	buf = array.array('I', [0])
121	ioctl(fd, CRIOGET, buf, 1)
122	os.close(fd)
123
124	return buf[0]
125
126_cryptodev = _getdev()
127
128def _findop(crid, name):
129	fop = FindOp()
130	fop.crid = crid
131	fop.name = name
132	s = array.array('B', fop.pack_hdr())
133	ioctl(_cryptodev, CIOCFINDDEV, s, 1)
134	fop.unpack(s)
135
136	try:
137		idx = fop.name.index('\x00')
138		name = fop.name[:idx]
139	except ValueError:
140		name = fop.name
141
142	return fop.crid, name
143
144class Crypto:
145	@staticmethod
146	def findcrid(name):
147		return _findop(-1, name)[0]
148
149	@staticmethod
150	def getcridname(crid):
151		return _findop(crid, '')[1]
152
153	def __init__(self, cipher=0, key=None, mac=0, mackey=None,
154	    crid=CRYPTOCAP_F_SOFTWARE | CRYPTOCAP_F_HARDWARE, maclen=None):
155		self._ses = None
156		self._maclen = maclen
157		ses = SessionOp2()
158		ses.cipher = cipher
159		ses.mac = mac
160
161		if key is not None:
162			ses.keylen = len(key)
163			k = array.array('B', key)
164			ses.key = k.buffer_info()[0]
165		else:
166			self.key = None
167
168		if mackey is not None:
169			ses.mackeylen = len(mackey)
170			mk = array.array('B', mackey)
171			ses.mackey = mk.buffer_info()[0]
172
173		if not cipher and not mac:
174			raise ValueError('one of cipher or mac MUST be specified.')
175		ses.crid = crid
176		#print(ses)
177		s = array.array('B', ses.pack_hdr())
178		#print(s)
179		ioctl(_cryptodev, CIOCGSESSION2, s, 1)
180		ses.unpack(s)
181
182		self._ses = ses.ses
183
184	def __del__(self):
185		if self._ses is None:
186			return
187
188		try:
189			ioctl(_cryptodev, CIOCFSESSION, _pack('I', self._ses))
190		except TypeError:
191			pass
192		self._ses = None
193
194	def _doop(self, op, src, iv):
195		cop = CryptOp()
196		cop.ses = self._ses
197		cop.op = op
198		cop.flags = 0
199		cop.len = len(src)
200		s = array.array('B', src)
201		cop.src = cop.dst = s.buffer_info()[0]
202		if self._maclen is not None:
203			m = array.array('B', [0] * self._maclen)
204			cop.mac = m.buffer_info()[0]
205		ivbuf = array.array('B', iv)
206		cop.iv = ivbuf.buffer_info()[0]
207
208		#print('cop:', cop)
209		ioctl(_cryptodev, CIOCCRYPT, str(cop))
210
211		s = s.tostring()
212		if self._maclen is not None:
213			return s, m.tostring()
214
215		return s
216
217	def _doaead(self, op, src, aad, iv, tag=None):
218		caead = CryptAEAD()
219		caead.ses = self._ses
220		caead.op = op
221		caead.flags = CRD_F_IV_EXPLICIT
222		caead.flags = 0
223		caead.len = len(src)
224		s = array.array('B', src)
225		caead.src = caead.dst = s.buffer_info()[0]
226		caead.aadlen = len(aad)
227		saad = array.array('B', aad)
228		caead.aad = saad.buffer_info()[0]
229
230		if self._maclen is None:
231			raise ValueError('must have a tag length')
232
233		if tag is None:
234			tag = array.array('B', [0] * self._maclen)
235		else:
236			assert len(tag) == self._maclen, \
237                '%d != %d' % (len(tag), self._maclen)
238			tag = array.array('B', tag)
239
240		caead.tag = tag.buffer_info()[0]
241
242		ivbuf = array.array('B', iv)
243		caead.ivlen = len(iv)
244		caead.iv = ivbuf.buffer_info()[0]
245
246		ioctl(_cryptodev, CIOCCRYPTAEAD, str(caead))
247
248		s = s.tostring()
249
250		return s, tag.tostring()
251
252	def perftest(self, op, size, timeo=3):
253		import random
254		import time
255
256		inp = array.array('B', (random.randint(0, 255) for x in xrange(size)))
257		out = array.array('B', inp)
258
259		# prep ioctl
260		cop = CryptOp()
261		cop.ses = self._ses
262		cop.op = op
263		cop.flags = 0
264		cop.len = len(inp)
265		s = array.array('B', inp)
266		cop.src = s.buffer_info()[0]
267		cop.dst = out.buffer_info()[0]
268		if self._maclen is not None:
269			m = array.array('B', [0] * self._maclen)
270			cop.mac = m.buffer_info()[0]
271		ivbuf = array.array('B', (random.randint(0, 255) for x in xrange(16)))
272		cop.iv = ivbuf.buffer_info()[0]
273
274		exit = [ False ]
275		def alarmhandle(a, b, exit=exit):
276			exit[0] = True
277
278		oldalarm = signal.signal(signal.SIGALRM, alarmhandle)
279		signal.alarm(timeo)
280
281		start = time.time()
282		reps = 0
283		while not exit[0]:
284			ioctl(_cryptodev, CIOCCRYPT, str(cop))
285			reps += 1
286
287		end = time.time()
288
289		signal.signal(signal.SIGALRM, oldalarm)
290
291		print('time:', end - start)
292		print('perf MB/sec:', (reps * size) / (end - start) / 1024 / 1024)
293
294	def encrypt(self, data, iv, aad=None):
295		if aad is None:
296			return self._doop(COP_ENCRYPT, data, iv)
297		else:
298			return self._doaead(COP_ENCRYPT, data, aad,
299			    iv)
300
301	def decrypt(self, data, iv, aad=None, tag=None):
302		if aad is None:
303			return self._doop(COP_DECRYPT, data, iv)
304		else:
305			return self._doaead(COP_DECRYPT, data, aad,
306			    iv, tag=tag)
307
308class MismatchError(Exception):
309	pass
310
311class KATParser:
312	def __init__(self, fname, fields):
313		self.fp = open(fname)
314		self.fields = set(fields)
315		self._pending = None
316
317	def __iter__(self):
318		while True:
319			didread = False
320			if self._pending is not None:
321				i = self._pending
322				self._pending = None
323			else:
324				i = self.fp.readline()
325				didread = True
326
327			if didread and not i:
328				return
329
330			if (i and i[0] == '#') or not i.strip():
331				continue
332			if i[0] == '[':
333				yield i[1:].split(']', 1)[0], self.fielditer()
334			else:
335				raise ValueError('unknown line: %r' % repr(i))
336
337	def eatblanks(self):
338		while True:
339			line = self.fp.readline()
340			if line == '':
341				break
342
343			line = line.strip()
344			if line:
345				break
346
347		return line
348
349	def fielditer(self):
350		while True:
351			values = {}
352
353			line = self.eatblanks()
354			if not line or line[0] == '[':
355				self._pending = line
356				return
357
358			while True:
359				try:
360					f, v = line.split(' =')
361				except:
362					if line == 'FAIL':
363						f, v = 'FAIL', ''
364					else:
365						print('line:', repr(line))
366						raise
367				v = v.strip()
368
369				if f in values:
370					raise ValueError('already present: %r' % repr(f))
371				values[f] = v
372				line = self.fp.readline().strip()
373				if not line:
374					break
375
376			# we should have everything
377			remain = self.fields.copy() - set(values.keys())
378			# XXX - special case GCM decrypt
379			if remain and not ('FAIL' in values and 'PT' in remain):
380				raise ValueError('not all fields found: %r' % repr(remain))
381
382			yield values
383
384# The CCM files use a bit of a different syntax that doesn't quite fit
385# the generic KATParser.  In particular, some keys are set globally at
386# the start of the file, and some are set globally at the start of a
387# section.
388class KATCCMParser:
389	def __init__(self, fname):
390		self.fp = open(fname)
391		self._pending = None
392		self.read_globals()
393
394	def read_globals(self):
395		self.global_values = {}
396		while True:
397			line = self.fp.readline()
398			if not line:
399				return
400			if line[0] == '#' or not line.strip():
401				continue
402			if line[0] == '[':
403				self._pending = line
404				return
405
406			try:
407				f, v = line.split(' =')
408			except:
409				print('line:', repr(line))
410				raise
411
412			v = v.strip()
413
414			if f in self.global_values:
415				raise ValueError('already present: %r' % repr(f))
416			self.global_values[f] = v
417
418	def read_section_values(self, kwpairs):
419		self.section_values = self.global_values.copy()
420		for pair in kwpairs.split(', '):
421			f, v = pair.split(' = ')
422			if f in self.section_values:
423				raise ValueError('already present: %r' % repr(f))
424			self.section_values[f] = v
425
426		while True:
427			line = self.fp.readline()
428			if not line:
429				return
430			if line[0] == '#' or not line.strip():
431				continue
432			if line[0] == '[':
433				self._pending = line
434				return
435
436			try:
437				f, v = line.split(' =')
438			except:
439				print('line:', repr(line))
440				raise
441
442			if f == 'Count':
443				self._pending = line
444				return
445
446			v = v.strip()
447
448			if f in self.section_values:
449				raise ValueError('already present: %r' % repr(f))
450			self.section_values[f] = v
451
452	def __iter__(self):
453		while True:
454			if self._pending:
455				line = self._pending
456				self._pending = None
457			else:
458				line = self.fp.readline()
459				if not line:
460					return
461
462			if (line and line[0] == '#') or not line.strip():
463				continue
464
465			if line[0] == '[':
466				section = line[1:].split(']', 1)[0]
467				self.read_section_values(section)
468				continue
469
470			values = self.section_values.copy()
471
472			while True:
473				try:
474					f, v = line.split(' =')
475				except:
476					print('line:', repr(line))
477					raise
478				v = v.strip()
479
480				if f in values:
481					raise ValueError('already present: %r' % repr(f))
482				values[f] = v
483				line = self.fp.readline().strip()
484				if not line:
485					break
486
487			yield values
488
489
490def _spdechex(s):
491	return ''.join(s.split()).decode('hex')
492
493if __name__ == '__main__':
494	if True:
495		try:
496			crid = Crypto.findcrid('aesni0')
497			print('aesni:', crid)
498		except IOError:
499			print('aesni0 not found')
500
501		for i in xrange(10):
502			try:
503				name = Crypto.getcridname(i)
504				print('%2d: %r' % (i, repr(name)))
505			except IOError:
506				pass
507	elif False:
508		kp = KATParser('/usr/home/jmg/aesni.testing/format tweak value input - data unit seq no/XTSGenAES128.rsp', [ 'COUNT', 'DataUnitLen', 'Key', 'DataUnitSeqNumber', 'PT', 'CT' ])
509		for mode, ni in kp:
510			print(i, ni)
511			for j in ni:
512				print(j)
513	elif False:
514		key = _spdechex('c939cc13397c1d37de6ae0e1cb7c423c')
515		iv = _spdechex('00000000000000000000000000000001')
516		pt = _spdechex('ab3cabed693a32946055524052afe3c9cb49664f09fc8b7da824d924006b7496353b8c1657c5dec564d8f38d7432e1de35aae9d95590e66278d4acce883e51abaf94977fcd3679660109a92bf7b2973ccd547f065ec6cee4cb4a72a5e9f45e615d920d76cb34cba482467b3e21422a7242e7d931330c0fbf465c3a3a46fae943029fd899626dda542750a1eee253df323c6ef1573f1c8c156613e2ea0a6cdbf2ae9701020be2d6a83ecb7f3f9d8e')
517		#pt = _spdechex('00000000000000000000000000000000')
518		ct = _spdechex('f42c33853ecc5ce2949865fdb83de3bff1089e9360c94f830baebfaff72836ab5236f77212f1e7396c8c54ac73d81986375a6e9e299cfeca5ba051ed25e8d1affa5beaf6c1d2b45e90802408f2ced21663497e906de5f29341e5e52ddfea5363d628b3eb7806835e17bae051b3a6da3f8e2941fe44384eac17a9d298d2c331ca8320c775b5d53263a5e905059d891b21dede2d8110fd427c7bd5a9a274ddb47b1945ee79522203b6e297d0e399ef')
519
520		c = Crypto(CRYPTO_AES_ICM, key)
521		enc = c.encrypt(pt, iv)
522
523		print('enc:', enc.encode('hex'))
524		print(' ct:', ct.encode('hex'))
525
526		assert ct == enc
527
528		dec = c.decrypt(ct, iv)
529
530		print('dec:', dec.encode('hex'))
531		print(' pt:', pt.encode('hex'))
532
533		assert pt == dec
534	elif False:
535		key = _spdechex('c939cc13397c1d37de6ae0e1cb7c423c')
536		iv = _spdechex('00000000000000000000000000000001')
537		pt = _spdechex('ab3cabed693a32946055524052afe3c9cb49664f09fc8b7da824d924006b7496353b8c1657c5dec564d8f38d7432e1de35aae9d95590e66278d4acce883e51abaf94977fcd3679660109a92bf7b2973ccd547f065ec6cee4cb4a72a5e9f45e615d920d76cb34cba482467b3e21422a7242e7d931330c0fbf465c3a3a46fae943029fd899626dda542750a1eee253df323c6ef1573f1c8c156613e2ea0a6cdbf2ae9701020be2d6a83ecb7f3f9d8e0a3f')
538		#pt = _spdechex('00000000000000000000000000000000')
539		ct = _spdechex('f42c33853ecc5ce2949865fdb83de3bff1089e9360c94f830baebfaff72836ab5236f77212f1e7396c8c54ac73d81986375a6e9e299cfeca5ba051ed25e8d1affa5beaf6c1d2b45e90802408f2ced21663497e906de5f29341e5e52ddfea5363d628b3eb7806835e17bae051b3a6da3f8e2941fe44384eac17a9d298d2c331ca8320c775b5d53263a5e905059d891b21dede2d8110fd427c7bd5a9a274ddb47b1945ee79522203b6e297d0e399ef3768')
540
541		c = Crypto(CRYPTO_AES_ICM, key)
542		enc = c.encrypt(pt, iv)
543
544		print('enc:', enc.encode('hex'))
545		print(' ct:', ct.encode('hex'))
546
547		assert ct == enc
548
549		dec = c.decrypt(ct, iv)
550
551		print('dec:', dec.encode('hex'))
552		print(' pt:', pt.encode('hex'))
553
554		assert pt == dec
555	elif False:
556		key = _spdechex('c939cc13397c1d37de6ae0e1cb7c423c')
557		iv = _spdechex('6eba2716ec0bd6fa5cdef5e6d3a795bc')
558		pt = _spdechex('ab3cabed693a32946055524052afe3c9cb49664f09fc8b7da824d924006b7496353b8c1657c5dec564d8f38d7432e1de35aae9d95590e66278d4acce883e51abaf94977fcd3679660109a92bf7b2973ccd547f065ec6cee4cb4a72a5e9f45e615d920d76cb34cba482467b3e21422a7242e7d931330c0fbf465c3a3a46fae943029fd899626dda542750a1eee253df323c6ef1573f1c8c156613e2ea0a6cdbf2ae9701020be2d6a83ecb7f3f9d8e0a3f')
559		ct = _spdechex('f1f81f12e72e992dbdc304032705dc75dc3e4180eff8ee4819906af6aee876d5b00b7c36d282a445ce3620327be481e8e53a8e5a8e5ca9abfeb2281be88d12ffa8f46d958d8224738c1f7eea48bda03edbf9adeb900985f4fa25648b406d13a886c25e70cfdecdde0ad0f2991420eb48a61c64fd797237cf2798c2675b9bb744360b0a3f329ac53bbceb4e3e7456e6514f1a9d2f06c236c31d0f080b79c15dce1096357416602520daa098b17d1af427')
560		c = Crypto(CRYPTO_AES_CBC, key)
561
562		enc = c.encrypt(pt, iv)
563
564		print('enc:', enc.encode('hex'))
565		print(' ct:', ct.encode('hex'))
566
567		assert ct == enc
568
569		dec = c.decrypt(ct, iv)
570
571		print('dec:', dec.encode('hex'))
572		print(' pt:', pt.encode('hex'))
573
574		assert pt == dec
575	elif False:
576		key = _spdechex('c939cc13397c1d37de6ae0e1cb7c423c')
577		iv = _spdechex('b3d8cc017cbb89b39e0f67e2')
578		pt = _spdechex('c3b3c41f113a31b73d9a5cd4321030')
579		aad = _spdechex('24825602bd12a984e0092d3e448eda5f')
580		ct = _spdechex('93fe7d9e9bfd10348a5606e5cafa7354')
581		ct = _spdechex('93fe7d9e9bfd10348a5606e5cafa73')
582		tag = _spdechex('0032a1dc85f1c9786925a2e71d8272dd')
583		tag = _spdechex('8d11a0929cb3fbe1fef01a4a38d5f8ea')
584
585		c = Crypto(CRYPTO_AES_NIST_GCM_16, key,
586		    mac=CRYPTO_AES_128_NIST_GMAC, mackey=key)
587
588		enc, enctag = c.encrypt(pt, iv, aad=aad)
589
590		print('enc:', enc.encode('hex'))
591		print(' ct:', ct.encode('hex'))
592
593		assert enc == ct
594
595		print('etg:', enctag.encode('hex'))
596		print('tag:', tag.encode('hex'))
597		assert enctag == tag
598
599		# Make sure we get EBADMSG
600		#enctag = enctag[:-1] + 'a'
601		dec, dectag = c.decrypt(ct, iv, aad=aad, tag=enctag)
602
603		print('dec:', dec.encode('hex'))
604		print(' pt:', pt.encode('hex'))
605
606		assert dec == pt
607
608		print('dtg:', dectag.encode('hex'))
609		print('tag:', tag.encode('hex'))
610
611		assert dectag == tag
612	elif False:
613		key = _spdechex('c939cc13397c1d37de6ae0e1cb7c423c')
614		iv = _spdechex('b3d8cc017cbb89b39e0f67e2')
615		key = key + iv[:4]
616		iv = iv[4:]
617		pt = _spdechex('c3b3c41f113a31b73d9a5cd432103069')
618		aad = _spdechex('24825602bd12a984e0092d3e448eda5f')
619		ct = _spdechex('93fe7d9e9bfd10348a5606e5cafa7354')
620		tag = _spdechex('0032a1dc85f1c9786925a2e71d8272dd')
621
622		c = Crypto(CRYPTO_AES_GCM_16, key, mac=CRYPTO_AES_128_GMAC, mackey=key)
623
624		enc, enctag = c.encrypt(pt, iv, aad=aad)
625
626		print('enc:', enc.encode('hex'))
627		print(' ct:', ct.encode('hex'))
628
629		assert enc == ct
630
631		print('etg:', enctag.encode('hex'))
632		print('tag:', tag.encode('hex'))
633		assert enctag == tag
634	elif False:
635		for i in xrange(100000):
636			c = Crypto(CRYPTO_AES_XTS, '1bbfeadf539daedcae33ced497343f3ca1f2474ad932b903997d44707db41382'.decode('hex'))
637			data = '52a42bca4e9425a25bbc8c8bf6129dec'.decode('hex')
638			ct = '517e602becd066b65fa4f4f56ddfe240'.decode('hex')
639			iv = _pack('QQ', 71, 0)
640
641			enc = c.encrypt(data, iv)
642			assert enc == ct
643	elif True:
644		c = Crypto(CRYPTO_AES_XTS, '1bbfeadf539daedcae33ced497343f3ca1f2474ad932b903997d44707db41382'.decode('hex'))
645		data = '52a42bca4e9425a25bbc8c8bf6129dec'.decode('hex')
646		ct = '517e602becd066b65fa4f4f56ddfe240'.decode('hex')
647		iv = _pack('QQ', 71, 0)
648
649		enc = c.encrypt(data, iv)
650		assert enc == ct
651
652		dec = c.decrypt(enc, iv)
653		assert dec == data
654
655		#c.perftest(COP_ENCRYPT, 192*1024, reps=30000)
656
657	else:
658		key = '1bbfeadf539daedcae33ced497343f3ca1f2474ad932b903997d44707db41382'.decode('hex')
659		print('XTS %d testing:' % (len(key) * 8))
660		c = Crypto(CRYPTO_AES_XTS, key)
661		for i in [ 8192, 192*1024]:
662			print('block size: %d' % i)
663			c.perftest(COP_ENCRYPT, i)
664			c.perftest(COP_DECRYPT, i)
665