test_EAX.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. # ===================================================================
  2. #
  3. # Copyright (c) 2015, Legrandin <helderijs@gmail.com>
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. #
  10. # 1. Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in
  14. # the documentation and/or other materials provided with the
  15. # distribution.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  27. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. # POSSIBILITY OF SUCH DAMAGE.
  29. # ===================================================================
  30. import unittest
  31. from Crypto.SelfTest.st_common import list_test_cases
  32. from Crypto.Util.py3compat import unhexlify, tobytes, bchr, b
  33. from Crypto.Cipher import AES, DES3
  34. from Crypto.Hash import SHAKE128
  35. def get_tag_random(tag, length):
  36. return SHAKE128.new(data=tobytes(tag)).read(length)
  37. class EaxTests(unittest.TestCase):
  38. key_128 = get_tag_random("key_128", 16)
  39. key_192 = get_tag_random("key_192", 16)
  40. nonce_96 = get_tag_random("nonce_128", 12)
  41. data_128 = get_tag_random("data_128", 16)
  42. def test_loopback_128(self):
  43. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  44. pt = get_tag_random("plaintext", 16 * 100)
  45. ct = cipher.encrypt(pt)
  46. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  47. pt2 = cipher.decrypt(ct)
  48. self.assertEqual(pt, pt2)
  49. def test_loopback_64(self):
  50. cipher = DES3.new(self.key_192, DES3.MODE_EAX, nonce=self.nonce_96)
  51. pt = get_tag_random("plaintext", 8 * 100)
  52. ct = cipher.encrypt(pt)
  53. cipher = DES3.new(self.key_192, DES3.MODE_EAX, nonce=self.nonce_96)
  54. pt2 = cipher.decrypt(ct)
  55. self.assertEqual(pt, pt2)
  56. def test_nonce(self):
  57. # If not passed, the nonce is created randomly
  58. cipher = AES.new(self.key_128, AES.MODE_EAX)
  59. nonce1 = cipher.nonce
  60. cipher = AES.new(self.key_128, AES.MODE_EAX)
  61. nonce2 = cipher.nonce
  62. self.assertEqual(len(nonce1), 16)
  63. self.assertNotEqual(nonce1, nonce2)
  64. cipher = AES.new(self.key_128, AES.MODE_EAX, self.nonce_96)
  65. ct = cipher.encrypt(self.data_128)
  66. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  67. self.assertEquals(ct, cipher.encrypt(self.data_128))
  68. def test_nonce_must_be_bytes(self):
  69. self.assertRaises(TypeError, AES.new, self.key_128, AES.MODE_EAX,
  70. nonce=u'test12345678')
  71. def test_nonce_length(self):
  72. # nonce can be of any length (but not empty)
  73. self.assertRaises(ValueError, AES.new, self.key_128, AES.MODE_EAX,
  74. nonce=b(""))
  75. for x in range(1, 128):
  76. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=bchr(1) * x)
  77. cipher.encrypt(bchr(1))
  78. def test_block_size_128(self):
  79. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  80. self.assertEqual(cipher.block_size, AES.block_size)
  81. def test_block_size_64(self):
  82. cipher = DES3.new(self.key_192, AES.MODE_EAX, nonce=self.nonce_96)
  83. self.assertEqual(cipher.block_size, DES3.block_size)
  84. def test_nonce_attribute(self):
  85. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  86. self.assertEqual(cipher.nonce, self.nonce_96)
  87. # By default, a 16 bytes long nonce is randomly generated
  88. nonce1 = AES.new(self.key_128, AES.MODE_EAX).nonce
  89. nonce2 = AES.new(self.key_128, AES.MODE_EAX).nonce
  90. self.assertEqual(len(nonce1), 16)
  91. self.assertNotEqual(nonce1, nonce2)
  92. def test_unknown_parameters(self):
  93. self.assertRaises(TypeError, AES.new, self.key_128, AES.MODE_EAX,
  94. self.nonce_96, 7)
  95. self.assertRaises(TypeError, AES.new, self.key_128, AES.MODE_EAX,
  96. nonce=self.nonce_96, unknown=7)
  97. # But some are only known by the base cipher
  98. # (e.g. use_aesni consumed by the AES module)
  99. AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96,
  100. use_aesni=False)
  101. def test_null_encryption_decryption(self):
  102. for func in "encrypt", "decrypt":
  103. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  104. result = getattr(cipher, func)(b(""))
  105. self.assertEqual(result, b(""))
  106. def test_either_encrypt_or_decrypt(self):
  107. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  108. cipher.encrypt(b(""))
  109. self.assertRaises(TypeError, cipher.decrypt, b(""))
  110. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  111. cipher.decrypt(b(""))
  112. self.assertRaises(TypeError, cipher.encrypt, b(""))
  113. def test_data_must_be_bytes(self):
  114. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  115. self.assertRaises(TypeError, cipher.encrypt, u'test1234567890-*')
  116. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  117. self.assertRaises(TypeError, cipher.decrypt, u'test1234567890-*')
  118. def test_mac_len(self):
  119. # Invalid MAC length
  120. self.assertRaises(ValueError, AES.new, self.key_128, AES.MODE_EAX,
  121. nonce=self.nonce_96, mac_len=3)
  122. self.assertRaises(ValueError, AES.new, self.key_128, AES.MODE_EAX,
  123. nonce=self.nonce_96, mac_len=16+1)
  124. # Valid MAC length
  125. for mac_len in xrange(5, 16 + 1):
  126. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96,
  127. mac_len=mac_len)
  128. _, mac = cipher.encrypt_and_digest(self.data_128)
  129. self.assertEqual(len(mac), mac_len)
  130. # Default MAC length
  131. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  132. _, mac = cipher.encrypt_and_digest(self.data_128)
  133. self.assertEqual(len(mac), 16)
  134. def test_invalid_mac(self):
  135. from Crypto.Util.strxor import strxor_c
  136. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  137. ct, mac = cipher.encrypt_and_digest(self.data_128)
  138. invalid_mac = strxor_c(mac, 0x01)
  139. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  140. self.assertRaises(ValueError, cipher.decrypt_and_verify, ct,
  141. invalid_mac)
  142. def test_hex_mac(self):
  143. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  144. mac_hex = cipher.hexdigest()
  145. self.assertEqual(cipher.digest(), unhexlify(mac_hex))
  146. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  147. cipher.hexverify(mac_hex)
  148. def test_message_chunks(self):
  149. # Validate that both associated data and plaintext/ciphertext
  150. # can be broken up in chunks of arbitrary length
  151. auth_data = get_tag_random("authenticated data", 127)
  152. plaintext = get_tag_random("plaintext", 127)
  153. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  154. cipher.update(auth_data)
  155. ciphertext, ref_mac = cipher.encrypt_and_digest(plaintext)
  156. def break_up(data, chunk_length):
  157. return [data[i:i+chunk_length] for i in range(0, len(data),
  158. chunk_length)]
  159. # Encryption
  160. for chunk_length in 1, 2, 3, 7, 10, 13, 16, 40, 80, 128:
  161. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  162. for chunk in break_up(auth_data, chunk_length):
  163. cipher.update(chunk)
  164. pt2 = b("")
  165. for chunk in break_up(ciphertext, chunk_length):
  166. pt2 += cipher.decrypt(chunk)
  167. self.assertEqual(plaintext, pt2)
  168. cipher.verify(ref_mac)
  169. # Decryption
  170. for chunk_length in 1, 2, 3, 7, 10, 13, 16, 40, 80, 128:
  171. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  172. for chunk in break_up(auth_data, chunk_length):
  173. cipher.update(chunk)
  174. ct2 = b("")
  175. for chunk in break_up(plaintext, chunk_length):
  176. ct2 += cipher.encrypt(chunk)
  177. self.assertEqual(ciphertext, ct2)
  178. self.assertEquals(cipher.digest(), ref_mac)
  179. class EaxFSMTests(unittest.TestCase):
  180. key_128 = get_tag_random("key_128", 16)
  181. nonce_96 = get_tag_random("nonce_128", 12)
  182. data_128 = get_tag_random("data_128", 16)
  183. def test_valid_init_encrypt_decrypt_digest_verify(self):
  184. # No authenticated data, fixed plaintext
  185. # Verify path INIT->ENCRYPT->DIGEST
  186. cipher = AES.new(self.key_128, AES.MODE_EAX,
  187. nonce=self.nonce_96)
  188. ct = cipher.encrypt(self.data_128)
  189. mac = cipher.digest()
  190. # Verify path INIT->DECRYPT->VERIFY
  191. cipher = AES.new(self.key_128, AES.MODE_EAX,
  192. nonce=self.nonce_96)
  193. cipher.decrypt(ct)
  194. cipher.verify(mac)
  195. def test_valid_init_update_digest_verify(self):
  196. # No plaintext, fixed authenticated data
  197. # Verify path INIT->UPDATE->DIGEST
  198. cipher = AES.new(self.key_128, AES.MODE_EAX,
  199. nonce=self.nonce_96)
  200. cipher.update(self.data_128)
  201. mac = cipher.digest()
  202. # Verify path INIT->UPDATE->VERIFY
  203. cipher = AES.new(self.key_128, AES.MODE_EAX,
  204. nonce=self.nonce_96)
  205. cipher.update(self.data_128)
  206. cipher.verify(mac)
  207. def test_valid_full_path(self):
  208. # Fixed authenticated data, fixed plaintext
  209. # Verify path INIT->UPDATE->ENCRYPT->DIGEST
  210. cipher = AES.new(self.key_128, AES.MODE_EAX,
  211. nonce=self.nonce_96)
  212. cipher.update(self.data_128)
  213. ct = cipher.encrypt(self.data_128)
  214. mac = cipher.digest()
  215. # Verify path INIT->UPDATE->DECRYPT->VERIFY
  216. cipher = AES.new(self.key_128, AES.MODE_EAX,
  217. nonce=self.nonce_96)
  218. cipher.update(self.data_128)
  219. cipher.decrypt(ct)
  220. cipher.verify(mac)
  221. def test_valid_init_digest(self):
  222. # Verify path INIT->DIGEST
  223. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  224. cipher.digest()
  225. def test_valid_init_verify(self):
  226. # Verify path INIT->VERIFY
  227. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  228. mac = cipher.digest()
  229. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  230. cipher.verify(mac)
  231. def test_valid_multiple_encrypt_or_decrypt(self):
  232. for method_name in "encrypt", "decrypt":
  233. for auth_data in (None, b("333"), self.data_128,
  234. self.data_128 + b("3")):
  235. if auth_data is None:
  236. assoc_len = None
  237. else:
  238. assoc_len = len(auth_data)
  239. cipher = AES.new(self.key_128, AES.MODE_EAX,
  240. nonce=self.nonce_96)
  241. if auth_data is not None:
  242. cipher.update(auth_data)
  243. method = getattr(cipher, method_name)
  244. method(self.data_128)
  245. method(self.data_128)
  246. method(self.data_128)
  247. method(self.data_128)
  248. def test_valid_multiple_digest_or_verify(self):
  249. # Multiple calls to digest
  250. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  251. cipher.update(self.data_128)
  252. first_mac = cipher.digest()
  253. for x in xrange(4):
  254. self.assertEqual(first_mac, cipher.digest())
  255. # Multiple calls to verify
  256. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  257. cipher.update(self.data_128)
  258. for x in xrange(5):
  259. cipher.verify(first_mac)
  260. def test_valid_encrypt_and_digest_decrypt_and_verify(self):
  261. # encrypt_and_digest
  262. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  263. cipher.update(self.data_128)
  264. ct, mac = cipher.encrypt_and_digest(self.data_128)
  265. # decrypt_and_verify
  266. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  267. cipher.update(self.data_128)
  268. pt = cipher.decrypt_and_verify(ct, mac)
  269. self.assertEqual(self.data_128, pt)
  270. def test_invalid_mixing_encrypt_decrypt(self):
  271. # Once per method, with or without assoc. data
  272. for method1_name, method2_name in (("encrypt", "decrypt"),
  273. ("decrypt", "encrypt")):
  274. for assoc_data_present in (True, False):
  275. cipher = AES.new(self.key_128, AES.MODE_EAX,
  276. nonce=self.nonce_96)
  277. if assoc_data_present:
  278. cipher.update(self.data_128)
  279. getattr(cipher, method1_name)(self.data_128)
  280. self.assertRaises(TypeError, getattr(cipher, method2_name),
  281. self.data_128)
  282. def test_invalid_encrypt_or_update_after_digest(self):
  283. for method_name in "encrypt", "update":
  284. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  285. cipher.encrypt(self.data_128)
  286. cipher.digest()
  287. self.assertRaises(TypeError, getattr(cipher, method_name),
  288. self.data_128)
  289. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  290. cipher.encrypt_and_digest(self.data_128)
  291. def test_invalid_decrypt_or_update_after_verify(self):
  292. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  293. ct = cipher.encrypt(self.data_128)
  294. mac = cipher.digest()
  295. for method_name in "decrypt", "update":
  296. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  297. cipher.decrypt(ct)
  298. cipher.verify(mac)
  299. self.assertRaises(TypeError, getattr(cipher, method_name),
  300. self.data_128)
  301. cipher = AES.new(self.key_128, AES.MODE_EAX, nonce=self.nonce_96)
  302. cipher.decrypt_and_verify(ct, mac)
  303. self.assertRaises(TypeError, getattr(cipher, method_name),
  304. self.data_128)
  305. class TestVectors(unittest.TestCase):
  306. """Class exercising the EAX test vectors found in
  307. http://www.cs.ucdavis.edu/~rogaway/papers/eax.pdf"""
  308. test_vectors = [
  309. ( '6bfb914fd07eae6b',
  310. '',
  311. '',
  312. 'e037830e8389f27b025a2d6527e79d01',
  313. '233952dee4d5ed5f9b9c6d6ff80ff478',
  314. '62EC67F9C3A4A407FCB2A8C49031A8B3'
  315. ),
  316. (
  317. 'fa3bfd4806eb53fa',
  318. 'f7fb',
  319. '19dd',
  320. '5c4c9331049d0bdab0277408f67967e5',
  321. '91945d3f4dcbee0bf45ef52255f095a4',
  322. 'BECAF043B0A23D843194BA972C66DEBD'
  323. ),
  324. ( '234a3463c1264ac6',
  325. '1a47cb4933',
  326. 'd851d5bae0',
  327. '3a59f238a23e39199dc9266626c40f80',
  328. '01f74ad64077f2e704c0f60ada3dd523',
  329. '70C3DB4F0D26368400A10ED05D2BFF5E'
  330. ),
  331. (
  332. '33cce2eabff5a79d',
  333. '481c9e39b1',
  334. '632a9d131a',
  335. 'd4c168a4225d8e1ff755939974a7bede',
  336. 'd07cf6cbb7f313bdde66b727afd3c5e8',
  337. '8408DFFF3C1A2B1292DC199E46B7D617'
  338. ),
  339. (
  340. 'aeb96eaebe2970e9',
  341. '40d0c07da5e4',
  342. '071dfe16c675',
  343. 'cb0677e536f73afe6a14b74ee49844dd',
  344. '35b6d0580005bbc12b0587124557d2c2',
  345. 'FDB6B06676EEDC5C61D74276E1F8E816'
  346. ),
  347. (
  348. 'd4482d1ca78dce0f',
  349. '4de3b35c3fc039245bd1fb7d',
  350. '835bb4f15d743e350e728414',
  351. 'abb8644fd6ccb86947c5e10590210a4f',
  352. 'bd8e6e11475e60b268784c38c62feb22',
  353. '6EAC5C93072D8E8513F750935E46DA1B'
  354. ),
  355. (
  356. '65d2017990d62528',
  357. '8b0a79306c9ce7ed99dae4f87f8dd61636',
  358. '02083e3979da014812f59f11d52630da30',
  359. '137327d10649b0aa6e1c181db617d7f2',
  360. '7c77d6e813bed5ac98baa417477a2e7d',
  361. '1A8C98DCD73D38393B2BF1569DEEFC19'
  362. ),
  363. (
  364. '54b9f04e6a09189a',
  365. '1bda122bce8a8dbaf1877d962b8592dd2d56',
  366. '2ec47b2c4954a489afc7ba4897edcdae8cc3',
  367. '3b60450599bd02c96382902aef7f832a',
  368. '5fff20cafab119ca2fc73549e20f5b0d',
  369. 'DDE59B97D722156D4D9AFF2BC7559826'
  370. ),
  371. (
  372. '899a175897561d7e',
  373. '6cf36720872b8513f6eab1a8a44438d5ef11',
  374. '0de18fd0fdd91e7af19f1d8ee8733938b1e8',
  375. 'e7f6d2231618102fdb7fe55ff1991700',
  376. 'a4a4782bcffd3ec5e7ef6d8c34a56123',
  377. 'B781FCF2F75FA5A8DE97A9CA48E522EC'
  378. ),
  379. (
  380. '126735fcc320d25a',
  381. 'ca40d7446e545ffaed3bd12a740a659ffbbb3ceab7',
  382. 'cb8920f87a6c75cff39627b56e3ed197c552d295a7',
  383. 'cfc46afc253b4652b1af3795b124ab6e',
  384. '8395fcf1e95bebd697bd010bc766aac3',
  385. '22E7ADD93CFC6393C57EC0B3C17D6B44'
  386. ),
  387. ]
  388. for index, tv in enumerate(test_vectors):
  389. test_vectors[index] = (unhexlify(x) for x in tv)
  390. def runTest(self):
  391. for assoc_data, pt, ct, mac, key, nonce in self.test_vectors:
  392. # Encrypt
  393. cipher = AES.new(key, AES.MODE_EAX, nonce, mac_len=len(mac))
  394. cipher.update(assoc_data)
  395. ct2, mac2 = cipher.encrypt_and_digest(pt)
  396. self.assertEqual(ct, ct2)
  397. self.assertEqual(mac, mac2)
  398. # Decrypt
  399. cipher = AES.new(key, AES.MODE_EAX, nonce, mac_len=len(mac))
  400. cipher.update(assoc_data)
  401. pt2 = cipher.decrypt_and_verify(ct, mac)
  402. self.assertEqual(pt, pt2)
  403. class TestOtherCiphers(unittest.TestCase):
  404. @classmethod
  405. def create_test(cls, name, factory, key_size):
  406. def test_template(self, factory=factory, key_size=key_size):
  407. cipher = factory.new(get_tag_random("cipher", key_size),
  408. factory.MODE_EAX,
  409. nonce=b("nonce"))
  410. ct, mac = cipher.encrypt_and_digest(b("plaintext"))
  411. cipher = factory.new(get_tag_random("cipher", key_size),
  412. factory.MODE_EAX,
  413. nonce=b("nonce"))
  414. pt2 = cipher.decrypt_and_verify(ct, mac)
  415. self.assertEqual(b("plaintext"), pt2)
  416. setattr(cls, "test_" + name, test_template)
  417. from Crypto.Cipher import DES, DES3, ARC2, CAST, Blowfish
  418. for name, factory in (('DES', DES),
  419. ('DES3', DES3),
  420. ('ARC2', ARC2),
  421. ('CAST', CAST),
  422. ('Blowfish', Blowfish)):
  423. key_sizes = []
  424. try:
  425. key_sizes += factory.key_size
  426. except TypeError:
  427. key_sizes = [factory.key_size]
  428. for ks in key_sizes:
  429. TestOtherCiphers.create_test(name + "_" + str(ks), factory, ks)
  430. def get_tests(config={}):
  431. tests = []
  432. tests += list_test_cases(EaxTests)
  433. tests += list_test_cases(EaxFSMTests)
  434. tests += [TestVectors()]
  435. tests += list_test_cases(TestOtherCiphers)
  436. return tests
  437. if __name__ == '__main__':
  438. suite = lambda: unittest.TestSuite(get_tests())
  439. unittest.main(defaultTest='suite')