diff eax_encrypt_authenticate_memory.c @ 143:5d99163f7e32 libtomcrypt-orig

import of libtomcrypt 0.99
author Matt Johnston <matt@ucc.asn.au>
date Sun, 19 Dec 2004 11:34:45 +0000
parents 7faae8f46238
children
line wrap: on
line diff
--- a/eax_encrypt_authenticate_memory.c	Tue Jun 15 14:07:21 2004 +0000
+++ b/eax_encrypt_authenticate_memory.c	Sun Dec 19 11:34:45 2004 +0000
@@ -23,21 +23,31 @@
           unsigned char *tag,    unsigned long *taglen)
 {
    int err;
-   eax_state eax;
+   eax_state *eax;
 
-   if ((err = eax_init(&eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
-      return err;
+   eax = XMALLOC(sizeof(eax_state));
+
+   if ((err = eax_init(eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
+      goto __ERR; 
    }
 
-   if ((err = eax_encrypt(&eax, pt, ct, ptlen)) != CRYPT_OK) {
-      return err;
+   if ((err = eax_encrypt(eax, pt, ct, ptlen)) != CRYPT_OK) {
+      goto __ERR; 
    }
  
-   if ((err = eax_done(&eax, tag, taglen)) != CRYPT_OK) {
-      return err;
+   if ((err = eax_done(eax, tag, taglen)) != CRYPT_OK) {
+      goto __ERR; 
    }
 
-   return CRYPT_OK;
+   err = CRYPT_OK;
+__ERR:
+#ifdef CLEAN_STACK
+   zeromem(eax, sizeof(eax_state));
+#endif
+
+   XFREE(eax);
+
+   return err;   
 }
 
 #endif