eax_encrypt_authenticate_memory.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* LibTomCrypt, modular cryptographic library -- Tom St Denis
  2. *
  3. * LibTomCrypt is a library that provides various cryptographic
  4. * algorithms in a highly modular and flexible manner.
  5. *
  6. * The library is free for all purposes without any express
  7. * guarantee it works.
  8. *
  9. * Tom St Denis, [email protected], http://libtomcrypt.org
  10. */
  11. /* EAX Implementation by Tom St Denis */
  12. #include "mycrypt.h"
  13. #ifdef EAX_MODE
  14. int eax_encrypt_authenticate_memory(int cipher,
  15. const unsigned char *key, unsigned long keylen,
  16. const unsigned char *nonce, unsigned long noncelen,
  17. const unsigned char *header, unsigned long headerlen,
  18. const unsigned char *pt, unsigned long ptlen,
  19. unsigned char *ct,
  20. unsigned char *tag, unsigned long *taglen)
  21. {
  22. int err;
  23. eax_state *eax;
  24. eax = XMALLOC(sizeof(eax_state));
  25. if ((err = eax_init(eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
  26. goto __ERR;
  27. }
  28. if ((err = eax_encrypt(eax, pt, ct, ptlen)) != CRYPT_OK) {
  29. goto __ERR;
  30. }
  31. if ((err = eax_done(eax, tag, taglen)) != CRYPT_OK) {
  32. goto __ERR;
  33. }
  34. err = CRYPT_OK;
  35. __ERR:
  36. #ifdef CLEAN_STACK
  37. zeromem(eax, sizeof(eax_state));
  38. #endif
  39. XFREE(eax);
  40. return err;
  41. }
  42. #endif