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, tomstdenis (at) gmail.com, http://libtomcrypt.com 10 */ 11 #include "tomcrypt.h" 12 #include <stdarg.h> 13 14 /** 15 @file omac_memory_multi.c 16 OMAC1 support, process multiple blocks of memory, Tom St Denis 17 */ 18 19 #ifdef LTC_OMAC 20 21 /** 22 OMAC multiple blocks of memory 23 @param cipher The index of the desired cipher 24 @param key The secret key 25 @param keylen The length of the secret key (octets) 26 @param out [out] The destination of the authentication tag 27 @param outlen [in/out] The max size and resulting size of the authentication tag (octets) 28 @param in The data to send through OMAC 29 @param inlen The length of the data to send through OMAC (octets) 30 @param ... tuples of (data,len) pairs to OMAC, terminated with a (NULL,x) (x=don't care) 31 @return CRYPT_OK if successful 32 */ 33 int omac_memory_multi(int cipher, 34 const unsigned char *key, unsigned long keylen, 35 unsigned char *out, unsigned long *outlen, 36 const unsigned char *in, unsigned long inlen, ...) 37 { 38 int err; 39 omac_state *omac; 40 va_list args; 41 const unsigned char *curptr; 42 unsigned long curlen; 43 44 LTC_ARGCHK(key != NULL); 45 LTC_ARGCHK(in != NULL); 46 LTC_ARGCHK(out != NULL); 47 LTC_ARGCHK(outlen != NULL); 48 49 /* allocate ram for omac state */ 50 omac = XMALLOC(sizeof(omac_state)); 51 if (omac == NULL) { 52 return CRYPT_MEM; 53 } 54 55 /* omac process the message */ 56 if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) { 57 goto LBL_ERR; 58 } 59 va_start(args, inlen); 60 curptr = in; 61 curlen = inlen; 62 for (;;) { 63 /* process buf */ 64 if ((err = omac_process(omac, curptr, curlen)) != CRYPT_OK) { 65 goto LBL_ERR; 66 } 67 /* step to next */ 68 curptr = va_arg(args, const unsigned char*); 69 if (curptr == NULL) { 70 break; 71 } 72 curlen = va_arg(args, unsigned long); 73 } 74 if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) { 75 goto LBL_ERR; 76 } 77 LBL_ERR: 78 #ifdef LTC_CLEAN_STACK 79 zeromem(omac, sizeof(omac_state)); 80 #endif 81 XFREE(omac); 82 va_end(args); 83 return err; 84 } 85 86 #endif 87 88 /* $Source: /cvs/libtom/libtomcrypt/src/mac/omac/omac_memory_multi.c,v $ */ 89 /* $Revision: 1.5 $ */ 90 /* $Date: 2006/11/03 00:39:49 $ */ 91