Added SelfTest module + some fixes
[python-cryptoplus.git] / src / SelfTest / Hash / test_SHA.py
blob3b986a63c838efcf8eea7bd3badaae335ba8b919
1 # -*- coding: utf-8 -*-
3 # SelfTest/Hash/SHA.py: Self-test for the SHA-1 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 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.Hash.SHA"""
31 __revision__ = "$Id$"
33 # Test vectors from various sources
34 # This is a list of (expected_result, input[, description]) tuples.
35 test_data = [
36 # FIPS PUB 180-2, A.1 - "One-Block Message"
37 ('a9993e364706816aba3e25717850c26c9cd0d89d', 'abc'),
39 # FIPS PUB 180-2, A.2 - "Multi-Block Message"
40 ('84983e441c3bd26ebaae4aa1f95129e5e54670f1',
41 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'),
43 # FIPS PUB 180-2, A.3 - "Long Message"
44 # ('34aa973cd4c4daa4f61eeb2bdbad27316534016f',
45 # 'a' * 10**6,
46 # '"a" * 10**6'),
48 # RFC 3174: Section 7.3, "TEST4" (multiple of 512 bits)
49 ('dea356a2cddd90c7a7ecedc5ebb563934f460452',
50 "01234567" * 80,
51 '"01234567" * 80'),
54 def get_tests():
55 from CryptoPlus.Hash import SHA
56 from common import make_hash_tests
57 return make_hash_tests(SHA, "SHA", test_data)
59 if __name__ == '__main__':
60 import unittest
61 suite = lambda: unittest.TestSuite(get_tests())
62 unittest.main(defaultTest='suite')
64 # vim:set ts=4 sw=4 sts=4 expandtab: