Guido van Rossum | a6386ce | 1999-03-24 19:04:32 +0000 | [diff] [blame] | 1 | # Testing sha module (NIST's Secure Hash Algorithm) |
| 2 | |
Guido van Rossum | a6386ce | 1999-03-24 19:04:32 +0000 | [diff] [blame] | 3 | # 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 Drake | cf99225 | 2001-05-22 21:43:17 +0000 | [diff] [blame^] | 7 | import sha |
| 8 | import test_support |
| 9 | import unittest |
Guido van Rossum | a6386ce | 1999-03-24 19:04:32 +0000 | [diff] [blame] | 10 | |
Guido van Rossum | a6386ce | 1999-03-24 19:04:32 +0000 | [diff] [blame] | 11 | |
Fred Drake | cf99225 | 2001-05-22 21:43:17 +0000 | [diff] [blame^] | 12 | class SHATestCase(unittest.TestCase): |
| 13 | def check(self, data, digest): |
| 14 | computed = sha.new(data).hexdigest() |
| 15 | self.assert_(computed == digest) |
Guido van Rossum | a6386ce | 1999-03-24 19:04:32 +0000 | [diff] [blame] | 16 | |
Fred Drake | cf99225 | 2001-05-22 21:43:17 +0000 | [diff] [blame^] | 17 | def test_case_1(self): |
| 18 | self.check("abc", |
| 19 | "a9993e364706816aba3e25717850c26c9cd0d89d") |
Guido van Rossum | a6386ce | 1999-03-24 19:04:32 +0000 | [diff] [blame] | 20 | |
Fred Drake | cf99225 | 2001-05-22 21:43:17 +0000 | [diff] [blame^] | 21 | 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 | |
| 30 | test_support.run_unittest(SHATestCase) |