Upgrade libtomcrypt
This commit is contained in:
@@ -15,9 +15,6 @@ int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen)
|
||||
|
||||
LTC_ARGCHK(pmac != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
if ((err = cipher_is_valid(pmac->cipher_idx)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((pmac->buflen > (int)sizeof(pmac->block)) || (pmac->buflen < 0) ||
|
||||
(pmac->block_len > (int)sizeof(pmac->block)) || (pmac->buflen > pmac->block_len)) {
|
||||
@@ -41,10 +38,10 @@ int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen)
|
||||
}
|
||||
|
||||
/* encrypt it */
|
||||
if ((err = cipher_descriptor[pmac->cipher_idx].ecb_encrypt(pmac->checksum, pmac->checksum, &pmac->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(pmac->checksum, pmac->checksum, &pmac->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[pmac->cipher_idx].done(&pmac->key);
|
||||
ecb_done(&pmac->key);
|
||||
|
||||
/* store it */
|
||||
for (x = 0; x < pmac->block_len && x < (int)*outlen; x++) {
|
||||
|
||||
@@ -55,12 +55,12 @@ int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned l
|
||||
|
||||
/* determine which polys to use */
|
||||
pmac->block_len = cipher_descriptor[cipher].block_length;
|
||||
for (poly = 0; poly < (int)(sizeof(polys)/sizeof(polys[0])); poly++) {
|
||||
for (poly = 0; poly < (int)LTC_ARRAY_SIZE(polys); poly++) {
|
||||
if (polys[poly].len == pmac->block_len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (poly >= (int)(sizeof(polys)/sizeof(polys[0]))) {
|
||||
if (poly >= (int)LTC_ARRAY_SIZE(polys)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
if (polys[poly].len != pmac->block_len) {
|
||||
@@ -75,7 +75,7 @@ int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned l
|
||||
|
||||
|
||||
/* schedule the key */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &pmac->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_start(cipher, key, keylen, 0, &pmac->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned l
|
||||
|
||||
/* find L = E[0] */
|
||||
zeromem(L, pmac->block_len);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(L, L, &pmac->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(L, L, &pmac->key)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,6 @@ int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned l
|
||||
|
||||
/* zero buffer, counters, etc... */
|
||||
pmac->block_index = 1;
|
||||
pmac->cipher_idx = cipher;
|
||||
pmac->buflen = 0;
|
||||
zeromem(pmac->block, sizeof(pmac->block));
|
||||
zeromem(pmac->Li, sizeof(pmac->Li));
|
||||
|
||||
@@ -14,6 +14,11 @@
|
||||
*/
|
||||
int pmac_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;
|
||||
@@ -22,6 +27,7 @@ int pmac_ntz(unsigned long x)
|
||||
x >>= 1;
|
||||
}
|
||||
return c;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,9 +29,6 @@ int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen)
|
||||
|
||||
LTC_ARGCHK(pmac != NULL);
|
||||
LTC_ARGCHK(in != NULL);
|
||||
if ((err = cipher_is_valid(pmac->cipher_idx)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((pmac->buflen > (int)sizeof(pmac->block)) || (pmac->buflen < 0) ||
|
||||
(pmac->block_len > (int)sizeof(pmac->block)) || (pmac->buflen > pmac->block_len)) {
|
||||
@@ -46,7 +43,7 @@ int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen)
|
||||
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(&Z[y])) = *(LTC_FAST_TYPE_PTR_CAST(&in[y])) ^ *(LTC_FAST_TYPE_PTR_CAST(&pmac->Li[y]));
|
||||
}
|
||||
if ((err = cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(Z, Z, &pmac->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
|
||||
@@ -65,7 +62,7 @@ int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen)
|
||||
for (x = 0; x < (unsigned long)pmac->block_len; x++) {
|
||||
Z[x] = pmac->Li[x] ^ pmac->block[x];
|
||||
}
|
||||
if ((err = cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key)) != CRYPT_OK) {
|
||||
if ((err = ecb_encrypt_block(Z, Z, &pmac->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
for (x = 0; x < (unsigned long)pmac->block_len; x++) {
|
||||
|
||||
@@ -124,7 +124,7 @@ int pmac_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 = pmac_memory(idx, tests[x].key, 16, tests[x].msg, tests[x].msglen, outtag, &len)) != CRYPT_OK) {
|
||||
return err;
|
||||
|
||||
Reference in New Issue
Block a user