idea_test.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include "idea.h"
  4. #include "io.h"
  5. static void test1(void)
  6. {
  7. bit_array test1_bits[IDEA_INITIAL_KEYS * 16] = {0};
  8. short test1_index = 0;
  9. for (uint16_t i = 0; i < 8; i++) {
  10. hex2bits(test1_bits, test1_index, i);
  11. test1_index += 16;
  12. }
  13. uint16_t subkeys[IDEA_SUBKEYS] = {0};
  14. generate_subkeys(test1_bits, subkeys);
  15. static const uint16_t correct_subkeys[IDEA_SUBKEYS] = {
  16. 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
  17. 0x0200, 0x0400, 0x0600, 0x0800, 0x0A00, 0x0C00, 0x0E00, 0x0000,
  18. 0x000C, 0x0010, 0x0014, 0x0018, 0x001C, 0x0000, 0x0004, 0x0008,
  19. 0x2000, 0x2800, 0x3000, 0x3800, 0x0000, 0x0800, 0x1000, 0x1800,
  20. 0x0060, 0x0070, 0x0000, 0x0010, 0x0020, 0x0030, 0x0040, 0x0050,
  21. 0xE000, 0x0000, 0x2000, 0x4000, 0x6000, 0x8000, 0xA000, 0xC000,
  22. 0x0040, 0x0080, 0x00C0, 0x0100
  23. };
  24. for (int i = 0; i < IDEA_SUBKEYS; i++) {
  25. assert(subkeys[i] == correct_subkeys[i]);
  26. }
  27. printf("Test1 Passed!\n");
  28. }
  29. int main(void)
  30. {
  31. test1();
  32. printf("All Tests Passed!\n");
  33. return 0;
  34. }