Upgrade libtomcrypt
This commit is contained in:
@@ -20,7 +20,6 @@ int gcm_add_aad(gcm_state *gcm,
|
||||
const unsigned char *adata, unsigned long adatalen)
|
||||
{
|
||||
unsigned long x;
|
||||
int err;
|
||||
#ifdef LTC_FAST
|
||||
unsigned long y;
|
||||
#endif
|
||||
@@ -34,10 +33,6 @@ int gcm_add_aad(gcm_state *gcm,
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* in IV mode? */
|
||||
if (gcm->mode == LTC_GCM_MODE_IV) {
|
||||
/* IV length must be > 0 */
|
||||
|
||||
@@ -20,7 +20,6 @@ int gcm_add_iv(gcm_state *gcm,
|
||||
const unsigned char *IV, unsigned long IVlen)
|
||||
{
|
||||
unsigned long x, y;
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(gcm != NULL);
|
||||
if (IVlen > 0) {
|
||||
@@ -36,11 +35,6 @@ int gcm_add_iv(gcm_state *gcm,
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/* trip the ivmode flag */
|
||||
if (IVlen + gcm->buflen > 12) {
|
||||
gcm->ivmode |= 1;
|
||||
|
||||
@@ -30,10 +30,6 @@ int gcm_done(gcm_state *gcm,
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (gcm->mode == LTC_GCM_MODE_IV) {
|
||||
/* let's process the IV */
|
||||
if ((err = gcm_add_aad(gcm, NULL, 0)) != CRYPT_OK) return err;
|
||||
@@ -63,7 +59,7 @@ int gcm_done(gcm_state *gcm,
|
||||
gcm_mult_h(gcm, gcm->X);
|
||||
|
||||
/* encrypt original counter */
|
||||
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y_0, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(gcm->Y_0, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
for (x = 0; x < 16 && x < *taglen; x++) {
|
||||
@@ -71,7 +67,7 @@ int gcm_done(gcm_state *gcm,
|
||||
}
|
||||
*taglen = x;
|
||||
|
||||
cipher_descriptor[gcm->cipher].done(&gcm->K);
|
||||
ecb_done(&gcm->K);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
@@ -44,20 +44,19 @@ int gcm_init(gcm_state *gcm, int cipher,
|
||||
}
|
||||
|
||||
/* schedule key */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &gcm->K)) != CRYPT_OK) {
|
||||
if ((err = ecb_start(cipher, key, keylen, 0, &gcm->K)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* H = E(0) */
|
||||
zeromem(B, 16);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(B, gcm->H, &gcm->K)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(B, gcm->H, &gcm->K)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* setup state */
|
||||
zeromem(gcm->buf, sizeof(gcm->buf));
|
||||
zeromem(gcm->X, sizeof(gcm->X));
|
||||
gcm->cipher = cipher;
|
||||
gcm->mode = LTC_GCM_MODE_IV;
|
||||
gcm->ivmode = 0;
|
||||
gcm->buflen = 0;
|
||||
|
||||
@@ -37,10 +37,6 @@ int gcm_process(gcm_state *gcm,
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* 0xFFFFFFFE0 = ((2^39)-256)/8 */
|
||||
if (gcm->pttotlen / 8 + (ulong64)gcm->buflen + (ulong64)ptlen >= CONST64(0xFFFFFFFE0)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
@@ -64,7 +60,7 @@ int gcm_process(gcm_state *gcm,
|
||||
if (++gcm->Y[y] & 255) { break; }
|
||||
}
|
||||
/* encrypt the counter */
|
||||
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -93,7 +89,7 @@ int gcm_process(gcm_state *gcm,
|
||||
for (y = 15; y >= 12; y--) {
|
||||
if (++gcm->Y[y] & 255) { break; }
|
||||
}
|
||||
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@@ -111,7 +107,7 @@ int gcm_process(gcm_state *gcm,
|
||||
for (y = 15; y >= 12; y--) {
|
||||
if (++gcm->Y[y] & 255) { break; }
|
||||
}
|
||||
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@@ -129,7 +125,7 @@ int gcm_process(gcm_state *gcm,
|
||||
for (y = 15; y >= 12; y--) {
|
||||
if (++gcm->Y[y] & 255) { break; }
|
||||
}
|
||||
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
gcm->buflen = 0;
|
||||
|
||||
@@ -338,7 +338,7 @@ int gcm_test(void)
|
||||
if ((err = gcm_done(&gcm, T[0], &y)) != CRYPT_OK) return err;
|
||||
if (compare_testvector(T[0], y, tests[0].T, 16, "GCM Encrypt Tag-special", 0)) return CRYPT_FAIL_TESTVECTOR;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
|
||||
y = sizeof(T[0]);
|
||||
if ((err = gcm_memory(idx, tests[x].K, tests[x].keylen,
|
||||
tests[x].IV, tests[x].IVlen,
|
||||
|
||||
Reference in New Issue
Block a user