Upgrade libtomcrypt
This commit is contained in:
@@ -25,16 +25,8 @@ int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt)
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
|
||||
/* check if valid cipher */
|
||||
if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
LTC_ARGCHK(cipher_descriptor[ocb->cipher].ecb_decrypt != NULL);
|
||||
|
||||
/* check length */
|
||||
if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
/* can't use a encrypt-only descriptor */
|
||||
LTC_ARGCHK(cipher_descriptor[ocb->key.cipher].ecb_decrypt != NULL);
|
||||
|
||||
/* Get Z[i] value */
|
||||
ocb_shift_xor(ocb, Z);
|
||||
@@ -43,7 +35,7 @@ int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt)
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
tmp[x] = ct[x] ^ Z[x];
|
||||
}
|
||||
if ((err = cipher_descriptor[ocb->cipher].ecb_decrypt(tmp, pt, &ocb->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_decrypt_block(tmp, pt, &ocb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
|
||||
@@ -24,12 +24,6 @@ int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct)
|
||||
LTC_ARGCHK(ocb != NULL);
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* compute checksum */
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
@@ -43,7 +37,7 @@ int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct)
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
tmp[x] = pt[x] ^ Z[x];
|
||||
}
|
||||
if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(tmp, ct, &ocb->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(tmp, ct, &ocb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
|
||||
@@ -57,7 +57,7 @@ int ocb_init(ocb_state *ocb, int cipher,
|
||||
|
||||
/* determine which polys to use */
|
||||
ocb->block_len = cipher_descriptor[cipher].block_length;
|
||||
x = (int)(sizeof(polys)/sizeof(polys[0]));
|
||||
x = (int)LTC_ARRAY_SIZE(polys);
|
||||
for (poly = 0; poly < x; poly++) {
|
||||
if (polys[poly].len == ocb->block_len) {
|
||||
break;
|
||||
@@ -71,13 +71,13 @@ int ocb_init(ocb_state *ocb, int cipher,
|
||||
}
|
||||
|
||||
/* schedule the key */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &ocb->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_start(cipher, key, keylen, 0, &ocb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* find L = E[0] */
|
||||
zeromem(ocb->L, ocb->block_len);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(ocb->L, ocb->L, &ocb->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(ocb->L, ocb->L, &ocb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ int ocb_init(ocb_state *ocb, int cipher,
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
ocb->R[x] = ocb->L[x] ^ nonce[x];
|
||||
}
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(ocb->R, ocb->R, &ocb->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(ocb->R, ocb->R, &ocb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,6 @@ int ocb_init(ocb_state *ocb, int cipher,
|
||||
|
||||
/* set other params */
|
||||
ocb->block_index = 1;
|
||||
ocb->cipher = cipher;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
*/
|
||||
int ocb_ntz(unsigned long x)
|
||||
{
|
||||
#if defined(LTC_HAVE_CTZL_BUILTIN)
|
||||
if (x == 0)
|
||||
return sizeof(unsigned long) * CHAR_BIT;
|
||||
return __builtin_ctzl(x);
|
||||
#else
|
||||
int c;
|
||||
x &= 0xFFFFFFFFUL;
|
||||
c = 0;
|
||||
@@ -25,6 +30,7 @@ int ocb_ntz(unsigned long x)
|
||||
x >>= 1;
|
||||
}
|
||||
return c;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -167,7 +167,7 @@ int ocb_test(void)
|
||||
}
|
||||
}
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
|
||||
len = sizeof(outtag);
|
||||
if ((err = ocb_encrypt_authenticate_memory(idx, tests[x].key, 16,
|
||||
tests[x].nonce, tests[x].pt, tests[x].ptlen, outct, outtag, &len)) != CRYPT_OK) {
|
||||
|
||||
@@ -40,11 +40,7 @@ int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(tag != NULL);
|
||||
LTC_ARGCHK(taglen != NULL);
|
||||
if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length ||
|
||||
(int)ptlen > ocb->block_len || (int)ptlen < 0) {
|
||||
if ((int)ptlen > ocb->block_len || (int)ptlen < 0) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
@@ -76,7 +72,7 @@ int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
|
||||
}
|
||||
|
||||
/* Y[m] = E(X[m])) */
|
||||
if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(X, Y, &ocb->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(X, Y, &ocb->key)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -107,10 +103,10 @@ int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
|
||||
}
|
||||
|
||||
/* encrypt checksum, er... tag!! */
|
||||
if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(ocb->checksum, X, &ocb->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(ocb->checksum, X, &ocb->key)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
cipher_descriptor[ocb->cipher].done(&ocb->key);
|
||||
ecb_done(&ocb->key);
|
||||
|
||||
/* now store it */
|
||||
for (x = 0; x < ocb->block_len && x < (int)*taglen; x++) {
|
||||
|
||||
Reference in New Issue
Block a user