crypto: caam - add IPsec ESN support
authorHoria Geanta <horia.geanta@freescale.com>
Tue, 4 Sep 2012 16:18:00 +0000 (19:18 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 6 Sep 2012 20:17:07 +0000 (04:17 +0800)
Support for ESNs (extended sequence numbers).
Tested with strongswan by connecting back-to-back P1010RDB with P2020RDB.

Signed-off-by: Horia Geanta <horia.geanta@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/caam/caamalg.c
drivers/crypto/caam/compat.h

index cf268b14ae9a393890ac37597f29008ee2c93126..b2a0a0726a5405caf7c0f7d252745d9554e34643 100644 (file)
@@ -1650,7 +1650,11 @@ struct caam_alg_template {
 };
 
 static struct caam_alg_template driver_algs[] = {
-       /* single-pass ipsec_esp descriptor */
+       /*
+        * single-pass ipsec_esp descriptor
+        * authencesn(*,*) is also registered, although not present
+        * explicitly here.
+        */
        {
                .name = "authenc(hmac(md5),cbc(aes))",
                .driver_name = "authenc-hmac-md5-cbc-aes-caam",
@@ -2213,7 +2217,9 @@ static int __init caam_algapi_init(void)
        for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
                /* TODO: check if h/w supports alg */
                struct caam_crypto_alg *t_alg;
+               bool done = false;
 
+authencesn:
                t_alg = caam_alg_alloc(ctrldev, &driver_algs[i]);
                if (IS_ERR(t_alg)) {
                        err = PTR_ERR(t_alg);
@@ -2227,8 +2233,25 @@ static int __init caam_algapi_init(void)
                        dev_warn(ctrldev, "%s alg registration failed\n",
                                t_alg->crypto_alg.cra_driver_name);
                        kfree(t_alg);
-               } else
+               } else {
                        list_add_tail(&t_alg->entry, &priv->alg_list);
+                       if (driver_algs[i].type == CRYPTO_ALG_TYPE_AEAD &&
+                           !memcmp(driver_algs[i].name, "authenc", 7) &&
+                           !done) {
+                               char *name;
+
+                               name = driver_algs[i].name;
+                               memmove(name + 10, name + 7, strlen(name) - 7);
+                               memcpy(name + 7, "esn", 3);
+
+                               name = driver_algs[i].driver_name;
+                               memmove(name + 10, name + 7, strlen(name) - 7);
+                               memcpy(name + 7, "esn", 3);
+
+                               done = true;
+                               goto authencesn;
+                       }
+               }
        }
        if (!list_empty(&priv->alg_list))
                dev_info(ctrldev, "%s algorithms registered in /proc/crypto\n",
index 762aeff626ac6f7a980c8fe3019fcd72252ecd7c..cf15e7813801a6cb8e1d631663a2fb4421cb5a7a 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/types.h>
 #include <linux/debugfs.h>
 #include <linux/circ_buf.h>
+#include <linux/string.h>
 #include <net/xfrm.h>
 
 #include <crypto/algapi.h>