test_SHA224.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 Cryptodome.Hash.SHA224"""
  25. # Test vectors from various sources
  26. # This is a list of (expected_result, input[, description]) tuples.
  27. test_data = [
  28. # RFC 3874: Section 3.1, "Test Vector #1
  29. ('23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7', 'abc'),
  30. # RFC 3874: Section 3.2, "Test Vector #2
  31. ('75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525', 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'),
  32. # RFC 3874: Section 3.3, "Test Vector #3
  33. ('20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67', 'a' * 10**6, "'a' * 10**6"),
  34. # Examples from http://de.wikipedia.org/wiki/Secure_Hash_Algorithm
  35. ('d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f', ''),
  36. ('49b08defa65e644cbf8a2dd9270bdededabc741997d1dadd42026d7b',
  37. 'Franz jagt im komplett verwahrlosten Taxi quer durch Bayern'),
  38. ('58911e7fccf2971a7d07f93162d8bd13568e71aa8fc86fc1fe9043d1',
  39. 'Frank jagt im komplett verwahrlosten Taxi quer durch Bayern'),
  40. ]
  41. def get_tests(config={}):
  42. from Cryptodome.Hash import SHA224
  43. from .common import make_hash_tests
  44. return make_hash_tests(SHA224, "SHA224", test_data,
  45. digest_size=28,
  46. oid='2.16.840.1.101.3.4.2.4')
  47. if __name__ == '__main__':
  48. import unittest
  49. suite = lambda: unittest.TestSuite(get_tests())
  50. unittest.main(defaultTest='suite')
  51. # vim:set ts=4 sw=4 sts=4 expandtab: