diff s_ocb_done.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/s_ocb_done.c	Tue Jun 15 14:07:21 2004 +0000
+++ b/s_ocb_done.c	Sun Dec 19 11:34:45 2004 +0000
@@ -25,7 +25,7 @@
                      unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode)
 
 {
-   unsigned char Z[MAXBLOCKSIZE], Y[MAXBLOCKSIZE], X[MAXBLOCKSIZE];
+   unsigned char *Z, *Y, *X;
    int err, x;
 
    _ARGCHK(ocb    != NULL);
@@ -41,9 +41,26 @@
       return CRYPT_INVALID_ARG;
    }
 
+   /* allocate ram */
+   Z = XMALLOC(MAXBLOCKSIZE);
+   Y = XMALLOC(MAXBLOCKSIZE);
+   X = XMALLOC(MAXBLOCKSIZE);
+   if (X == NULL || Y == NULL || Z == NULL) {
+      if (X != NULL) {
+         XFREE(X);
+      }
+      if (Y != NULL) {
+         XFREE(Y);
+      }
+      if (Z != NULL) {
+         XFREE(Z);
+      }
+      return CRYPT_MEM;
+   }
+
    /* compute X[m] = len(pt[m]) XOR Lr XOR Z[m] */
    ocb_shift_xor(ocb, X); 
-   memcpy(Z, X, ocb->block_len);
+   XMEMCPY(Z, X, ocb->block_len);
 
    X[ocb->block_len-1] ^= (ptlen*8)&255;
    X[ocb->block_len-2] ^= ((ptlen*8)>>8)&255;
@@ -90,11 +107,16 @@
    *taglen = x;
 
 #ifdef CLEAN_STACK
-   zeromem(X, sizeof(X));
-   zeromem(Y, sizeof(Y));
-   zeromem(Z, sizeof(Z));
+   zeromem(X, MAXBLOCKSIZE);
+   zeromem(Y, MAXBLOCKSIZE);
+   zeromem(Z, MAXBLOCKSIZE);
    zeromem(ocb, sizeof(*ocb));
 #endif
+   
+   XFREE(X);
+   XFREE(Y);
+   XFREE(Z);
+
    return CRYPT_OK;
 }