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
11 @file eax_encrypt_authenticate_memory.c
12 EAX implementation, encrypt a block of memory, by Tom St Denis
19 EAX encrypt and produce an authentication tag
20 @param cipher The index of the cipher desired
21 @param key The secret key to use
22 @param keylen The length of the secret key (octets)
23 @param nonce The session nonce [use once]
24 @param noncelen The length of the nonce
25 @param header The header for the session
26 @param headerlen The length of the header (octets)
27 @param pt The plaintext
28 @param ptlen The length of the plaintext (octets)
29 @param ct [out] The ciphertext
30 @param tag [out] The destination tag
31 @param taglen [in/out] The max size and resulting size of the authentication tag
32 @return CRYPT_OK if successful
34 int eax_encrypt_authenticate_memory(int cipher,
35 const unsigned char *key, unsigned long keylen,
36 const unsigned char *nonce, unsigned long noncelen,
37 const unsigned char *header, unsigned long headerlen,
38 const unsigned char *pt, unsigned long ptlen,
40 unsigned char *tag, unsigned long *taglen)
45 LTC_ARGCHK(key != NULL);
46 LTC_ARGCHK(pt != NULL);
47 LTC_ARGCHK(ct != NULL);
48 LTC_ARGCHK(tag != NULL);
49 LTC_ARGCHK(taglen != NULL);
51 eax = XMALLOC(sizeof(*eax));
53 if ((err = eax_init(eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
57 if ((err = eax_encrypt(eax, pt, ct, ptlen)) != CRYPT_OK) {
61 if ((err = eax_done(eax, tag, taglen)) != CRYPT_OK) {
67 #ifdef LTC_CLEAN_STACK
68 zeromem(eax, sizeof(*eax));
78 /* ref: $Format:%D$ */
79 /* git commit: $Format:%H$ */
80 /* commit time: $Format:%ai$ */