omac_memory.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. /* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */
  12. #include "mycrypt.h"
  13. #ifdef OMAC
  14. int omac_memory(int cipher,
  15. const unsigned char *key, unsigned long keylen,
  16. const unsigned char *msg, unsigned long msglen,
  17. unsigned char *out, unsigned long *outlen)
  18. {
  19. int err;
  20. omac_state *omac;
  21. _ARGCHK(key != NULL);
  22. _ARGCHK(msg != NULL);
  23. _ARGCHK(out != NULL);
  24. _ARGCHK(outlen != NULL);
  25. /* allocate ram for omac state */
  26. omac = XMALLOC(sizeof(omac_state));
  27. if (omac == NULL) {
  28. return CRYPT_MEM;
  29. }
  30. /* omac process the message */
  31. if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) {
  32. goto __ERR;
  33. }
  34. if ((err = omac_process(omac, msg, msglen)) != CRYPT_OK) {
  35. goto __ERR;
  36. }
  37. if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) {
  38. goto __ERR;
  39. }
  40. err = CRYPT_OK;
  41. __ERR:
  42. #ifdef CLEAN_STACK
  43. zeromem(omac, sizeof(omac_state));
  44. #endif
  45. XFREE(omac);
  46. return err;
  47. }
  48. #endif