multi.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. len = sizeof(buf[0]);
  54. omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
  55. len2 = sizeof(buf[0]);
  56. omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL);
  57. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  58. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  59. return EXIT_FAILURE;
  60. }
  61. len2 = sizeof(buf[0]);
  62. omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
  63. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  64. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  65. return EXIT_FAILURE;
  66. }
  67. len2 = sizeof(buf[0]);
  68. omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
  69. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  70. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  71. return EXIT_FAILURE;
  72. }
  73. /* PMAC */
  74. len = sizeof(buf[0]);
  75. pmac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
  76. len2 = sizeof(buf[0]);
  77. pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL);
  78. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  79. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  80. return EXIT_FAILURE;
  81. }
  82. len2 = sizeof(buf[0]);
  83. pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
  84. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  85. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  86. return EXIT_FAILURE;
  87. }
  88. len2 = sizeof(buf[0]);
  89. pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
  90. if (len != len2 || memcmp(buf[0], buf[1], len)) {
  91. printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
  92. return EXIT_FAILURE;
  93. }
  94. printf("All passed\n");
  95. return EXIT_SUCCESS;
  96. }
  97. /* $Source$ */
  98. /* $Revision$ */
  99. /* $Date$ */