Lines Matching refs:ctr
15 CTR implementation, encrypt data, Tom St Denis
22 CTR encrypt
26 @param ctr CTR state
29 int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr)
35 LTC_ARGCHK(ctr != NULL);
37 if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
42 if (ctr->blocklen < 1 || ctr->blocklen > (int)sizeof(ctr->ctr) ||
43 ctr->padlen < 0 || ctr->padlen > (int)sizeof(ctr->pad)) {
48 if (ctr->blocklen % sizeof(LTC_FAST_TYPE)) {
54 if ((ctr->padlen == ctr->blocklen) && cipher_descriptor[ctr->cipher].accel_ctr_encrypt != NULL && (len >= (unsigned long)ctr->blocklen)) {
55 if ((err = cipher_descriptor[ctr->cipher].accel_ctr_encrypt(pt, ct, len/ctr->blocklen, ctr->ctr, ctr->mode, &ctr->key)) != CRYPT_OK) {
58 len %= ctr->blocklen;
63 if (ctr->padlen == ctr->blocklen) {
65 if (ctr->mode == CTR_COUNTER_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) {
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) {
84 if ((err = cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key)) != CRYPT_OK) {
87 ctr->padlen = 0;
90 if (ctr->padlen == 0 && len >= (unsigned long)ctr->blocklen) {
91 for (x = 0; x < ctr->blocklen; x += sizeof(LTC_FAST_TYPE)) {
93 *((LTC_FAST_TYPE*)((unsigned char *)ctr->pad + x));
95 pt += ctr->blocklen;
96 ct += ctr->blocklen;
97 len -= ctr->blocklen;
98 ctr->padlen = ctr->blocklen;
102 *ct++ = *pt++ ^ ctr->pad[ctr->padlen++];
110 /* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_encrypt.c,v $ */