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

« back to all changes in this revision

Viewing changes to libtomcrypt/omac_done.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@iahu.ca, http://libtomcrypt.org
10
 
 */
11
 
/* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */
12
 
#include "mycrypt.h"
13
 
 
14
 
#ifdef OMAC
15
 
 
16
 
int omac_done(omac_state *state, unsigned char *out, unsigned long *outlen)
17
 
{
18
 
   int       err, mode;
19
 
   unsigned  x;
20
 
 
21
 
   _ARGCHK(state  != NULL);
22
 
   _ARGCHK(out    != NULL);
23
 
   _ARGCHK(outlen != NULL);
24
 
   if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
25
 
      return err;
26
 
   }
27
 
 
28
 
   if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) ||
29
 
       (state->blklen > (int)sizeof(state->block)) || (state->buflen > state->blklen)) {
30
 
      return CRYPT_INVALID_ARG;
31
 
   }
32
 
 
33
 
   /* figure out mode */
34
 
   if (state->buflen != state->blklen) {
35
 
      /* add the 0x80 byte */
36
 
      state->block[state->buflen++] = 0x80;
37
 
 
38
 
      /* pad with 0x00 */
39
 
      while (state->buflen < state->blklen) {
40
 
         state->block[state->buflen++] = 0x00;
41
 
      }
42
 
      mode = 1;
43
 
   } else {
44
 
      mode = 0;
45
 
   }
46
 
 
47
 
   /* now xor prev + Lu[mode] */
48
 
   for (x = 0; x < (unsigned)state->blklen; x++) {
49
 
       state->block[x] ^= state->prev[x] ^ state->Lu[mode][x];
50
 
   }
51
 
 
52
 
   /* encrypt it */
53
 
   cipher_descriptor[state->cipher_idx].ecb_encrypt(state->block, state->block, &state->key);
54
 
 
55
 
   /* output it */
56
 
   for (x = 0; x < (unsigned)state->blklen && x < *outlen; x++) {
57
 
       out[x] = state->block[x];
58
 
   }
59
 
   *outlen = x;
60
 
 
61
 
#ifdef CLEAN_STACK
62
 
   zeromem(state, sizeof(*state));
63
 
#endif
64
 
   return CRYPT_OK;
65
 
}
66
 
 
67
 
#endif
68