Mercurial > dropbear
view pmac_done.c @ 211:f01f0400314d libtomcrypt
disapproval of revision 6a39eb8b36778460fca83b8149df2a8b6d3327fd
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 06 Jul 2005 13:23:45 +0000 |
parents | d7da3b1e1540 |
children |
line wrap: on
line source
/* 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. * * Tom St Denis, [email protected], http://libtomcrypt.org */ /* PMAC implementation by Tom St Denis */ #include "mycrypt.h" #ifdef PMAC int pmac_done(pmac_state *state, unsigned char *out, unsigned long *outlen) { int err, x; _ARGCHK(state != NULL); _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 */ cipher_descriptor[state->cipher_idx].ecb_encrypt(state->checksum, state->checksum, &state->key); /* store it */ for (x = 0; x < state->block_len && x <= (int)*outlen; x++) { out[x] = state->checksum[x]; } *outlen = x; #ifdef CLEAN_STACK zeromem(state, sizeof(*state)); #endif return CRYPT_OK; } #endif