multi.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* test the multi helpers... */
  2. #include <tomcrypt.h>
  3. int main(void)
  4. {
  5. unsigned char key[16], buf[2][MAXBLOCKSIZE];
  6. unsigned long len, len2;
  7. /* register algos */
  8. register_hash(&sha256_desc);
  9. register_cipher(&aes_desc);
  10. /* HASH testing */
  11. len = sizeof(buf[0]);
  12. hash_memory(find_hash("sha256"), (unsigned char*)"hello", 5, buf[0], &len);
  13. len2 = sizeof(buf[0]);
  14. hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"hello", 5, NULL);
  15. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  16. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  17. return EXIT_FAILURE;
  18. }
  19. len2 = sizeof(buf[0]);
  20. hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL, 0);
  21. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  22. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  23. return EXIT_FAILURE;
  24. }
  25. len2 = sizeof(buf[0]);
  26. hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
  27. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  28. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  29. return EXIT_FAILURE;
  30. }
  31. /* LTC_HMAC */
  32. len = sizeof(buf[0]);
  33. hmac_memory(find_hash("sha256"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
  34. len2 = sizeof(buf[0]);
  35. hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL);
  36. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  37. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  38. return EXIT_FAILURE;
  39. }
  40. len2 = sizeof(buf[0]);
  41. hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
  42. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  43. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  44. return EXIT_FAILURE;
  45. }
  46. len2 = sizeof(buf[0]);
  47. hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
  48. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  49. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  50. return EXIT_FAILURE;
  51. }
  52. /* LTC_OMAC */
  53. #ifdef LTC_OMAC
  54. len = sizeof(buf[0]);
  55. omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
  56. len2 = sizeof(buf[0]);
  57. omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL);
  58. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  59. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  60. return EXIT_FAILURE;
  61. }
  62. len2 = sizeof(buf[0]);
  63. omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
  64. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  65. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  66. return EXIT_FAILURE;
  67. }
  68. len2 = sizeof(buf[0]);
  69. omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
  70. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  71. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  72. return EXIT_FAILURE;
  73. }
  74. #endif
  75. /* PMAC */
  76. #ifdef LTC_PMAC
  77. len = sizeof(buf[0]);
  78. pmac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
  79. len2 = sizeof(buf[0]);
  80. pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL);
  81. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  82. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  83. return EXIT_FAILURE;
  84. }
  85. len2 = sizeof(buf[0]);
  86. pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
  87. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  88. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  89. return EXIT_FAILURE;
  90. }
  91. len2 = sizeof(buf[0]);
  92. pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
  93. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  94. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  95. return EXIT_FAILURE;
  96. }
  97. #endif
  98. printf("All passed\n");
  99. return EXIT_SUCCESS;
  100. }
  101. /* $Source$ */
  102. /* $Revision$ */
  103. /* $Date$ */