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

« back to all changes in this revision

Viewing changes to libtomcrypt/ocb_encrypt_authenticate_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
 
/* OCB Implementation by Tom St Denis */
13
 
#include "mycrypt.h"
14
 
 
15
 
#ifdef OCB_MODE
16
 
 
17
 
int ocb_encrypt_authenticate_memory(int cipher,
18
 
    const unsigned char *key,    unsigned long keylen,
19
 
    const unsigned char *nonce,  
20
 
    const unsigned char *pt,     unsigned long ptlen,
21
 
          unsigned char *ct,
22
 
          unsigned char *tag,    unsigned long *taglen)
23
 
{
24
 
   int err;
25
 
   ocb_state *ocb;
26
 
 
27
 
   _ARGCHK(key    != NULL);
28
 
   _ARGCHK(nonce  != NULL);
29
 
   _ARGCHK(pt     != NULL);
30
 
   _ARGCHK(ct     != NULL);
31
 
   _ARGCHK(tag    != NULL);
32
 
   _ARGCHK(taglen != NULL);
33
 
 
34
 
   /* allocate ram */
35
 
   ocb = XMALLOC(sizeof(ocb_state));
36
 
   if (ocb == NULL) {
37
 
      return CRYPT_MEM;
38
 
   }
39
 
 
40
 
   if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
41
 
      goto __ERR;
42
 
   }
43
 
 
44
 
   while (ptlen > (unsigned long)ocb->block_len) {
45
 
        if ((err = ocb_encrypt(ocb, pt, ct)) != CRYPT_OK) {
46
 
           goto __ERR;
47
 
        }
48
 
        ptlen   -= ocb->block_len;
49
 
        pt      += ocb->block_len;
50
 
        ct      += ocb->block_len;
51
 
   }
52
 
 
53
 
   err = ocb_done_encrypt(ocb, pt, ptlen, ct, tag, taglen);
54
 
__ERR:
55
 
#ifdef CLEAN_STACK
56
 
   zeromem(ocb, sizeof(ocb_state));
57
 
#endif
58
 
 
59
 
   XFREE(ocb);
60
 
 
61
 
   return err;
62
 
}
63
 
 
64
 
#endif