Mercurial > dropbear
comparison libtomcrypt/src/mac/f9/f9_done.c @ 382:0cbe8f6dbf9e
propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 2af22fb4e878750b88f80f90d439b316d229796f)
to branch 'au.asn.ucc.matt.dropbear' (head 02c413252c90e9de8e03d91e9939dde3029f5c0a)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 11 Jan 2007 02:41:05 +0000 |
parents | |
children | f849a5ca2efc |
comparison
equal
deleted
inserted
replaced
379:b66a00272a90 | 382:0cbe8f6dbf9e |
---|---|
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.com | |
10 */ | |
11 #include "tomcrypt.h" | |
12 | |
13 /** | |
14 @file f9_done.c | |
15 f9 Support, terminate the state | |
16 */ | |
17 | |
18 #ifdef LTC_F9_MODE | |
19 | |
20 /** Terminate the f9-MAC state | |
21 @param f9 f9 state to terminate | |
22 @param out [out] Destination for the MAC tag | |
23 @param outlen [in/out] Destination size and final tag size | |
24 Return CRYPT_OK on success | |
25 */ | |
26 int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen) | |
27 { | |
28 int err, x; | |
29 LTC_ARGCHK(f9 != NULL); | |
30 LTC_ARGCHK(out != NULL); | |
31 | |
32 /* check structure */ | |
33 if ((err = cipher_is_valid(f9->cipher)) != CRYPT_OK) { | |
34 return err; | |
35 } | |
36 | |
37 if ((f9->blocksize > cipher_descriptor[f9->cipher].block_length) || (f9->blocksize < 0) || | |
38 (f9->buflen > f9->blocksize) || (f9->buflen < 0)) { | |
39 return CRYPT_INVALID_ARG; | |
40 } | |
41 | |
42 if (f9->buflen != 0) { | |
43 /* encrypt */ | |
44 cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key); | |
45 f9->buflen = 0; | |
46 for (x = 0; x < f9->blocksize; x++) { | |
47 f9->ACC[x] ^= f9->IV[x]; | |
48 } | |
49 } | |
50 | |
51 /* schedule modified key */ | |
52 if ((err = cipher_descriptor[f9->cipher].setup(f9->akey, f9->keylen, 0, &f9->key)) != CRYPT_OK) { | |
53 return err; | |
54 } | |
55 | |
56 /* encrypt the ACC */ | |
57 cipher_descriptor[f9->cipher].ecb_encrypt(f9->ACC, f9->ACC, &f9->key); | |
58 cipher_descriptor[f9->cipher].done(&f9->key); | |
59 | |
60 /* extract tag */ | |
61 for (x = 0; x < f9->blocksize && (unsigned long)x < *outlen; x++) { | |
62 out[x] = f9->ACC[x]; | |
63 } | |
64 *outlen = x; | |
65 | |
66 #ifdef LTC_CLEAN_STACK | |
67 zeromem(f9, sizeof(*f9)); | |
68 #endif | |
69 return CRYPT_OK; | |
70 } | |
71 | |
72 #endif | |
73 | |
74 /* $Source: /cvs/libtom/libtomcrypt/src/mac/f9/f9_done.c,v $ */ | |
75 /* $Revision: 1.5 $ */ | |
76 /* $Date: 2006/11/09 01:53:32 $ */ | |
77 |