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
13 PMAC implementation, terminate a session, by Tom St Denis
18 int pmac_done(pmac_state *state, unsigned char *out, unsigned long *outlen)
22 LTC_ARGCHK(state != NULL);
23 LTC_ARGCHK(out != 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->block_len > (int)sizeof(state->block)) || (state->buflen > state->block_len)) {
30 return CRYPT_INVALID_ARG;
34 /* handle padding. If multiple xor in L/x */
36 if (state->buflen == state->block_len) {
37 /* xor Lr against the checksum */
38 for (x = 0; x < state->block_len; x++) {
39 state->checksum[x] ^= state->block[x] ^ state->Lr[x];
42 /* otherwise xor message bytes then the 0x80 byte */
43 for (x = 0; x < state->buflen; x++) {
44 state->checksum[x] ^= state->block[x];
46 state->checksum[x] ^= 0x80;
50 if ((err = cipher_descriptor[state->cipher_idx].ecb_encrypt(state->checksum, state->checksum, &state->key)) != CRYPT_OK) {
53 cipher_descriptor[state->cipher_idx].done(&state->key);
56 for (x = 0; x < state->block_len && x < (int)*outlen; x++) {
57 out[x] = state->checksum[x];
61 #ifdef LTC_CLEAN_STACK
62 zeromem(state, sizeof(*state));
70 /* ref: $Format:%D$ */
71 /* git commit: $Format:%H$ */
72 /* commit time: $Format:%ai$ */