comparison src/mac/pmac/pmac_done.c @ 280:59400faa4b44 libtomcrypt-orig libtomcrypt-1.05

Re-import libtomcrypt 1.05 for cleaner propagating. From crypt-1.05.tar.bz2, SHA1 of 88250202bb51570dc64f7e8f1c943cda9479258f
author Matt Johnston <matt@ucc.asn.au>
date Wed, 08 Mar 2006 12:58:00 +0000
parents
children d5faf4814ddb
comparison
equal deleted inserted replaced
-1:000000000000 280:59400faa4b44
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
69
70 /* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_done.c,v $ */
71 /* $Revision: 1.4 $ */
72 /* $Date: 2005/05/05 14:35:59 $ */