1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
6
* The library is free for all purposes without any express
9
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
15
PMAC implementation, process data, by Tom St Denis
22
Process data in a PMAC stream
23
@param pmac The PMAC state
24
@param in The data to send through PMAC
25
@param inlen The length of the data to send through PMAC
26
@return CRYPT_OK if successful
28
int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen)
32
unsigned char Z[MAXBLOCKSIZE];
34
LTC_ARGCHK(pmac != NULL);
35
LTC_ARGCHK(in != NULL);
36
if ((err = cipher_is_valid(pmac->cipher_idx)) != CRYPT_OK) {
40
if ((pmac->buflen > (int)sizeof(pmac->block)) || (pmac->buflen < 0) ||
41
(pmac->block_len > (int)sizeof(pmac->block)) || (pmac->buflen > pmac->block_len)) {
42
return CRYPT_INVALID_ARG;
46
if (pmac->buflen == 0 && inlen > 16) {
48
for (x = 0; x < (inlen - 16); x += 16) {
50
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]));
53
cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key);
54
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
55
*((LTC_FAST_TYPE*)(&pmac->checksum[y])) ^= *((LTC_FAST_TYPE*)(&Z[y]));
64
/* ok if the block is full we xor in prev, encrypt and replace prev */
65
if (pmac->buflen == pmac->block_len) {
67
for (x = 0; x < (unsigned long)pmac->block_len; x++) {
68
Z[x] = pmac->Li[x] ^ pmac->block[x];
70
cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key);
71
for (x = 0; x < (unsigned long)pmac->block_len; x++) {
72
pmac->checksum[x] ^= Z[x];
78
n = MIN(inlen, (unsigned long)(pmac->block_len - pmac->buflen));
79
XMEMCPY(pmac->block + pmac->buflen, in, n);
85
#ifdef LTC_CLEAN_STACK
86
zeromem(Z, sizeof(Z));
94
/* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_process.c,v $ */
95
/* $Revision: 1.5 $ */
96
/* $Date: 2005/05/05 14:35:59 $ */