comparison pmac_process.c @ 3:7faae8f46238 libtomcrypt-orig

Branch renaming
author Matt Johnston <matt@ucc.asn.au>
date Mon, 31 May 2004 18:25:41 +0000
parents
children 5d99163f7e32
comparison
equal deleted inserted replaced
-1:000000000000 3:7faae8f46238
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org
10 */
11
12 /* PMAC implementation by Tom St Denis */
13 #include "mycrypt.h"
14
15 #ifdef PMAC
16
17 int pmac_process(pmac_state *state, const unsigned char *buf, unsigned long len)
18 {
19 int err, n, x;
20 unsigned char Z[MAXBLOCKSIZE];
21
22 _ARGCHK(state != NULL);
23 _ARGCHK(buf != NULL);
24 if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
25 return err;
26 }
27
28 if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) ||
29 (state->block_len > (int)sizeof(state->block)) || (state->buflen > state->block_len)) {
30 return CRYPT_INVALID_ARG;
31 }
32
33 while (len != 0) {
34 /* ok if the block is full we xor in prev, encrypt and replace prev */
35 if (state->buflen == state->block_len) {
36 pmac_shift_xor(state);
37 for (x = 0; x < state->block_len; x++) {
38 Z[x] = state->Li[x] ^ state->block[x];
39 }
40 cipher_descriptor[state->cipher_idx].ecb_encrypt(Z, Z, &state->key);
41 for (x = 0; x < state->block_len; x++) {
42 state->checksum[x] ^= Z[x];
43 }
44 state->buflen = 0;
45 }
46
47 /* add bytes */
48 n = MIN(len, (unsigned long)(state->block_len - state->buflen));
49 memcpy(state->block + state->buflen, buf, n);
50 state->buflen += n;
51 len -= n;
52 buf += n;
53 }
54
55 #ifdef CLEAN_STACK
56 zeromem(Z, sizeof(Z));
57 #endif
58
59 return CRYPT_OK;
60 }
61
62 #endif