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

« back to all changes in this revision

Viewing changes to libtomcrypt/src/encauth/ocb/ocb_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@gmail.com, http://libtomcrypt.org
 
10
 */
 
11
 
 
12
/**
 
13
   @file ocb_decrypt.c
 
14
   OCB implementation, decrypt data, by Tom St Denis 
 
15
*/
 
16
#include "tomcrypt.h"
 
17
 
 
18
#ifdef OCB_MODE
 
19
 
 
20
/**
 
21
  Decrypt a block with OCB.
 
22
  @param ocb    The OCB state
 
23
  @param ct     The ciphertext (length of the block size of the block cipher)
 
24
  @param pt     [out] The plaintext (length of ct)
 
25
  @return CRYPT_OK if successful
 
26
*/
 
27
int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt)
 
28
{
 
29
   unsigned char Z[MAXBLOCKSIZE], tmp[MAXBLOCKSIZE];
 
30
   int err, x;
 
31
 
 
32
   LTC_ARGCHK(ocb != NULL);
 
33
   LTC_ARGCHK(pt  != NULL);
 
34
   LTC_ARGCHK(ct  != NULL);
 
35
 
 
36
   /* check if valid cipher */
 
37
   if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
 
38
      return err;
 
39
   }
 
40
   LTC_ARGCHK(cipher_descriptor[ocb->cipher].ecb_decrypt != NULL);
 
41
   
 
42
   /* check length */
 
43
   if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length) {
 
44
      return CRYPT_INVALID_ARG;
 
45
   }
 
46
 
 
47
   /* Get Z[i] value */
 
48
   ocb_shift_xor(ocb, Z);
 
49
 
 
50
   /* xor ct in, encrypt, xor Z out */
 
51
   for (x = 0; x < ocb->block_len; x++) {
 
52
       tmp[x] = ct[x] ^ Z[x];
 
53
   }
 
54
   cipher_descriptor[ocb->cipher].ecb_decrypt(tmp, pt, &ocb->key);
 
55
   for (x = 0; x < ocb->block_len; x++) {
 
56
       pt[x] ^= Z[x];
 
57
   }
 
58
 
 
59
   /* compute checksum */
 
60
   for (x = 0; x < ocb->block_len; x++) {
 
61
       ocb->checksum[x] ^= pt[x];
 
62
   }
 
63
 
 
64
 
 
65
#ifdef LTC_CLEAN_STACK
 
66
   zeromem(Z, sizeof(Z));
 
67
   zeromem(tmp, sizeof(tmp));
 
68
#endif
 
69
   return CRYPT_OK;
 
70
}
 
71
 
 
72
#endif
 
73
 
 
74
 
 
75
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_decrypt.c,v $ */
 
76
/* $Revision: 1.3 $ */
 
77
/* $Date: 2005/05/05 14:35:58 $ */