blob: de7a5aa08614c1dafe391ce4392f5ac51d4cc360 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*/
#include "tomcrypt.h"
/**
@file pmac_done.c
PMAC implementation, terminate a session, by Tom St Denis
*/
#ifdef LTC_PMAC
int pmac_done(pmac_state *state, unsigned char *out, unsigned long *outlen)
{
int err, x;
LTC_ARGCHK(state != NULL);
LTC_ARGCHK(out != NULL);
if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
return err;
}
if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) ||
(state->block_len > (int)sizeof(state->block)) || (state->buflen > state->block_len)) {
return CRYPT_INVALID_ARG;
}
/* handle padding. If multiple xor in L/x */
if (state->buflen == state->block_len) {
/* xor Lr against the checksum */
for (x = 0; x < state->block_len; x++) {
state->checksum[x] ^= state->block[x] ^ state->Lr[x];
}
} else {
/* otherwise xor message bytes then the 0x80 byte */
for (x = 0; x < state->buflen; x++) {
state->checksum[x] ^= state->block[x];
}
state->checksum[x] ^= 0x80;
}
/* encrypt it */
if ((err = cipher_descriptor[state->cipher_idx].ecb_encrypt(state->checksum, state->checksum, &state->key)) != CRYPT_OK) {
return err;
}
cipher_descriptor[state->cipher_idx].done(&state->key);
/* store it */
for (x = 0; x < state->block_len && x < (int)*outlen; x++) {
out[x] = state->checksum[x];
}
*outlen = x;
#ifdef LTC_CLEAN_STACK
zeromem(state, sizeof(*state));
#endif
return CRYPT_OK;
}
#endif
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */
|