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

« back to all changes in this revision

Viewing changes to libtomcrypt/src/mac/omac/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@gmail.com, http://libtomcrypt.org
 
10
 */
 
11
#include "tomcrypt.h"
 
12
 
 
13
/** 
 
14
  @file omac_done.c
 
15
  OMAC1 support, terminate a stream, Tom St Denis
 
16
*/
 
17
 
 
18
#ifdef OMAC
 
19
 
 
20
/**
 
21
  Terminate an OMAC stream
 
22
  @param omac   The OMAC state
 
23
  @param out    [out] Destination for the authentication tag
 
24
  @param outlen [in/out]  The max size and resulting size of the authentication tag
 
25
  @return CRYPT_OK if successful
 
26
*/
 
27
int omac_done(omac_state *omac, unsigned char *out, unsigned long *outlen)
 
28
{
 
29
   int       err, mode;
 
30
   unsigned  x;
 
31
 
 
32
   LTC_ARGCHK(omac   != NULL);
 
33
   LTC_ARGCHK(out    != NULL);
 
34
   LTC_ARGCHK(outlen != 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
   /* figure out mode */
 
45
   if (omac->buflen != omac->blklen) {
 
46
      /* add the 0x80 byte */
 
47
      omac->block[omac->buflen++] = 0x80;
 
48
 
 
49
      /* pad with 0x00 */
 
50
      while (omac->buflen < omac->blklen) {
 
51
         omac->block[omac->buflen++] = 0x00;
 
52
      }
 
53
      mode = 1;
 
54
   } else {
 
55
      mode = 0;
 
56
   }
 
57
 
 
58
   /* now xor prev + Lu[mode] */
 
59
   for (x = 0; x < (unsigned)omac->blklen; x++) {
 
60
       omac->block[x] ^= omac->prev[x] ^ omac->Lu[mode][x];
 
61
   }
 
62
 
 
63
   /* encrypt it */
 
64
   cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->block, omac->block, &omac->key);
 
65
   cipher_descriptor[omac->cipher_idx].done(&omac->key);
 
66
 
 
67
   /* output it */
 
68
   for (x = 0; x < (unsigned)omac->blklen && x < *outlen; x++) {
 
69
       out[x] = omac->block[x];
 
70
   }
 
71
   *outlen = x;
 
72
 
 
73
#ifdef LTC_CLEAN_STACK
 
74
   zeromem(omac, sizeof(*omac));
 
75
#endif
 
76
   return CRYPT_OK;
 
77
}
 
78
 
 
79
#endif
 
80
 
 
81
 
 
82
/* $Source: /cvs/libtom/libtomcrypt/src/mac/omac/omac_done.c,v $ */
 
83
/* $Revision: 1.4 $ */
 
84
/* $Date: 2005/05/05 14:35:58 $ */