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

« back to all changes in this revision

Viewing changes to libtomcrypt/eax_decrypt_verify_memory.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
 
 
12
 
/* EAX Implementation by Tom St Denis */
13
 
#include "mycrypt.h"
14
 
 
15
 
#ifdef EAX_MODE
16
 
 
17
 
int eax_decrypt_verify_memory(int cipher,
18
 
    const unsigned char *key,    unsigned long keylen,
19
 
    const unsigned char *nonce,  unsigned long noncelen,
20
 
    const unsigned char *header, unsigned long headerlen,
21
 
    const unsigned char *ct,     unsigned long ctlen,
22
 
          unsigned char *pt,
23
 
          unsigned char *tag,    unsigned long taglen,
24
 
          int           *res)
25
 
{
26
 
   int            err;
27
 
   eax_state     *eax;
28
 
   unsigned char *buf;
29
 
   unsigned long  buflen;
30
 
 
31
 
   _ARGCHK(res != NULL);
32
 
 
33
 
   /* default to zero */
34
 
   *res = 0;
35
 
 
36
 
   /* allocate ram */
37
 
   buf = XMALLOC(taglen);
38
 
   eax = XMALLOC(sizeof(eax_state));
39
 
   if (eax == NULL || buf == NULL) {
40
 
      if (eax != NULL) {
41
 
         XFREE(eax);
42
 
      }
43
 
      if (buf != NULL) {
44
 
         XFREE(buf);
45
 
      }
46
 
      return CRYPT_MEM;
47
 
   }
48
 
 
49
 
   if ((err = eax_init(eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
50
 
      goto __ERR;
51
 
   }
52
 
 
53
 
   if ((err = eax_decrypt(eax, ct, pt, ctlen)) != CRYPT_OK) {
54
 
      goto __ERR;
55
 
   }
56
 
 
57
 
   buflen = taglen;
58
 
   if ((err = eax_done(eax, buf, &buflen)) != CRYPT_OK) {
59
 
      goto __ERR;
60
 
   }
61
 
 
62
 
   /* compare tags */
63
 
   if (buflen >= taglen && memcmp(buf, tag, taglen) == 0) {
64
 
      *res = 1;
65
 
   }
66
 
   
67
 
   err = CRYPT_OK;
68
 
__ERR:
69
 
#ifdef CLEAN_STACK
70
 
   zeromem(buf, taglen);
71
 
   zeromem(eax, sizeof(eax_state));
72
 
#endif
73
 
 
74
 
   XFREE(eax);
75
 
   XFREE(buf);
76
 
 
77
 
   return err;
78
 
}
79
 
 
80
 
#endif