Home | History | Annotate | Download | only in eax
      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, tomstdenis (at) gmail.com, http://libtomcrypt.com
     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.4 $ */
     82 /* $Date: 2006/03/31 14:15:35 $ */
     83