diff pmac_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/pmac_memory.c	Tue Jun 15 14:07:21 2004 +0000
+++ b/pmac_memory.c	Sun Dec 19 11:34:45 2004 +0000
@@ -20,25 +20,37 @@
                       unsigned char *out, unsigned long *outlen)
 {
    int err;
-   pmac_state pmac;
+   pmac_state *pmac;
 
    _ARGCHK(key    != NULL);
    _ARGCHK(msg    != NULL);
    _ARGCHK(out    != NULL);
    _ARGCHK(outlen != NULL);
 
-
-   if ((err = pmac_init(&pmac, cipher, key, keylen)) != CRYPT_OK) {
-      return err;
+   /* allocate ram for pmac state */
+   pmac = XMALLOC(sizeof(pmac_state));
+   if (pmac == NULL) {
+      return CRYPT_MEM;
    }
-   if ((err = pmac_process(&pmac, msg, msglen)) != CRYPT_OK) {
-      return err;
+   
+   if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) {
+      goto __ERR;
    }
-   if ((err = pmac_done(&pmac, out, outlen)) != CRYPT_OK) {
-      return err;
+   if ((err = pmac_process(pmac, msg, msglen)) != CRYPT_OK) {
+      goto __ERR;
+   }
+   if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) {
+      goto __ERR;
    }
 
-   return CRYPT_OK;
+   err = CRYPT_OK;
+__ERR:
+#ifdef CLEAN_STACK
+   zeromem(pmac, sizeof(pmac_state));
+#endif
+
+   XFREE(pmac);
+   return err;   
 }
 
 #endif