test_SHA224.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. #
  3. # SelfTest/Hash/test_SHA224.py: Self-test for the SHA-224 hash function
  4. #
  5. # Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
  6. #
  7. # ===================================================================
  8. # The contents of this file are dedicated to the public domain. To
  9. # the extent that dedication to the public domain is not available,
  10. # everyone is granted a worldwide, perpetual, royalty-free,
  11. # non-exclusive license to exercise all rights associated with the
  12. # contents of this file for any purpose whatsoever.
  13. # No rights are reserved.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. # SOFTWARE.
  23. # ===================================================================
  24. """Self-test suite for Crypto.Hash.SHA224"""
  25. __revision__ = "$Id$"
  26. # Test vectors from various sources
  27. # This is a list of (expected_result, input[, description]) tuples.
  28. test_data = [
  29. # RFC 3874: Section 3.1, "Test Vector #1
  30. ('23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7', 'abc'),
  31. # RFC 3874: Section 3.2, "Test Vector #2
  32. ('75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525', 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'),
  33. # RFC 3874: Section 3.3, "Test Vector #3
  34. ('20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67', 'a' * 10**6, "'a' * 10**6"),
  35. # Examples from http://de.wikipedia.org/wiki/Secure_Hash_Algorithm
  36. ('d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f', ''),
  37. ('49b08defa65e644cbf8a2dd9270bdededabc741997d1dadd42026d7b',
  38. 'Franz jagt im komplett verwahrlosten Taxi quer durch Bayern'),
  39. ('58911e7fccf2971a7d07f93162d8bd13568e71aa8fc86fc1fe9043d1',
  40. 'Frank jagt im komplett verwahrlosten Taxi quer durch Bayern'),
  41. ]
  42. def get_tests(config={}):
  43. from Crypto.Hash import SHA224
  44. from common import make_hash_tests
  45. return make_hash_tests(SHA224, "SHA224", test_data,
  46. digest_size=28,
  47. oid='\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x04')
  48. if __name__ == '__main__':
  49. import unittest
  50. suite = lambda: unittest.TestSuite(get_tests())
  51. unittest.main(defaultTest='suite')
  52. # vim:set ts=4 sw=4 sts=4 expandtab: