Added SelfTest module + some fixes
[python-cryptoplus.git] / src / SelfTest / Cipher / test_RC5.py
blob637f4a380596bea86415f81a095dcd9b55dcd8f7
1 # -*- coding: utf-8 -*-
3 # SelfTest/Cipher/RC5.py: Self-test for the RC5 cipher
5 # =======================================================================
6 # Copyright (C) 2008 Dwayne C. Litzenberger <dlitz@dlitz.net>
8 # Permission is hereby granted, free of charge, to any person obtaining
9 # a copy of this software and associated documentation files (the
10 # "Software"), to deal in the Software without restriction, including
11 # without limitation the rights to use, copy, modify, merge, publish,
12 # distribute, sublicense, and/or sell copies of the Software, and to
13 # permit persons to whom the Software is furnished to do so.
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 # =======================================================================
29 """Self-test suite for CryptoPlus.Cipher.RC5"""
31 __revision__ = "$Id$"
33 from common import dict # For compatibility with Python 2.1 and 2.2
35 # This is a list of (plaintext, ciphertext, key, description or None, extra_params) tuples.
36 test_data = [
37 # Test vectors from http://theory.lcs.mit.edu/~rivest/Rivest-rc5rev.pdf
38 # Rivest, R. L. (1994). "The RC5 Encryption Algorithm" (pdf). Proceedings
39 # of the Second International Workshop on Fast Software Encryption (FSE)
40 # 1994e: 86–96.
41 ('0000000000000000', '21a5dbee154b8f6d', '00000000000000000000000000000000',
42 "Rivest94-1", dict(word_size=32, rounds=12)),
43 ('21a5dbee154b8f6d', 'f7c013ac5b2b8952', '915f4619be41b2516355a50110a9ce91',
44 "Rivest94-2", dict(word_size=32, rounds=12)),
45 ('f7c013ac5b2b8952', '2f42b3b70369fc92', '783348e75aeb0f2fd7b169bb8dc16787',
46 "Rivest94-3", dict(word_size=32, rounds=12)),
47 ('2f42b3b70369fc92', '65c178b284d197cc', 'dc49db1375a5584f6485b413b5f12baf',
48 "Rivest94-4", dict(word_size=32, rounds=12)),
49 ('65c178b284d197cc', 'eb44e415da319824', '5269f149d41ba0152497574d7f153125',
50 "Rivest94-5", dict(word_size=32, rounds=12)),
52 # Test vectors from RFC 2040
53 ('0000000000000000', '7a7bba4d79111d1e', '00', 'RFC2040-1', dict(rounds=0, mode='CBC', iv='0000000000000000')),
54 ('ffffffffffffffff', '797bba4d78111d1e', '00', 'RFC2040-2', dict(rounds=0, mode='CBC', iv='0000000000000000')),
55 ('0000000000000000', '7a7bba4d79111d1f', '00', 'RFC2040-3', dict(rounds=0, mode='CBC', iv='0000000000000001')),
56 ('0000000000000001', '7a7bba4d79111d1f', '00', 'RFC2040-4', dict(rounds=0, mode='CBC', iv='0000000000000000')),
57 ('1020304050607080', '8b9ded91ce7794a6', '00', 'RFC2040-5', dict(rounds=0, mode='CBC', iv='0102030405060708')),
58 ('0000000000000000', '2f759fe7ad86a378', '11', 'RFC2040-6', dict(rounds=1, mode='CBC', iv='0000000000000000')),
59 ('0000000000000000', 'dca2694bf40e0788', '00', 'RFC2040-7', dict(rounds=2, mode='CBC', iv='0000000000000000')),
60 ('0000000000000000', 'dca2694bf40e0788', '00000000', 'RFC2040-8', dict(rounds=2, mode='CBC', iv='0000000000000000')),
61 ('0000000000000000', 'dcfe098577eca5ff', '00', 'RFC2040-9', dict(rounds=8, mode='CBC', iv='0000000000000000')),
62 ('1020304050607080', '9646fb77638f9ca8', '00', 'RFC2040-10', dict(rounds=8, mode='CBC', iv='0102030405060708')),
63 ('1020304050607080', 'b2b3209db6594da4', '00', 'RFC2040-11', dict(rounds=12, mode='CBC', iv='0102030405060708')),
64 ('1020304050607080', '545f7f32a5fc3836', '00', 'RFC2040-12', dict(rounds=16, mode='CBC', iv='0102030405060708')),
65 ('ffffffffffffffff', '8285e7c1b5bc7402', '01020304', 'RFC2040-13', dict(rounds=8, mode='CBC', iv='0000000000000000')),
66 ('ffffffffffffffff', 'fc586f92f7080934', '01020304', 'RFC2040-14', dict(rounds=12, mode='CBC', iv='0000000000000000')),
67 ('ffffffffffffffff', 'cf270ef9717ff7c4', '01020304', 'RFC2040-15', dict(rounds=16, mode='CBC', iv='0000000000000000')),
68 ('ffffffffffffffff', 'e493f1c1bb4d6e8c', '0102030405060708', 'RFC2040-16', dict(rounds=12, mode='CBC', iv='0000000000000000')),
69 ('1020304050607080', '5c4c041e0f217ac3', '0102030405060708', 'RFC2040-17', dict(rounds=8, mode='CBC', iv='0102030405060708')),
70 ('1020304050607080', '921f12485373b4f7', '0102030405060708', 'RFC2040-18', dict(rounds=12, mode='CBC', iv='0102030405060708')),
71 ('1020304050607080', '5ba0ca6bbe7f5fad', '0102030405060708', 'RFC2040-19', dict(rounds=16, mode='CBC', iv='0102030405060708')),
72 ('1020304050607080', 'c533771cd0110e63', '01020304050607081020304050607080', 'RFC2040-20', dict(rounds=8, mode='CBC', iv='0102030405060708')),
73 ('1020304050607080', '294ddb46b3278d60', '01020304050607081020304050607080', 'RFC2040-21', dict(rounds=12, mode='CBC', iv='0102030405060708')),
74 ('1020304050607080', 'dad6bda9dfe8f7e8', '01020304050607081020304050607080', 'RFC2040-22', dict(rounds=16, mode='CBC', iv='0102030405060708')),
75 ('ffffffffffffffff', '97e0787837ed317f', '0102030405', 'RFC2040-23', dict(rounds=12, mode='CBC', iv='0000000000000000')),
76 ('ffffffffffffffff', '7875dbf6738c6478', '0102030405', 'RFC2040-24', dict(rounds=8, mode='CBC', iv='0000000000000000')),
77 ('0808080808080808', '8f34c3c681c99695', '0102030405', 'RFC2040-25', dict(rounds=8, mode='CBC', iv='7875dbf6738c6478')),
78 # ('ffffffffffffffff', '7875dbf6738c64788f34c3c681c99695', '0102030405', 'RFC2040-26', dict(rounds=8, mode='CBC-Pad', iv='0000000000000000')),
79 ('0000000000000000', '7cb3f1df34f94811', '0102030405', 'RFC2040-27', dict(rounds=8, mode='CBC', iv='0000000000000000')),
80 ('1122334455667701', '7fd1a023a5bba217', '0102030405', 'RFC2040-28', dict(rounds=8, mode='CBC', iv='7cb3f1df34f94811')),
81 # ('ffffffffffffffff7875dbf6738c647811223344556677', '7875dbf6738c64787cb3f1df34f948117fd1a023a5bba217', '0102030405', 'RFC2040-29', dict(rounds=8, mode='CBC-Pad', iv='0000000000000000')),
84 def get_tests():
85 from CryptoPlus.Cipher import RC5
86 from common import make_block_tests
87 return make_block_tests(RC5, "RC5", test_data)
89 if __name__ == '__main__':
90 import unittest
91 suite = lambda: unittest.TestSuite(get_tests())
92 unittest.main(defaultTest='suite')
94 # vim:set ts=4 sw=4 sts=4 expandtab: