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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape, Matt Johnston, Gerrit Pape
  • Date: 2008-03-27 20:08:06 UTC
  • mfrom: (1.4.1 upstream) (9 hardy)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20080327200806-c1hhdgt3ht2gk496
Tags: 0.51-1
[ Matt Johnston ]
* New upstream release.
  - Wait until a process exits before the server closes a connection,
    so that an exit code can be sent. This fixes problems with exit
    codes not being returned, which could cause scp to fail (closes:
    #448397, #472483).

[ Gerrit Pape ]
* debian/dropbear.postinst: don't print an error message if the
  update-service program is not installed (thx Matt).

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 encrypt
39
39
   }
40
40
   
41
41
   /* is blocklen valid? */
42
 
   if (cbc->blocklen < 0 || cbc->blocklen > (int)sizeof(cbc->IV)) {
 
42
   if (cbc->blocklen < 1 || cbc->blocklen > (int)sizeof(cbc->IV)) {
43
43
      return CRYPT_INVALID_ARG;
44
44
   }    
45
45
 
47
47
      return CRYPT_INVALID_ARG;
48
48
   }
49
49
#ifdef LTC_FAST
50
 
   if (len % sizeof(LTC_FAST_TYPE)) {   
 
50
   if (cbc->blocklen % sizeof(LTC_FAST_TYPE)) {   
51
51
      return CRYPT_INVALID_ARG;
52
52
   }
53
53
#endif
54
54
 
55
55
   if (cipher_descriptor[cbc->cipher].accel_cbc_encrypt != NULL) {
56
 
      cipher_descriptor[cbc->cipher].accel_cbc_encrypt(pt, ct, len / cbc->blocklen, cbc->IV, &cbc->key);
 
56
      return cipher_descriptor[cbc->cipher].accel_cbc_encrypt(pt, ct, len / cbc->blocklen, cbc->IV, &cbc->key);
57
57
   } else {
58
58
      while (len) {
59
59
         /* xor IV against plaintext */
60
60
         #if defined(LTC_FAST)
61
 
             for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
62
 
                 *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) ^= *((LTC_FAST_TYPE*)((unsigned char *)pt + x));
63
 
             }
64
 
         #else 
 
61
        for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
 
62
            *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) ^= *((LTC_FAST_TYPE*)((unsigned char *)pt + x));
 
63
        }
 
64
    #else 
65
65
            for (x = 0; x < cbc->blocklen; x++) {
66
66
               cbc->IV[x] ^= pt[x];
67
67
            }
68
 
         #endif
 
68
    #endif
69
69
 
70
70
         /* encrypt */
71
 
         cipher_descriptor[cbc->cipher].ecb_encrypt(cbc->IV, ct, &cbc->key);
 
71
         if ((err = cipher_descriptor[cbc->cipher].ecb_encrypt(cbc->IV, ct, &cbc->key)) != CRYPT_OK) {
 
72
            return err;
 
73
         }
72
74
 
73
75
        /* store IV [ciphertext] for a future block */
74
76
         #if defined(LTC_FAST)
75
 
             for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
76
 
                 *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
77
 
             }
78
 
         #else 
 
77
        for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
 
78
            *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
 
79
        }
 
80
    #else 
79
81
             for (x = 0; x < cbc->blocklen; x++) {
80
82
                cbc->IV[x] = ct[x];
81
83
             }
82
 
         #endif
 
84
    #endif
83
85
        
84
86
        ct  += cbc->blocklen;
85
87
        pt  += cbc->blocklen;
92
94
#endif
93
95
 
94
96
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_encrypt.c,v $ */
95
 
/* $Revision: 1.7 $ */
96
 
/* $Date: 2005/05/05 14:35:59 $ */
 
97
/* $Revision: 1.13 $ */
 
98
/* $Date: 2006/11/21 00:18:23 $ */