Mercurial > dropbear
diff libtomcrypt/src/modes/ctr/ctr_encrypt.c @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | f849a5ca2efc |
children | e9dba7abd939 |
line wrap: on
line diff
--- a/libtomcrypt/src/modes/ctr/ctr_encrypt.c Thu Feb 08 23:11:40 2018 +0800 +++ b/libtomcrypt/src/modes/ctr/ctr_encrypt.c Fri Feb 09 21:44:05 2018 +0800 @@ -5,8 +5,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, [email protected], http://libtom.org */ #include "tomcrypt.h" @@ -37,7 +35,7 @@ if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) { return err; } - + /* is blocklen/padlen valid? */ if (ctr->blocklen < 1 || ctr->blocklen > (int)sizeof(ctr->ctr) || ctr->padlen < 0 || ctr->padlen > (int)sizeof(ctr->pad)) { @@ -49,12 +47,14 @@ return CRYPT_INVALID_ARG; } #endif - + /* handle acceleration only if pad is empty, accelerator is present and length is >= a block size */ if ((ctr->padlen == ctr->blocklen) && cipher_descriptor[ctr->cipher].accel_ctr_encrypt != NULL && (len >= (unsigned long)ctr->blocklen)) { if ((err = cipher_descriptor[ctr->cipher].accel_ctr_encrypt(pt, ct, len/ctr->blocklen, ctr->ctr, ctr->mode, &ctr->key)) != CRYPT_OK) { return err; } + pt += (len / ctr->blocklen) * ctr->blocklen; + ct += (len / ctr->blocklen) * ctr->blocklen; len %= ctr->blocklen; } @@ -89,8 +89,8 @@ #ifdef LTC_FAST if (ctr->padlen == 0 && len >= (unsigned long)ctr->blocklen) { for (x = 0; x < ctr->blocklen; x += sizeof(LTC_FAST_TYPE)) { - *((LTC_FAST_TYPE*)((unsigned char *)ct + x)) = *((LTC_FAST_TYPE*)((unsigned char *)pt + x)) ^ - *((LTC_FAST_TYPE*)((unsigned char *)ctr->pad + x)); + *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) ^ + *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ctr->pad + x)); } pt += ctr->blocklen; ct += ctr->blocklen; @@ -98,7 +98,7 @@ ctr->padlen = ctr->blocklen; continue; } -#endif +#endif *ct++ = *pt++ ^ ctr->pad[ctr->padlen++]; --len; } @@ -107,6 +107,6 @@ #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */