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

« back to all changes in this revision

Viewing changes to libtomcrypt/ocb_done_decrypt.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
 
/* OCB Implementation by Tom St Denis */
13
 
#include "mycrypt.h"
14
 
 
15
 
#ifdef OCB_MODE
16
 
 
17
 
int ocb_done_decrypt(ocb_state *ocb, 
18
 
                     const unsigned char *ct,  unsigned long ctlen,
19
 
                           unsigned char *pt, 
20
 
                     const unsigned char *tag, unsigned long taglen, int *res)
21
 
{
22
 
   int err;
23
 
   unsigned char *tagbuf;
24
 
   unsigned long tagbuflen;
25
 
 
26
 
   _ARGCHK(ocb != NULL);
27
 
   _ARGCHK(pt  != NULL);
28
 
   _ARGCHK(ct  != NULL);
29
 
   _ARGCHK(tag != NULL);
30
 
   _ARGCHK(res != NULL);
31
 
 
32
 
   /* default to failed */
33
 
   *res = 0;
34
 
 
35
 
   /* allocate memory */
36
 
   tagbuf = XMALLOC(MAXBLOCKSIZE);
37
 
   if (tagbuf == NULL) {
38
 
      return CRYPT_MEM;
39
 
   }
40
 
 
41
 
   tagbuflen = MAXBLOCKSIZE;
42
 
   if ((err = __ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) {
43
 
      goto __ERR;
44
 
   }
45
 
 
46
 
   if (taglen <= tagbuflen && memcmp(tagbuf, tag, taglen) == 0) {
47
 
      *res = 1;
48
 
   }
49
 
 
50
 
   err = CRYPT_OK;
51
 
__ERR:
52
 
#ifdef CLEAN_STACK
53
 
   zeromem(tagbuf, MAXBLOCKSIZE);
54
 
#endif
55
 
 
56
 
   XFREE(tagbuf);
57
 
 
58
 
   return err;
59
 
}
60
 
 
61
 
#endif
62