comparison libtomcrypt/src/mac/pmac/pmac_done.c @ 302:973fccb59ea4 ucc-axis-hack

propagate from branch 'au.asn.ucc.matt.dropbear' (head 11034278bd1917bebcbdc69cf53b1891ce9db121) to branch 'au.asn.ucc.matt.dropbear.ucc-axis-hack' (head 10a1f614fec73d0820c3f61160d9db409b9beb46)
author Matt Johnston <matt@ucc.asn.au>
date Sat, 25 Mar 2006 12:59:58 +0000
parents 1b9e69c058d2
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
299:740e782679be 302:973fccb59ea4
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 $ */