comparison libtomcrypt/src/encauth/eax/eax_encrypt_authenticate_memory.c @ 285:1b9e69c058d2

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3) to branch 'au.asn.ucc.matt.dropbear' (head fdf4a7a3b97ae5046139915de7e40399cceb2c01)
author Matt Johnston <matt@ucc.asn.au>
date Wed, 08 Mar 2006 13:23:58 +0000
parents
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
281:997e6f7dc01e 285:1b9e69c058d2
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 /**
13 @file eax_encrypt_authenticate_memory.c
14 EAX implementation, encrypt a block of memory, by Tom St Denis
15 */
16 #include "tomcrypt.h"
17
18 #ifdef EAX_MODE
19
20 /**
21 EAX encrypt and produce an authentication tag
22 @param cipher The index of the cipher desired
23 @param key The secret key to use
24 @param keylen The length of the secret key (octets)
25 @param nonce The session nonce [use once]
26 @param noncelen The length of the nonce
27 @param header The header for the session
28 @param headerlen The length of the header (octets)
29 @param pt The plaintext
30 @param ptlen The length of the plaintext (octets)
31 @param ct [out] The ciphertext
32 @param tag [out] The destination tag
33 @param taglen [in/out] The max size and resulting size of the authentication tag
34 @return CRYPT_OK if successful
35 */
36 int eax_encrypt_authenticate_memory(int cipher,
37 const unsigned char *key, unsigned long keylen,
38 const unsigned char *nonce, unsigned long noncelen,
39 const unsigned char *header, unsigned long headerlen,
40 const unsigned char *pt, unsigned long ptlen,
41 unsigned char *ct,
42 unsigned char *tag, unsigned long *taglen)
43 {
44 int err;
45 eax_state *eax;
46
47 LTC_ARGCHK(key != NULL);
48 LTC_ARGCHK(pt != NULL);
49 LTC_ARGCHK(ct != NULL);
50 LTC_ARGCHK(tag != NULL);
51 LTC_ARGCHK(taglen != NULL);
52
53 eax = XMALLOC(sizeof(*eax));
54
55 if ((err = eax_init(eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
56 goto LBL_ERR;
57 }
58
59 if ((err = eax_encrypt(eax, pt, ct, ptlen)) != CRYPT_OK) {
60 goto LBL_ERR;
61 }
62
63 if ((err = eax_done(eax, tag, taglen)) != CRYPT_OK) {
64 goto LBL_ERR;
65 }
66
67 err = CRYPT_OK;
68 LBL_ERR:
69 #ifdef LTC_CLEAN_STACK
70 zeromem(eax, sizeof(*eax));
71 #endif
72
73 XFREE(eax);
74
75 return err;
76 }
77
78 #endif
79
80 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_encrypt_authenticate_memory.c,v $ */
81 /* $Revision: 1.3 $ */
82 /* $Date: 2005/05/05 14:35:58 $ */