Added SelfTest module + some fixes
[python-cryptoplus.git] / src / SelfTest / Hash / test_SHA256.py
blob2e97eee059db491bfc75f606d1ee8efdb1d5565d
1 # -*- coding: utf-8 -*-
3 # SelfTest/Hash/SHA256.py: Self-test for the SHA-256 hash function
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 SHA256LL 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.Hash.SHA256"""
31 __revision__ = "$Id$"
33 # Test vectors from FIPS PUB 180-2
34 # This is a list of (expected_result, input[, description]) tuples.
35 test_data = [
36 # FIPS PUB 180-2, B.1 - "One-Block Message"
37 ('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad',
38 'abc'),
40 # FIPS PUB 180-2, B.2 - "Multi-Block Message"
41 ('248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1',
42 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'),
44 # FIPS PUB 180-2, B.3 - "Long Message"
45 # ('cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0',
46 # 'a' * 10**6,
47 # '"a" * 10**6'),
49 # Test for an old PyCryptoPlus bug.
50 ('f7fd017a3c721ce7ff03f3552c0813adcc48b7f33f07e5e2ba71e23ea393d103',
51 'This message is precisely 55 bytes long, to test a bug.',
52 'Length = 55 (mod 64)'),
55 def get_tests():
56 from CryptoPlus.Hash import SHA256
57 from common import make_hash_tests
58 return make_hash_tests(SHA256, "SHA256", test_data)
60 if __name__ == '__main__':
61 import unittest
62 suite = lambda: unittest.TestSuite(get_tests())
63 unittest.main(defaultTest='suite')
65 # vim:set ts=4 sw=4 sts=4 expandtab: