diff ocb_done_decrypt.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/ocb_done_decrypt.c	Tue Jun 15 14:07:21 2004 +0000
+++ b/ocb_done_decrypt.c	Sun Dec 19 11:34:45 2004 +0000
@@ -20,7 +20,7 @@
                      const unsigned char *tag, unsigned long taglen, int *res)
 {
    int err;
-   unsigned char tagbuf[MAXBLOCKSIZE];
+   unsigned char *tagbuf;
    unsigned long tagbuflen;
 
    _ARGCHK(ocb != NULL);
@@ -29,22 +29,33 @@
    _ARGCHK(tag != NULL);
    _ARGCHK(res != NULL);
 
+   /* default to failed */
    *res = 0;
 
-   tagbuflen = sizeof(tagbuf);
+   /* allocate memory */
+   tagbuf = XMALLOC(MAXBLOCKSIZE);
+   if (tagbuf == NULL) {
+      return CRYPT_MEM;
+   }
+
+   tagbuflen = MAXBLOCKSIZE;
    if ((err = __ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) {
-      return err;
+      goto __ERR;
    }
 
    if (taglen <= tagbuflen && memcmp(tagbuf, tag, taglen) == 0) {
       *res = 1;
    }
 
+   err = CRYPT_OK;
+__ERR:
 #ifdef CLEAN_STACK
-   zeromem(tagbuf, sizeof(tagbuf));
+   zeromem(tagbuf, MAXBLOCKSIZE);
 #endif
 
-   return CRYPT_OK;
+   XFREE(tagbuf);
+
+   return err;
 }
 
 #endif