test_CAST.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. #
  3. # SelfTest/Cipher/CAST.py: Self-test for the CAST-128 (CAST5) cipher
  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.Cipher.CAST"""
  25. __revision__ = "$Id$"
  26. from Crypto.Util.py3compat import *
  27. # This is a list of (plaintext, ciphertext, key) tuples.
  28. test_data = [
  29. # Test vectors from RFC 2144, B.1
  30. ('0123456789abcdef', '238b4fe5847e44b2',
  31. '0123456712345678234567893456789a',
  32. '128-bit key'),
  33. ('0123456789abcdef', 'eb6a711a2c02271b',
  34. '01234567123456782345',
  35. '80-bit key'),
  36. ('0123456789abcdef', '7ac816d16e9b302e',
  37. '0123456712',
  38. '40-bit key'),
  39. ]
  40. def get_tests(config={}):
  41. from Crypto.Cipher import CAST
  42. from common import make_block_tests
  43. return make_block_tests(CAST, "CAST", test_data)
  44. if __name__ == '__main__':
  45. import unittest
  46. suite = lambda: unittest.TestSuite(get_tests())
  47. unittest.main(defaultTest='suite')
  48. # vim:set ts=4 sw=4 sts=4 expandtab: