diff pmac_init.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_init.c	Tue Jun 15 14:07:21 2004 +0000
+++ b/pmac_init.c	Sun Dec 19 11:34:45 2004 +0000
@@ -35,7 +35,7 @@
 int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned long keylen)
 {
    int poly, x, y, m, err;
-   unsigned char L[MAXBLOCKSIZE];
+   unsigned char *L;
 
    _ARGCHK(pmac  != NULL);
    _ARGCHK(key   != NULL);
@@ -61,12 +61,18 @@
       return err;
    }
  
+   /* allocate L */
+   L = XMALLOC(pmac->block_len);
+   if (L == NULL) {
+      return CRYPT_MEM;
+   }
+
    /* find L = E[0] */
    zeromem(L, pmac->block_len);
    cipher_descriptor[cipher].ecb_encrypt(L, L, &pmac->key);
 
    /* find Ls[i] = L << i for i == 0..31 */
-   memcpy(pmac->Ls[0], L, pmac->block_len);
+   XMEMCPY(pmac->Ls[0], L, pmac->block_len);
    for (x = 1; x < 32; x++) {
        m = pmac->Ls[x-1][0] >> 7;
        for (y = 0; y < pmac->block_len-1; y++) {
@@ -105,9 +111,11 @@
     zeromem(pmac->checksum, sizeof(pmac->checksum));
 
 #ifdef CLEAN_STACK
-    zeromem(L, sizeof(L));
+    zeromem(L, pmac->block_len);
 #endif
 
+    XFREE(L);
+
     return CRYPT_OK;
 }