General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.1 KiB

  1. #include "rc6_generic.hpp"
  2. #include "test_scaffold.h"
  3. #include <iostream>
  4. #include <ios>
  5. struct RC6test : public test_scaffold {
  6. RC6test() {
  7. name = __FILE__ ":1";
  8. }
  9. virtual int run() {
  10. using rc = RC6<>;
  11. auto test = [](rc::key_type key, rc::block_type plaintext, rc::block_type expected) -> bool {
  12. auto cipher = rc{key};
  13. plaintext = cipher.encrypt(plaintext);
  14. return plaintext != expected;
  15. };
  16. auto res = 0;
  17. res += test(
  18. {0, 0, 0, 0},
  19. {0,0,0,0},
  20. {0x8fc3a536,0x56b1f778,0xc129df4e,0x9848a41e}
  21. );
  22. res += test(
  23. {0x80000000, 0x00000000, 0x00000000, 0x00000000},
  24. {0,0,0,0},
  25. {0x1AD578A0, 0x2A081628, 0x50A15A15, 0x52A17AD4}
  26. );
  27. return res;
  28. }
  29. };
  30. append_test dummy_szfhu5463(new RC6test{});
  31. struct RC6test2 : public test_scaffold {
  32. RC6test2() {
  33. name = __FILE__ ":2";
  34. }
  35. virtual int run() {
  36. using rc = RC6<>;
  37. rc::key_type key{0,0,0,0};
  38. rc::block_type plaintext{0,0,0,0};
  39. rc::block_type expected{0,0,0,0};
  40. auto cipher = rc{key};
  41. auto plaintext2 = cipher.encrypt(plaintext);
  42. auto plaintext3 = cipher.decrypt(plaintext2);
  43. return plaintext3 != expected;
  44. }
  45. };
  46. append_test dummy_szmltz63(new RC6test2{});