1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
13 OMAC1 support, process data, Tom St Denis
20 Process data through OMAC
21 @param omac The OMAC state
22 @param in The input data to send through OMAC
23 @param inlen The length of the input (octets)
24 @return CRYPT_OK if successful
26 int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen)
31 LTC_ARGCHK(omac != NULL);
32 LTC_ARGCHK(in != NULL);
33 if ((err = cipher_is_valid(omac->cipher_idx)) != CRYPT_OK) {
37 if ((omac->buflen > (int)sizeof(omac->block)) || (omac->buflen < 0) ||
38 (omac->blklen > (int)sizeof(omac->block)) || (omac->buflen > omac->blklen)) {
39 return CRYPT_INVALID_ARG;
44 unsigned long blklen = cipher_descriptor[omac->cipher_idx].block_length;
46 if (omac->buflen == 0 && inlen > blklen) {
48 for (x = 0; x < (inlen - blklen); x += blklen) {
49 for (y = 0; y < blklen; y += sizeof(LTC_FAST_TYPE)) {
50 *(LTC_FAST_TYPE_PTR_CAST(&omac->prev[y])) ^= *(LTC_FAST_TYPE_PTR_CAST(&in[y]));
53 if ((err = cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->prev, omac->prev, &omac->key)) != CRYPT_OK) {
63 /* ok if the block is full we xor in prev, encrypt and replace prev */
64 if (omac->buflen == omac->blklen) {
65 for (x = 0; x < (unsigned long)omac->blklen; x++) {
66 omac->block[x] ^= omac->prev[x];
68 if ((err = cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->block, omac->prev, &omac->key)) != CRYPT_OK) {
75 n = MIN(inlen, (unsigned long)(omac->blklen - omac->buflen));
76 XMEMCPY(omac->block + omac->buflen, in, n);
88 /* ref: $Format:%D$ */
89 /* git commit: $Format:%H$ */
90 /* commit time: $Format:%ai$ */