comparison libtomcrypt/src/mac/pmac/pmac_process.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file pmac_process.c 12 @file pmac_process.c
15 PMAC implementation, process data, by Tom St Denis 13 PMAC implementation, process data, by Tom St Denis
16 */ 14 */
17 15
18 16
19 #ifdef LTC_PMAC 17 #ifdef LTC_PMAC
20 18
46 if (pmac->buflen == 0 && inlen > 16) { 44 if (pmac->buflen == 0 && inlen > 16) {
47 unsigned long y; 45 unsigned long y;
48 for (x = 0; x < (inlen - 16); x += 16) { 46 for (x = 0; x < (inlen - 16); x += 16) {
49 pmac_shift_xor(pmac); 47 pmac_shift_xor(pmac);
50 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { 48 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
51 *((LTC_FAST_TYPE*)(&Z[y])) = *((LTC_FAST_TYPE*)(&in[y])) ^ *((LTC_FAST_TYPE*)(&pmac->Li[y])); 49 *(LTC_FAST_TYPE_PTR_CAST(&Z[y])) = *(LTC_FAST_TYPE_PTR_CAST(&in[y])) ^ *(LTC_FAST_TYPE_PTR_CAST(&pmac->Li[y]));
52 } 50 }
53 if ((err = cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key)) != CRYPT_OK) { 51 if ((err = cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key)) != CRYPT_OK) {
54 return err; 52 return err;
55 } 53 }
56 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { 54 for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
57 *((LTC_FAST_TYPE*)(&pmac->checksum[y])) ^= *((LTC_FAST_TYPE*)(&Z[y])); 55 *(LTC_FAST_TYPE_PTR_CAST(&pmac->checksum[y])) ^= *(LTC_FAST_TYPE_PTR_CAST(&Z[y]));
58 } 56 }
59 in += 16; 57 in += 16;
60 } 58 }
61 inlen -= x; 59 inlen -= x;
62 } 60 }
63 #endif 61 #endif
64 62
65 while (inlen != 0) { 63 while (inlen != 0) {
66 /* ok if the block is full we xor in prev, encrypt and replace prev */ 64 /* ok if the block is full we xor in prev, encrypt and replace prev */
67 if (pmac->buflen == pmac->block_len) { 65 if (pmac->buflen == pmac->block_len) {
68 pmac_shift_xor(pmac); 66 pmac_shift_xor(pmac);
69 for (x = 0; x < (unsigned long)pmac->block_len; x++) { 67 for (x = 0; x < (unsigned long)pmac->block_len; x++) {
70 Z[x] = pmac->Li[x] ^ pmac->block[x]; 68 Z[x] = pmac->Li[x] ^ pmac->block[x];
93 return CRYPT_OK; 91 return CRYPT_OK;
94 } 92 }
95 93
96 #endif 94 #endif
97 95
98 /* $Source$ */ 96 /* ref: $Format:%D$ */
99 /* $Revision$ */ 97 /* git commit: $Format:%H$ */
100 /* $Date$ */ 98 /* commit time: $Format:%ai$ */