comparison omac_done.c @ 143:5d99163f7e32 libtomcrypt-orig

import of libtomcrypt 0.99
author Matt Johnston <matt@ucc.asn.au>
date Sun, 19 Dec 2004 11:34:45 +0000
parents 7faae8f46238
children
comparison
equal deleted inserted replaced
15:6362d3854bb4 143:5d99163f7e32
13 13
14 #ifdef OMAC 14 #ifdef OMAC
15 15
16 int omac_done(omac_state *state, unsigned char *out, unsigned long *outlen) 16 int omac_done(omac_state *state, unsigned char *out, unsigned long *outlen)
17 { 17 {
18 int err, mode, x; 18 int err, mode;
19 unsigned x;
19 20
20 _ARGCHK(state != NULL); 21 _ARGCHK(state != NULL);
21 _ARGCHK(out != NULL); 22 _ARGCHK(out != NULL);
23 _ARGCHK(outlen != NULL);
22 if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) { 24 if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
23 return err; 25 return err;
24 } 26 }
25 27
26 if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) || 28 if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) ||
41 } else { 43 } else {
42 mode = 0; 44 mode = 0;
43 } 45 }
44 46
45 /* now xor prev + Lu[mode] */ 47 /* now xor prev + Lu[mode] */
46 for (x = 0; x < state->blklen; x++) { 48 for (x = 0; x < (unsigned)state->blklen; x++) {
47 state->block[x] ^= state->prev[x] ^ state->Lu[mode][x]; 49 state->block[x] ^= state->prev[x] ^ state->Lu[mode][x];
48 } 50 }
49 51
50 /* encrypt it */ 52 /* encrypt it */
51 cipher_descriptor[state->cipher_idx].ecb_encrypt(state->block, state->block, &state->key); 53 cipher_descriptor[state->cipher_idx].ecb_encrypt(state->block, state->block, &state->key);
52 54
53 /* output it */ 55 /* output it */
54 for (x = 0; x < state->blklen && (unsigned long)x < *outlen; x++) { 56 for (x = 0; x < (unsigned)state->blklen && x < *outlen; x++) {
55 out[x] = state->block[x]; 57 out[x] = state->block[x];
56 } 58 }
57 *outlen = x; 59 *outlen = x;
58 60
59 #ifdef CLEAN_STACK 61 #ifdef CLEAN_STACK