comparison libtomcrypt/src/modes/ctr/ctr_encrypt.c @ 1435:f849a5ca2efc

update to libtomcrypt 1.17 (with Dropbear changes)
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 17:50:50 +0800
parents 0cbe8f6dbf9e
children 6dba84798cd5
comparison
equal deleted inserted replaced
1434:27b9ddb06b09 1435:f849a5ca2efc
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.com 9 * Tom St Denis, [email protected], http://libtom.org
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file ctr_encrypt.c 14 @file ctr_encrypt.c
62 /* is the pad empty? */ 62 /* is the pad empty? */
63 if (ctr->padlen == ctr->blocklen) { 63 if (ctr->padlen == ctr->blocklen) {
64 /* increment counter */ 64 /* increment counter */
65 if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) { 65 if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
66 /* little-endian */ 66 /* little-endian */
67 for (x = 0; x < ctr->blocklen; x++) { 67 for (x = 0; x < ctr->ctrlen; x++) {
68 ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255; 68 ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
69 if (ctr->ctr[x] != (unsigned char)0) { 69 if (ctr->ctr[x] != (unsigned char)0) {
70 break; 70 break;
71 } 71 }
72 } 72 }
73 } else { 73 } else {
74 /* big-endian */ 74 /* big-endian */
75 for (x = ctr->blocklen-1; x >= 0; x--) { 75 for (x = ctr->blocklen-1; x >= ctr->ctrlen; x--) {
76 ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255; 76 ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
77 if (ctr->ctr[x] != (unsigned char)0) { 77 if (ctr->ctr[x] != (unsigned char)0) {
78 break; 78 break;
79 } 79 }
80 } 80 }
105 return CRYPT_OK; 105 return CRYPT_OK;
106 } 106 }
107 107
108 #endif 108 #endif
109 109
110 /* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_encrypt.c,v $ */ 110 /* $Source$ */
111 /* $Revision: 1.20 $ */ 111 /* $Revision$ */
112 /* $Date: 2006/11/21 00:18:23 $ */ 112 /* $Date$ */