1
0

CryptoAuth_randnonce_test.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "crypto/CryptoAuth_pvt.h"
  16. #include "util/Hex.h"
  17. #include "util/Bits.h"
  18. #include <stdio.h>
  19. #define HELLOWORLDLOWER "hello world"
  20. #define HELLOWORLDLEN 12
  21. static void encryptRndNonceTest()
  22. {
  23. uint8_t buff[44];
  24. Bits_memset(buff, 0, 44);
  25. uint8_t nonce[24];
  26. Bits_memset(nonce, 0, 24);
  27. uint8_t secret[32];
  28. Bits_memset(secret, 0, 32);
  29. struct Message m = Message_foreign(44, buff);
  30. Er_assert(Message_epop(&m, NULL, 44));
  31. Er_assert(Message_epush(&m, HELLOWORLDLOWER, CString_strlen(HELLOWORLDLOWER)+1));
  32. CryptoAuth_encryptRndNonce(nonce, &m, secret);
  33. uint8_t* expected = (uint8_t*) "1391ac5d03ba9f7099bffbb6e6c69d67ae5bd79391a5b94399b293dc";
  34. uint8_t output[57];
  35. Hex_encode(output, 57, m.msgbytes, Message_getLength(&m));
  36. printf("\n%s\n%s\n", (char*) expected, (char*) output);
  37. Assert_true(!Bits_memcmp(expected, output, 56));
  38. Assert_true(!CryptoAuth_decryptRndNonce(nonce, &m, secret));
  39. Assert_true(Message_getLength(&m) == HELLOWORLDLEN
  40. && !Bits_memcmp(m.msgbytes, HELLOWORLDLOWER, Message_getLength(&m)));
  41. }
  42. int main()
  43. {
  44. encryptRndNonceTest();
  45. return 0;
  46. }