]> git.neil.brown.name Git - history.git/commitdiff
[CRYPTO]: Fix digest.c kmapping sg entries > page in length.
authorClay Haapala <chaapala@cisco.com>
Thu, 10 Jun 2004 14:58:26 +0000 (07:58 -0700)
committerDavid S. Miller <davem@nuts.davemloft.net>
Thu, 10 Jun 2004 14:58:26 +0000 (07:58 -0700)
Below is the patch, against 2.6.7-rc2, to fix crypto/digest.c to do
multiple kmap()/kunmap() for scatterlist entries which have a size
greater than a single page, originally found and fixed by
N.C.Krishna Murthy <krmurthy@cisco.com>.

Signed-off-by: Clay Haapala <chaapala@cisco.com>
Signed-off-by: David S. Miller <davem@redhat.com>
crypto/digest.c

index 30dabe203d30e7c2c938b279b8866d5aea4822bc..d9b6ac9dbf8d08e8ae88572c71f93d132a10df25 100644 (file)
@@ -27,13 +27,28 @@ static void update(struct crypto_tfm *tfm,
                    struct scatterlist *sg, unsigned int nsg)
 {
        unsigned int i;
-       
+
        for (i = 0; i < nsg; i++) {
-               char *p = crypto_kmap(sg[i].page, 0) + sg[i].offset;
-               tfm->__crt_alg->cra_digest.dia_update(crypto_tfm_ctx(tfm),
-                                                     p, sg[i].length);
-               crypto_kunmap(p, 0);
-               crypto_yield(tfm);
+
+               struct page *pg = sg[i].page;
+               unsigned int offset = sg[i].offset;
+               unsigned int l = sg[i].length;
+
+               do {
+                       unsigned int bytes_from_page = min(l, ((unsigned int)
+                                                          (PAGE_SIZE)) - 
+                                                          offset);
+                       char *p = crypto_kmap(pg, 0) + offset;
+
+                       tfm->__crt_alg->cra_digest.dia_update
+                                       (crypto_tfm_ctx(tfm), p,
+                                        bytes_from_page);
+                       crypto_kunmap(p, 0);
+                       crypto_yield(tfm);
+                       offset = 0;
+                       pg++;
+                       l -= bytes_from_page;
+               } while (l > 0);
        }
 }