blob: cad7780467fff7c3d06e14b562bfb0772dded06e [file] [log] [blame]
Guido van Rossuma6386ce1999-03-24 19:04:32 +00001# Testing sha module (NIST's Secure Hash Algorithm)
2
Guido van Rossuma6386ce1999-03-24 19:04:32 +00003# use the three examples from Federal Information Processing Standards
4# Publication 180-1, Secure Hash Standard, 1995 April 17
5# http://www.itl.nist.gov/div897/pubs/fip180-1.htm
6
Fred Drakecf992252001-05-22 21:43:17 +00007import sha
8import test_support
9import unittest
Guido van Rossuma6386ce1999-03-24 19:04:32 +000010
Guido van Rossuma6386ce1999-03-24 19:04:32 +000011
Fred Drakecf992252001-05-22 21:43:17 +000012class SHATestCase(unittest.TestCase):
13 def check(self, data, digest):
14 computed = sha.new(data).hexdigest()
15 self.assert_(computed == digest)
Guido van Rossuma6386ce1999-03-24 19:04:32 +000016
Fred Drakecf992252001-05-22 21:43:17 +000017 def test_case_1(self):
18 self.check("abc",
19 "a9993e364706816aba3e25717850c26c9cd0d89d")
Guido van Rossuma6386ce1999-03-24 19:04:32 +000020
Fred Drakecf992252001-05-22 21:43:17 +000021 def test_case_2(self):
22 self.check("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
23 "84983e441c3bd26ebaae4aa1f95129e5e54670f1")
24
25 def test_case_3(self):
26 self.check("a" * 1000000,
27 "34aa973cd4c4daa4f61eeb2bdbad27316534016f")
28
29
Fred Drake2e2be372001-09-20 21:33:42 +000030def test_main():
31 test_support.run_unittest(SHATestCase)
32
33
34if __name__ == "__main__":
35 test_main()