3
|
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 /* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */ |
|
12 #include "mycrypt.h" |
|
13 |
|
14 #ifdef OMAC |
|
15 |
|
16 int omac_process(omac_state *state, const unsigned char *buf, unsigned long len) |
|
17 { |
|
18 int err, n, x; |
|
19 |
|
20 _ARGCHK(state != NULL); |
|
21 _ARGCHK(buf != NULL); |
|
22 if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) { |
|
23 return err; |
|
24 } |
|
25 |
|
26 if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) || |
|
27 (state->blklen > (int)sizeof(state->block)) || (state->buflen > state->blklen)) { |
|
28 return CRYPT_INVALID_ARG; |
|
29 } |
|
30 |
|
31 while (len != 0) { |
|
32 /* ok if the block is full we xor in prev, encrypt and replace prev */ |
|
33 if (state->buflen == state->blklen) { |
|
34 for (x = 0; x < state->blklen; x++) { |
|
35 state->block[x] ^= state->prev[x]; |
|
36 } |
|
37 cipher_descriptor[state->cipher_idx].ecb_encrypt(state->block, state->prev, &state->key); |
|
38 state->buflen = 0; |
|
39 } |
|
40 |
|
41 /* add bytes */ |
|
42 n = MIN(len, (unsigned long)(state->blklen - state->buflen)); |
143
|
43 XMEMCPY(state->block + state->buflen, buf, n); |
3
|
44 state->buflen += n; |
|
45 len -= n; |
|
46 buf += n; |
|
47 } |
|
48 |
|
49 return CRYPT_OK; |
|
50 } |
|
51 |
|
52 #endif |
|
53 |