pmac_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. /* PMAC implementation by Tom St Denis */
  12. #include "mycrypt.h"
  13. #ifdef PMAC
  14. int pmac_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. pmac_state *pmac;
  21. _ARGCHK(key != NULL);
  22. _ARGCHK(msg != NULL);
  23. _ARGCHK(out != NULL);
  24. _ARGCHK(outlen != NULL);
  25. /* allocate ram for pmac state */
  26. pmac = XMALLOC(sizeof(pmac_state));
  27. if (pmac == NULL) {
  28. return CRYPT_MEM;
  29. }
  30. if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) {
  31. goto __ERR;
  32. }
  33. if ((err = pmac_process(pmac, msg, msglen)) != CRYPT_OK) {
  34. goto __ERR;
  35. }
  36. if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) {
  37. goto __ERR;
  38. }
  39. err = CRYPT_OK;
  40. __ERR:
  41. #ifdef CLEAN_STACK
  42. zeromem(pmac, sizeof(pmac_state));
  43. #endif
  44. XFREE(pmac);
  45. return err;
  46. }
  47. #endif