KVM: MMU: invalidate and flush on spte small->large page size change
[safe/jmp/linux-2.6] / crypto / cipher.c
index 333aab2..39541e0 100644 (file)
@@ -8,7 +8,7 @@
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option) 
+ * Software Foundation; either version 2 of the License, or (at your option)
  * any later version.
  *
  */
 #include <linux/kernel.h>
 #include <linux/crypto.h>
 #include <linux/errno.h>
-#include <linux/scatterlist.h>
+#include <linux/slab.h>
 #include <linux/string.h>
 #include "internal.h"
 
+static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
+                           unsigned int keylen)
+{
+       struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
+       unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
+       int ret;
+       u8 *buffer, *alignbuffer;
+       unsigned long absize;
+
+       absize = keylen + alignmask;
+       buffer = kmalloc(absize, GFP_ATOMIC);
+       if (!buffer)
+               return -ENOMEM;
+
+       alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
+       memcpy(alignbuffer, key, keylen);
+       ret = cia->cia_setkey(tfm, alignbuffer, keylen);
+       memset(alignbuffer, 0, keylen);
+       kfree(buffer);
+       return ret;
+
+}
+
 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
 {
        struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
-       
+       unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
+
        tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
        if (keylen < cia->cia_min_keysize || keylen > cia->cia_max_keysize) {
                tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
                return -EINVAL;
-       } else
-               return cia->cia_setkey(tfm, key, keylen);
+       }
+
+       if ((unsigned long)key & alignmask)
+               return setkey_unaligned(tfm, key, keylen);
+
+       return cia->cia_setkey(tfm, key, keylen);
 }
 
 static void cipher_crypt_unaligned(void (*fn)(struct crypto_tfm *, u8 *,