test_SHAd256.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. #
  3. # SelfTest/Random/Fortuna/test_SHAd256.py: Self-test for the SHAd256 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.Random.Fortuna.SHAd256"""
  25. __revision__ = "$Id$"
  26. from Crypto.Util.py3compat import *
  27. # This is a list of (expected_result, input[, description]) tuples.
  28. test_data = [
  29. # I could not find any test vectors for SHAd256, so I made these vectors by
  30. # feeding some sample data into several plain SHA256 implementations
  31. # (including OpenSSL, the "sha256sum" tool, and this implementation).
  32. # This is a subset of the resulting test vectors. The complete list can be
  33. # found at: http://www.dlitz.net/crypto/shad256-test-vectors/
  34. ('5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456',
  35. '', "'' (empty string)"),
  36. ('4f8b42c22dd3729b519ba6f68d2da7cc5b2d606d05daed5ad5128cc03e6c6358',
  37. 'abc'),
  38. ('0cffe17f68954dac3a84fb1458bd5ec99209449749b2b308b7cb55812f9563af',
  39. 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')
  40. ]
  41. def get_tests(config={}):
  42. from Crypto.Random.Fortuna import SHAd256
  43. from Crypto.SelfTest.Hash.common import make_hash_tests
  44. return make_hash_tests(SHAd256, "SHAd256", test_data, 32)
  45. if __name__ == '__main__':
  46. import unittest
  47. suite = lambda: unittest.TestSuite(get_tests())
  48. unittest.main(defaultTest='suite')
  49. # vim:set ts=4 sw=4 sts=4 expandtab: