comparison omac_done.c @ 0:d7da3b1e1540 libtomcrypt

put back the 0.95 makefile which was inadvertently merged over
author Matt Johnston <matt@ucc.asn.au>
date Mon, 31 May 2004 18:21:40 +0000
parents
children 5d99163f7e32
comparison
equal deleted inserted replaced
-1:000000000000 0:d7da3b1e1540
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_done(omac_state *state, unsigned char *out, unsigned long *outlen)
17 {
18 int err, mode, x;
19
20 _ARGCHK(state != NULL);
21 _ARGCHK(out != 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 /* figure out mode */
32 if (state->buflen != state->blklen) {
33 /* add the 0x80 byte */
34 state->block[state->buflen++] = 0x80;
35
36 /* pad with 0x00 */
37 while (state->buflen < state->blklen) {
38 state->block[state->buflen++] = 0x00;
39 }
40 mode = 1;
41 } else {
42 mode = 0;
43 }
44
45 /* now xor prev + Lu[mode] */
46 for (x = 0; x < state->blklen; x++) {
47 state->block[x] ^= state->prev[x] ^ state->Lu[mode][x];
48 }
49
50 /* encrypt it */
51 cipher_descriptor[state->cipher_idx].ecb_encrypt(state->block, state->block, &state->key);
52
53 /* output it */
54 for (x = 0; x < state->blklen && (unsigned long)x < *outlen; x++) {
55 out[x] = state->block[x];
56 }
57 *outlen = x;
58
59 #ifdef CLEAN_STACK
60 zeromem(state, sizeof(*state));
61 #endif
62 return CRYPT_OK;
63 }
64
65 #endif
66