comparison src/mac/pmac/pmac_done.c @ 191:1c15b283127b libtomcrypt-orig

Import of libtomcrypt 1.02 with manual path rename rearrangement etc
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 May 2005 13:23:02 +0000
parents
children 39d5d58461d6
comparison
equal deleted inserted replaced
143:5d99163f7e32 191:1c15b283127b
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 #include "tomcrypt.h"
12
13 /**
14 @file pmac_done.c
15 PMAC implementation, terminate a session, by Tom St Denis
16 */
17
18 #ifdef PMAC
19
20 int pmac_done(pmac_state *state, unsigned char *out, unsigned long *outlen)
21 {
22 int err, x;
23
24 LTC_ARGCHK(state != NULL);
25 LTC_ARGCHK(out != NULL);
26 if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
27 return err;
28 }
29
30 if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) ||
31 (state->block_len > (int)sizeof(state->block)) || (state->buflen > state->block_len)) {
32 return CRYPT_INVALID_ARG;
33 }
34
35
36 /* handle padding. If multiple xor in L/x */
37
38 if (state->buflen == state->block_len) {
39 /* xor Lr against the checksum */
40 for (x = 0; x < state->block_len; x++) {
41 state->checksum[x] ^= state->block[x] ^ state->Lr[x];
42 }
43 } else {
44 /* otherwise xor message bytes then the 0x80 byte */
45 for (x = 0; x < state->buflen; x++) {
46 state->checksum[x] ^= state->block[x];
47 }
48 state->checksum[x] ^= 0x80;
49 }
50
51 /* encrypt it */
52 cipher_descriptor[state->cipher_idx].ecb_encrypt(state->checksum, state->checksum, &state->key);
53 cipher_descriptor[state->cipher_idx].done(&state->key);
54
55 /* store it */
56 for (x = 0; x < state->block_len && x <= (int)*outlen; x++) {
57 out[x] = state->checksum[x];
58 }
59 *outlen = x;
60
61 #ifdef LTC_CLEAN_STACK
62 zeromem(state, sizeof(*state));
63 #endif
64 return CRYPT_OK;
65 }
66
67 #endif
68