Mercurial > dropbear
comparison pmac_done.c @ 3:7faae8f46238 libtomcrypt-orig
Branch renaming
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 31 May 2004 18:25:41 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 3:7faae8f46238 |
---|---|
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 | |
12 /* PMAC implementation by Tom St Denis */ | |
13 #include "mycrypt.h" | |
14 | |
15 #ifdef PMAC | |
16 | |
17 int pmac_done(pmac_state *state, unsigned char *out, unsigned long *outlen) | |
18 { | |
19 int err, x; | |
20 | |
21 _ARGCHK(state != NULL); | |
22 _ARGCHK(out != NULL); | |
23 if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) { | |
24 return err; | |
25 } | |
26 | |
27 if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) || | |
28 (state->block_len > (int)sizeof(state->block)) || (state->buflen > state->block_len)) { | |
29 return CRYPT_INVALID_ARG; | |
30 } | |
31 | |
32 | |
33 /* handle padding. If multiple xor in L/x */ | |
34 | |
35 if (state->buflen == state->block_len) { | |
36 /* xor Lr against the checksum */ | |
37 for (x = 0; x < state->block_len; x++) { | |
38 state->checksum[x] ^= state->block[x] ^ state->Lr[x]; | |
39 } | |
40 } else { | |
41 /* otherwise xor message bytes then the 0x80 byte */ | |
42 for (x = 0; x < state->buflen; x++) { | |
43 state->checksum[x] ^= state->block[x]; | |
44 } | |
45 state->checksum[x] ^= 0x80; | |
46 } | |
47 | |
48 /* encrypt it */ | |
49 cipher_descriptor[state->cipher_idx].ecb_encrypt(state->checksum, state->checksum, &state->key); | |
50 | |
51 /* store it */ | |
52 for (x = 0; x < state->block_len && x <= (int)*outlen; x++) { | |
53 out[x] = state->checksum[x]; | |
54 } | |
55 *outlen = x; | |
56 | |
57 #ifdef CLEAN_STACK | |
58 zeromem(state, sizeof(*state)); | |
59 #endif | |
60 return CRYPT_OK; | |
61 } | |
62 | |
63 #endif | |
64 |