Fix link error in relocatability wrappers, due to xalloc_die().
[gnulib.git] / lib / rijndael-api-fst.c
index b7053a5..b55df79 100644 (file)
@@ -1,5 +1,5 @@
 /* rijndael-api-fst.c --- Rijndael cipher implementation.
- * Copyright (C) 2005 Free Software Foundation, Inc.
+ * Copyright (C) 2005, 2006 Free Software Foundation, Inc.
  *
  * This file is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
@@ -25,9 +25,7 @@
  * http://www.iaik.tu-graz.ac.at/research/krypto/AES/old/~rijmen/rijndael/rijndael-fst-3.0.zip
  */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
 
 /**
  * rijndael-api-fst.c
@@ -244,7 +242,7 @@ rijndaelBlockEncrypt (rijndaelCipherInstance *cipher,
          ((uint32_t *) block)[3] = ((uint32_t *) input)[3] ^
            ((uint32_t *) iv)[3];
          rijndaelEncrypt (key->rk, key->Nr, block, outBuffer);
-         iv = outBuffer;
+         memcpy (cipher->IV, outBuffer, 16);
          input += 16;
          outBuffer += 16;
        }
@@ -327,7 +325,7 @@ rijndaelPadEncrypt (rijndaelCipherInstance *cipher,
          ((uint32_t *) block)[3] = ((uint32_t *) input)[3] ^
            ((uint32_t *) iv)[3];
          rijndaelEncrypt (key->rk, key->Nr, block, outBuffer);
-         iv = outBuffer;
+         memcpy (cipher->IV, outBuffer, 16);
          input += 16;
          outBuffer += 16;
        }
@@ -342,6 +340,7 @@ rijndaelPadEncrypt (rijndaelCipherInstance *cipher,
          block[i] = (char) padLen ^ iv[i];
        }
       rijndaelEncrypt (key->rk, key->Nr, block, outBuffer);
+      memcpy (cipher->IV, outBuffer, 16);
       break;
 
     default:
@@ -360,10 +359,10 @@ rijndaelBlockDecrypt (rijndaelCipherInstance *cipher,
   size_t i, k, t, numBlocks;
   char block[16], *iv;
 
-  if (cipher == NULL ||
-      key == NULL ||
-      cipher->mode != RIJNDAEL_MODE_CFB1
-      && key->direction == RIJNDAEL_DIR_ENCRYPT)
+  if (cipher == NULL
+      || key == NULL
+      || (cipher->mode != RIJNDAEL_MODE_CFB1
+          && key->direction == RIJNDAEL_DIR_ENCRYPT))
     {
       return RIJNDAEL_BAD_CIPHER_STATE;
     }