crypto: user - Fix lookup of algorithms with IV generator
[linux-flexiantxendom0-3.2.10.git] / crypto / ahash.c
index 33a4ff4..33bc9b6 100644 (file)
@@ -21,6 +21,8 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/seq_file.h>
+#include <linux/cryptouser.h>
+#include <net/netlink.h>
 
 #include "internal.h"
 
@@ -44,11 +46,14 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
        unsigned int nbytes = min(walk->entrylen,
                                  ((unsigned int)(PAGE_SIZE)) - offset);
 
-       walk->data = crypto_kmap(walk->pg, 0);
+       walk->data = kmap_atomic(walk->pg);
        walk->data += offset;
 
-       if (offset & alignmask)
-               nbytes = alignmask + 1 - (offset & alignmask);
+       if (offset & alignmask) {
+               unsigned int unaligned = alignmask + 1 - (offset & alignmask);
+               if (nbytes > unaligned)
+                       nbytes = unaligned;
+       }
 
        walk->entrylen -= nbytes;
        return nbytes;
@@ -78,7 +83,6 @@ int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err)
        walk->data -= walk->offset;
 
        if (nbytes && walk->offset & alignmask && !err) {
-               walk->offset += alignmask - 1;
                walk->offset = ALIGN(walk->offset, alignmask + 1);
                walk->data += walk->offset;
 
@@ -89,7 +93,7 @@ int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err)
                return nbytes;
        }
 
-       crypto_kunmap(walk->data, 0);
+       kunmap_atomic(walk->data);
        crypto_yield(walk->flags);
 
        if (err)
@@ -395,6 +399,31 @@ static unsigned int crypto_ahash_extsize(struct crypto_alg *alg)
        return sizeof(struct crypto_shash *);
 }
 
+#ifdef CONFIG_NET
+static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       struct crypto_report_hash rhash;
+
+       snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
+
+       rhash.blocksize = alg->cra_blocksize;
+       rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
+
+       NLA_PUT(skb, CRYPTOCFGA_REPORT_HASH,
+               sizeof(struct crypto_report_hash), &rhash);
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+#else
+static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+       return -ENOSYS;
+}
+#endif
+
 static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
@@ -413,6 +442,7 @@ const struct crypto_type crypto_ahash_type = {
 #ifdef CONFIG_PROC_FS
        .show = crypto_ahash_show,
 #endif
+       .report = crypto_ahash_report,
        .maskclear = ~CRYPTO_ALG_TYPE_MASK,
        .maskset = CRYPTO_ALG_TYPE_AHASH_MASK,
        .type = CRYPTO_ALG_TYPE_AHASH,