comparison src/modes/ctr/ctr_start.c @ 381:999a5eb4ed10 libtomcrypt-dropbear

propagate from branch 'au.asn.ucc.matt.ltc.orig' (head 52840647ac7f5c707c3bd158d119a15734a7ef28) to branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:39:21 +0000
parents d5faf4814ddb
children
comparison
equal deleted inserted replaced
281:997e6f7dc01e 381:999a5eb4ed10
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org 9 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file ctr_start.c 14 @file ctr_start.c
15 CTR implementation, start chain, Tom St Denis 15 CTR implementation, start chain, Tom St Denis
16 */ 16 */
17 17
18 18
19 #ifdef CTR 19 #ifdef LTC_CTR_MODE
20 20
21 /** 21 /**
22 Initialize a CTR context 22 Initialize a CTR context
23 @param cipher The index of the cipher desired 23 @param cipher The index of the cipher desired
24 @param IV The initial vector 24 @param IV The initial vector
53 53
54 /* copy ctr */ 54 /* copy ctr */
55 ctr->blocklen = cipher_descriptor[cipher].block_length; 55 ctr->blocklen = cipher_descriptor[cipher].block_length;
56 ctr->cipher = cipher; 56 ctr->cipher = cipher;
57 ctr->padlen = 0; 57 ctr->padlen = 0;
58 ctr->mode = ctr_mode; 58 ctr->mode = ctr_mode & 1;
59 for (x = 0; x < ctr->blocklen; x++) { 59 for (x = 0; x < ctr->blocklen; x++) {
60 ctr->ctr[x] = IV[x]; 60 ctr->ctr[x] = IV[x];
61 } 61 }
62 cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key); 62
63 return CRYPT_OK; 63 if (ctr_mode & LTC_CTR_RFC3686) {
64 /* increment the IV as per RFC 3686 */
65 if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
66 /* little-endian */
67 for (x = 0; x < ctr->blocklen; x++) {
68 ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
69 if (ctr->ctr[x] != (unsigned char)0) {
70 break;
71 }
72 }
73 } else {
74 /* big-endian */
75 for (x = ctr->blocklen-1; x >= 0; x--) {
76 ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
77 if (ctr->ctr[x] != (unsigned char)0) {
78 break;
79 }
80 }
81 }
82 }
83
84 return cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
64 } 85 }
65 86
66 #endif 87 #endif
67 88
68 /* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_start.c,v $ */ 89 /* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_start.c,v $ */
69 /* $Revision: 1.6 $ */ 90 /* $Revision: 1.11 $ */
70 /* $Date: 2005/05/05 14:35:59 $ */ 91 /* $Date: 2006/11/05 01:46:35 $ */