Upgrade libtomcrypt
This commit is contained in:
@@ -15,14 +15,9 @@
|
||||
*/
|
||||
int ctr_done(symmetric_CTR *ctr)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[ctr->cipher].done(&ctr->key);
|
||||
return CRYPT_OK;
|
||||
return ecb_done(&ctr->ecb);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ static int s_ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned lo
|
||||
|
||||
while (len) {
|
||||
/* is the pad empty? */
|
||||
if (ctr->padlen == ctr->blocklen) {
|
||||
if (ctr->padlen == ctr->ecb.blocklen) {
|
||||
/* increment counter */
|
||||
if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
|
||||
/* little-endian */
|
||||
@@ -36,7 +36,7 @@ static int s_ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned lo
|
||||
}
|
||||
} else {
|
||||
/* big-endian */
|
||||
for (x = ctr->blocklen-1; x >= ctr->ctrlen; x--) {
|
||||
for (x = ctr->ecb.blocklen-1; x >= ctr->ctrlen; x--) {
|
||||
ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
|
||||
if (ctr->ctr[x] != (unsigned char)0) {
|
||||
break;
|
||||
@@ -45,21 +45,21 @@ static int s_ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned lo
|
||||
}
|
||||
|
||||
/* encrypt it */
|
||||
if ((err = cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(ctr->ctr, ctr->pad, &ctr->ecb)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
ctr->padlen = 0;
|
||||
}
|
||||
#ifdef LTC_FAST
|
||||
if ((ctr->padlen == 0) && (len >= (unsigned long)ctr->blocklen)) {
|
||||
for (x = 0; x < ctr->blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
if ((ctr->padlen == 0) && (len >= (unsigned long)ctr->ecb.blocklen)) {
|
||||
for (x = 0; x < ctr->ecb.blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(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;
|
||||
len -= ctr->blocklen;
|
||||
ctr->padlen = ctr->blocklen;
|
||||
pt += ctr->ecb.blocklen;
|
||||
ct += ctr->ecb.blocklen;
|
||||
len -= ctr->ecb.blocklen;
|
||||
ctr->padlen = ctr->ecb.blocklen;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
@@ -85,26 +85,26 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
|
||||
if ((err = cipher_is_valid(ctr->ecb.cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen/padlen valid? */
|
||||
if ((ctr->blocklen < 1) || (ctr->blocklen > (int)sizeof(ctr->ctr)) ||
|
||||
if ((ctr->ecb.blocklen < 1) || (ctr->ecb.blocklen > (int)sizeof(ctr->ctr)) ||
|
||||
(ctr->padlen < 0) || (ctr->padlen > (int)sizeof(ctr->pad))) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
#ifdef LTC_FAST
|
||||
if (ctr->blocklen % sizeof(LTC_FAST_TYPE)) {
|
||||
if (ctr->ecb.blocklen % sizeof(LTC_FAST_TYPE)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* handle acceleration only if pad is empty, accelerator is present and length is >= a block size */
|
||||
if ((cipher_descriptor[ctr->cipher].accel_ctr_encrypt != NULL) && (len >= (unsigned long)ctr->blocklen)) {
|
||||
if (ctr->padlen < ctr->blocklen) {
|
||||
fr = ctr->blocklen - ctr->padlen;
|
||||
if ((cipher_descriptor[ctr->ecb.cipher].accel_ctr_encrypt != NULL) && (len >= (unsigned long)ctr->ecb.blocklen)) {
|
||||
if (ctr->padlen < ctr->ecb.blocklen) {
|
||||
fr = ctr->ecb.blocklen - ctr->padlen;
|
||||
if ((err = s_ctr_encrypt(pt, ct, fr, ctr)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
@@ -113,13 +113,13 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
len -= fr;
|
||||
}
|
||||
|
||||
if (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) {
|
||||
if (len >= (unsigned long)ctr->ecb.blocklen) {
|
||||
if ((err = cipher_descriptor[ctr->ecb.cipher].accel_ctr_encrypt(pt, ct, len/ctr->ecb.blocklen, ctr->ctr, ctr->mode, &ctr->ecb.key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
pt += (len / ctr->blocklen) * ctr->blocklen;
|
||||
ct += (len / ctr->blocklen) * ctr->blocklen;
|
||||
len %= ctr->blocklen;
|
||||
pt += (len / ctr->ecb.blocklen) * ctr->ecb.blocklen;
|
||||
ct += (len / ctr->ecb.blocklen) * ctr->ecb.blocklen;
|
||||
len %= ctr->ecb.blocklen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,12 @@ int ctr_getiv(unsigned char *IV, unsigned long *len, const symmetric_CTR *ctr)
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
if ((unsigned long)ctr->blocklen > *len) {
|
||||
*len = ctr->blocklen;
|
||||
if ((unsigned long)ctr->ecb.blocklen > *len) {
|
||||
*len = ctr->ecb.blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, ctr->ctr, ctr->blocklen);
|
||||
*len = ctr->blocklen;
|
||||
XMEMCPY(IV, ctr->ctr, ctr->ecb.blocklen);
|
||||
*len = ctr->ecb.blocklen;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
|
||||
/* bad param? */
|
||||
if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
|
||||
if ((err = cipher_is_valid(ctr->ecb.cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (len != (unsigned long)ctr->blocklen) {
|
||||
if (len != (unsigned long)ctr->ecb.blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)
|
||||
|
||||
/* force next block */
|
||||
ctr->padlen = 0;
|
||||
return cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key);
|
||||
return ecb_encrypt_block(IV, ctr->pad, &ctr->ecb);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -49,16 +49,14 @@ int ctr_start( int cipher,
|
||||
}
|
||||
|
||||
/* setup cipher */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ctr->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_start(cipher, key, keylen, num_rounds, &ctr->ecb)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* copy ctr */
|
||||
ctr->blocklen = cipher_descriptor[cipher].block_length;
|
||||
ctr->cipher = cipher;
|
||||
ctr->padlen = 0;
|
||||
ctr->mode = ctr_mode & 0x1000;
|
||||
for (x = 0; x < ctr->blocklen; x++) {
|
||||
for (x = 0; x < ctr->ecb.blocklen; x++) {
|
||||
ctr->ctr[x] = IV[x];
|
||||
}
|
||||
|
||||
@@ -74,7 +72,7 @@ int ctr_start( int cipher,
|
||||
}
|
||||
} else {
|
||||
/* big-endian */
|
||||
for (x = ctr->blocklen-1; x >= ctr->ctrlen; x--) {
|
||||
for (x = ctr->ecb.blocklen-1; x >= ctr->ctrlen; x--) {
|
||||
ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
|
||||
if (ctr->ctr[x] != (unsigned char)0) {
|
||||
break;
|
||||
@@ -83,7 +81,7 @@ int ctr_start( int cipher,
|
||||
}
|
||||
}
|
||||
|
||||
return cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
|
||||
return ecb_encrypt_block(ctr->ctr, ctr->pad, &ctr->ecb);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -51,7 +51,7 @@ int ctr_test(void)
|
||||
}
|
||||
}
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
|
||||
if ((err = ctr_start(idx, tests[x].IV, tests[x].key, tests[x].keylen, 0, CTR_COUNTER_BIG_ENDIAN|LTC_CTR_RFC3686, &ctr)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user