~ubuntu-branches/ubuntu/precise/dropbear/precise

« back to all changes in this revision

Viewing changes to libtomcrypt/src/modes/cbc/cbc_decrypt.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape
  • Date: 2007-03-02 20:48:18 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070302204818-ozmbou2sbyj7dus5
Tags: 0.49-1
* new upstream release, fixes
  * CVE-2007-1099: dropbear dbclient insufficient warning on hostkey
    mismatch (closes: #412899).
  * dbclient uses static "Password:" prompt instead of using the server's
    prompt (closes: #394996).
* debian/control: Suggests: openssh-client, not ssh (closes: #405686);
  Standards-Version: 3.7.2.2.
* debian/README.Debian: ssh -> openssh-server, openssh-client; remove
  'Replacing OpenSSH "sshd" with Dropbear' part, this is simply done by not
  installing the openssh-server package.
* debian/README.runit: runsvstat -> sv status.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * The library is free for all purposes without any express
7
7
 * guarantee it works.
8
8
 *
9
 
 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
 
9
 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
10
10
 */
11
11
#include "tomcrypt.h"
12
12
 
16
16
*/
17
17
 
18
18
 
19
 
#ifdef CBC
 
19
#ifdef LTC_CBC_MODE
20
20
 
21
21
/**
22
22
  CBC decrypt
45
45
   }
46
46
   
47
47
   /* is blocklen valid? */
48
 
   if (cbc->blocklen < 0 || cbc->blocklen > (int)sizeof(cbc->IV)) {
 
48
   if (cbc->blocklen < 1 || cbc->blocklen > (int)sizeof(cbc->IV)) {
49
49
      return CRYPT_INVALID_ARG;
50
50
   }    
51
51
 
53
53
      return CRYPT_INVALID_ARG;
54
54
   }
55
55
#ifdef LTC_FAST
56
 
   if (len % sizeof(LTC_FAST_TYPE)) {   
 
56
   if (cbc->blocklen % sizeof(LTC_FAST_TYPE)) {   
57
57
      return CRYPT_INVALID_ARG;
58
58
   }
59
59
#endif
60
60
   
61
61
   if (cipher_descriptor[cbc->cipher].accel_cbc_decrypt != NULL) {
62
 
      cipher_descriptor[cbc->cipher].accel_cbc_decrypt(ct, pt, len / cbc->blocklen, cbc->IV, &cbc->key);
 
62
      return cipher_descriptor[cbc->cipher].accel_cbc_decrypt(ct, pt, len / cbc->blocklen, cbc->IV, &cbc->key);
63
63
   } else {
64
64
      while (len) {
65
65
         /* decrypt */
66
 
         cipher_descriptor[cbc->cipher].ecb_decrypt(ct, tmp, &cbc->key);
 
66
         if ((err = cipher_descriptor[cbc->cipher].ecb_decrypt(ct, tmp, &cbc->key)) != CRYPT_OK) {
 
67
            return err;
 
68
         }
67
69
 
68
70
         /* xor IV against plaintext */
69
71
         #if defined(LTC_FAST)
70
 
             for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
71
 
                 tmpy = *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) ^ *((LTC_FAST_TYPE*)((unsigned char *)tmp + x));
72
 
                 *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
73
 
                 *((LTC_FAST_TYPE*)((unsigned char *)pt + x)) = tmpy;
74
 
             }
75
 
         #else 
 
72
        for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
 
73
            tmpy = *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) ^ *((LTC_FAST_TYPE*)((unsigned char *)tmp + x));
 
74
       *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
 
75
       *((LTC_FAST_TYPE*)((unsigned char *)pt + x)) = tmpy;
 
76
        }
 
77
    #else 
76
78
            for (x = 0; x < cbc->blocklen; x++) {
77
79
               tmpy       = tmp[x] ^ cbc->IV[x];
78
80
               cbc->IV[x] = ct[x];
79
81
               pt[x]      = tmpy;
80
82
            }
81
 
         #endif
 
83
    #endif
82
84
       
83
85
         ct  += cbc->blocklen;
84
86
         pt  += cbc->blocklen;
91
93
#endif
92
94
 
93
95
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_decrypt.c,v $ */
94
 
/* $Revision: 1.9 $ */
95
 
/* $Date: 2005/05/05 14:35:59 $ */
 
96
/* $Revision: 1.15 $ */
 
97
/* $Date: 2006/11/21 00:18:23 $ */