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@iahu.ca, http://libtomcrypt.org
11
/* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */
16
int omac_done(omac_state *state, unsigned char *out, unsigned long *outlen)
21
_ARGCHK(state != NULL);
23
_ARGCHK(outlen != NULL);
24
if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
28
if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) ||
29
(state->blklen > (int)sizeof(state->block)) || (state->buflen > state->blklen)) {
30
return CRYPT_INVALID_ARG;
34
if (state->buflen != state->blklen) {
35
/* add the 0x80 byte */
36
state->block[state->buflen++] = 0x80;
39
while (state->buflen < state->blklen) {
40
state->block[state->buflen++] = 0x00;
47
/* now xor prev + Lu[mode] */
48
for (x = 0; x < (unsigned)state->blklen; x++) {
49
state->block[x] ^= state->prev[x] ^ state->Lu[mode][x];
53
cipher_descriptor[state->cipher_idx].ecb_encrypt(state->block, state->block, &state->key);
56
for (x = 0; x < (unsigned)state->blklen && x < *outlen; x++) {
57
out[x] = state->block[x];
62
zeromem(state, sizeof(*state));