Upgrade libtomcrypt
This commit is contained in:
@@ -32,51 +32,51 @@ int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
|
||||
if ((err = cipher_is_valid(cbc->ecb.cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen valid? */
|
||||
if (cbc->blocklen < 1 || cbc->blocklen > (int)sizeof(cbc->IV) || cbc->blocklen > (int)sizeof(tmp)) {
|
||||
if (cbc->ecb.blocklen < 1 || cbc->ecb.blocklen > (int)sizeof(cbc->IV) || cbc->ecb.blocklen > (int)sizeof(tmp)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (len % cbc->blocklen) {
|
||||
if (len % cbc->ecb.blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#ifdef LTC_FAST
|
||||
if (cbc->blocklen % sizeof(LTC_FAST_TYPE)) {
|
||||
if (cbc->ecb.blocklen % sizeof(LTC_FAST_TYPE)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cipher_descriptor[cbc->cipher].accel_cbc_decrypt != NULL) {
|
||||
return cipher_descriptor[cbc->cipher].accel_cbc_decrypt(ct, pt, len / cbc->blocklen, cbc->IV, &cbc->key);
|
||||
if (cipher_descriptor[cbc->ecb.cipher].accel_cbc_decrypt != NULL) {
|
||||
return cipher_descriptor[cbc->ecb.cipher].accel_cbc_decrypt(ct, pt, len / cbc->ecb.blocklen, cbc->IV, &cbc->ecb.key);
|
||||
}
|
||||
while (len) {
|
||||
/* decrypt */
|
||||
if ((err = cipher_descriptor[cbc->cipher].ecb_decrypt(ct, tmp, &cbc->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_decrypt_block(ct, tmp, &cbc->ecb)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* xor IV against plaintext */
|
||||
#if defined(LTC_FAST)
|
||||
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
for (x = 0; x < cbc->ecb.blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
tmpy = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) ^ *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)tmp + x));
|
||||
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x));
|
||||
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) = tmpy;
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < cbc->blocklen; x++) {
|
||||
for (x = 0; x < cbc->ecb.blocklen; x++) {
|
||||
tmpy = tmp[x] ^ cbc->IV[x];
|
||||
cbc->IV[x] = ct[x];
|
||||
pt[x] = tmpy;
|
||||
}
|
||||
#endif
|
||||
|
||||
ct += cbc->blocklen;
|
||||
pt += cbc->blocklen;
|
||||
len -= cbc->blocklen;
|
||||
ct += cbc->ecb.blocklen;
|
||||
pt += cbc->ecb.blocklen;
|
||||
len -= cbc->ecb.blocklen;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
@@ -15,14 +15,9 @@
|
||||
*/
|
||||
int cbc_done(symmetric_CBC *cbc)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[cbc->cipher].done(&cbc->key);
|
||||
return CRYPT_OK;
|
||||
return ecb_done(&cbc->ecb);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,58 +26,58 @@ int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
|
||||
if ((err = cipher_is_valid(cbc->ecb.cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen valid? */
|
||||
if (cbc->blocklen < 1 || cbc->blocklen > (int)sizeof(cbc->IV)) {
|
||||
if (cbc->ecb.blocklen < 1 || cbc->ecb.blocklen > (int)sizeof(cbc->IV)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (len % cbc->blocklen) {
|
||||
if (len % cbc->ecb.blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#ifdef LTC_FAST
|
||||
if (cbc->blocklen % sizeof(LTC_FAST_TYPE)) {
|
||||
if (cbc->ecb.blocklen % sizeof(LTC_FAST_TYPE)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cipher_descriptor[cbc->cipher].accel_cbc_encrypt != NULL) {
|
||||
return cipher_descriptor[cbc->cipher].accel_cbc_encrypt(pt, ct, len / cbc->blocklen, cbc->IV, &cbc->key);
|
||||
if (cipher_descriptor[cbc->ecb.cipher].accel_cbc_encrypt != NULL) {
|
||||
return cipher_descriptor[cbc->ecb.cipher].accel_cbc_encrypt(pt, ct, len / cbc->ecb.blocklen, cbc->IV, &cbc->ecb.key);
|
||||
}
|
||||
while (len) {
|
||||
/* xor IV against plaintext */
|
||||
#if defined(LTC_FAST)
|
||||
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
for (x = 0; x < cbc->ecb.blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) ^= *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x));
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < cbc->blocklen; x++) {
|
||||
for (x = 0; x < cbc->ecb.blocklen; x++) {
|
||||
cbc->IV[x] ^= pt[x];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* encrypt */
|
||||
if ((err = cipher_descriptor[cbc->cipher].ecb_encrypt(cbc->IV, ct, &cbc->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(cbc->IV, ct, &cbc->ecb)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* store IV [ciphertext] for a future block */
|
||||
#if defined(LTC_FAST)
|
||||
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
for (x = 0; x < cbc->ecb.blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x));
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < cbc->blocklen; x++) {
|
||||
for (x = 0; x < cbc->ecb.blocklen; x++) {
|
||||
cbc->IV[x] = ct[x];
|
||||
}
|
||||
#endif
|
||||
|
||||
ct += cbc->blocklen;
|
||||
pt += cbc->blocklen;
|
||||
len -= cbc->blocklen;
|
||||
ct += cbc->ecb.blocklen;
|
||||
pt += cbc->ecb.blocklen;
|
||||
len -= cbc->ecb.blocklen;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ int cbc_getiv(unsigned char *IV, unsigned long *len, const symmetric_CBC *cbc)
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
if ((unsigned long)cbc->blocklen > *len) {
|
||||
*len = cbc->blocklen;
|
||||
if ((unsigned long)cbc->ecb.blocklen > *len) {
|
||||
*len = cbc->ecb.blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, cbc->IV, cbc->blocklen);
|
||||
*len = cbc->blocklen;
|
||||
XMEMCPY(IV, cbc->IV, cbc->ecb.blocklen);
|
||||
*len = cbc->ecb.blocklen;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc)
|
||||
{
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
if (len != (unsigned long)cbc->blocklen) {
|
||||
if (len != (unsigned long)cbc->ecb.blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
XMEMCPY(cbc->IV, IV, len);
|
||||
|
||||
@@ -28,20 +28,13 @@ int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
|
||||
/* bad param? */
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* setup cipher */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cbc->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_start(cipher, key, keylen, num_rounds, &cbc->ecb)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* copy IV */
|
||||
cbc->blocklen = cipher_descriptor[cipher].block_length;
|
||||
cbc->cipher = cipher;
|
||||
for (x = 0; x < cbc->blocklen; x++) {
|
||||
for (x = 0; x < cbc->ecb.blocklen; x++) {
|
||||
cbc->IV[x] = IV[x];
|
||||
}
|
||||
return CRYPT_OK;
|
||||
|
||||
Reference in New Issue
Block a user