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.

60 lines
1.9 KiB

  1. #define TEST_NAME "auth"
  2. #include "cmptest.h"
  3. /* "Test Case 2" from RFC 4231 */
  4. unsigned char key[32] = "Jefe";
  5. unsigned char c[] = "what do ya want for nothing?";
  6. /* Hacker manifesto */
  7. unsigned char key2[] = "Another one got caught today, it's all over the papers. \"Teenager Arrested in Computer Crime Scandal\", \"Hacker Arrested after Bank Tampering\"... Damn kids. They're all alike.";
  8. unsigned char a[crypto_auth_BYTES];
  9. unsigned char a2[crypto_auth_hmacsha512_BYTES];
  10. int main(void)
  11. {
  12. crypto_auth_hmacsha512_state st;
  13. int i;
  14. crypto_auth(a, c, sizeof c - 1U, key);
  15. for (i = 0; i < sizeof a; ++i) {
  16. printf(",0x%02x", (unsigned int)a[i]);
  17. if (i % 8 == 7)
  18. printf("\n");
  19. }
  20. printf("\n");
  21. crypto_auth_hmacsha512_init(&st, key, sizeof key);
  22. crypto_auth_hmacsha512_update(&st, c, 1U);
  23. crypto_auth_hmacsha512_update(&st, c, sizeof c - 2U);
  24. crypto_auth_hmacsha512_final(&st, a2);
  25. for (i = 0; i < sizeof a2; ++i) {
  26. printf(",0x%02x", (unsigned int)a2[i]);
  27. if (i % 8 == 7)
  28. printf("\n");
  29. }
  30. printf("\n");
  31. crypto_auth_hmacsha512_init(&st, key2, sizeof key2);
  32. crypto_auth_hmacsha512_update(&st, c, 1U);
  33. crypto_auth_hmacsha512_update(&st, c, sizeof c - 2U);
  34. crypto_auth_hmacsha512_final(&st, a2);
  35. for (i = 0; i < sizeof a2; ++i) {
  36. printf(",0x%02x", (unsigned int)a2[i]);
  37. if (i % 8 == 7)
  38. printf("\n");
  39. }
  40. assert(crypto_auth_bytes() > 0U);
  41. assert(crypto_auth_keybytes() > 0U);
  42. assert(strcmp(crypto_auth_primitive(), "hmacsha512256") == 0);
  43. assert(crypto_auth_hmacsha256_bytes() > 0U);
  44. assert(crypto_auth_hmacsha256_keybytes() > 0U);
  45. assert(crypto_auth_hmacsha512_bytes() > 0U);
  46. assert(crypto_auth_hmacsha512_keybytes() > 0U);
  47. assert(crypto_auth_hmacsha512256_bytes() == crypto_auth_bytes());
  48. assert(crypto_auth_hmacsha512256_keybytes() == crypto_auth_keybytes());
  49. return 0;
  50. }