~ubuntu-branches/ubuntu/utopic/dropbear/utopic-proposed

« back to all changes in this revision

Viewing changes to libtomcrypt/src/mac/omac/omac_process.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Johnston
  • Date: 2005-12-08 19:20:21 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051208192021-nyp9rwnt77nsg6ty
Tags: 0.47-1
* New upstream release.
* SECURITY: Fix incorrect buffer sizing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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@gmail.com, http://libtomcrypt.org
 
10
 */
 
11
#include "tomcrypt.h"
 
12
 
 
13
/** 
 
14
  @file omac_process.c
 
15
  OMAC1 support, process data, Tom St Denis
 
16
*/
 
17
 
 
18
 
 
19
#ifdef OMAC
 
20
 
 
21
/** 
 
22
   Process data through OMAC
 
23
   @param omac     The OMAC state
 
24
   @param in       The input data to send through OMAC
 
25
   @param inlen    The length of the input (octets)
 
26
   @return CRYPT_OK if successful
 
27
*/
 
28
int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen)
 
29
{
 
30
   unsigned long n, x;
 
31
   int           err;
 
32
 
 
33
   LTC_ARGCHK(omac  != NULL);
 
34
   LTC_ARGCHK(in    != NULL);
 
35
   if ((err = cipher_is_valid(omac->cipher_idx)) != CRYPT_OK) {
 
36
      return err;
 
37
   }
 
38
 
 
39
   if ((omac->buflen > (int)sizeof(omac->block)) || (omac->buflen < 0) ||
 
40
       (omac->blklen > (int)sizeof(omac->block)) || (omac->buflen > omac->blklen)) {
 
41
      return CRYPT_INVALID_ARG;
 
42
   }
 
43
 
 
44
#ifdef LTC_FAST
 
45
   if (omac->buflen == 0 && inlen > 16) {
 
46
      int y;
 
47
      for (x = 0; x < (inlen - 16); x += 16) {
 
48
          for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
 
49
              *((LTC_FAST_TYPE*)(&omac->prev[y])) ^= *((LTC_FAST_TYPE*)(&in[y]));
 
50
          }
 
51
          in += 16;
 
52
          cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->prev, omac->prev, &omac->key);
 
53
      }
 
54
      inlen -= x;
 
55
    }
 
56
#endif
 
57
 
 
58
   while (inlen != 0) { 
 
59
       /* ok if the block is full we xor in prev, encrypt and replace prev */
 
60
       if (omac->buflen == omac->blklen) {
 
61
          for (x = 0; x < (unsigned long)omac->blklen; x++) {
 
62
              omac->block[x] ^= omac->prev[x];
 
63
          }
 
64
          cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->block, omac->prev, &omac->key);
 
65
          omac->buflen = 0;
 
66
       }
 
67
 
 
68
       /* add bytes */
 
69
       n = MIN(inlen, (unsigned long)(omac->blklen - omac->buflen));
 
70
       XMEMCPY(omac->block + omac->buflen, in, n);
 
71
       omac->buflen  += n;
 
72
       inlen         -= n;
 
73
       in            += n;
 
74
   }
 
75
 
 
76
   return CRYPT_OK;
 
77
}
 
78
 
 
79
#endif
 
80
 
 
81
 
 
82
/* $Source: /cvs/libtom/libtomcrypt/src/mac/omac/omac_process.c,v $ */
 
83
/* $Revision: 1.6 $ */
 
84
/* $Date: 2005/05/05 14:35:58 $ */