[PATCH 3/3] crypto: atmel-sha - add sha information to the log

2013-10-15 Thread Nicolas Ferre
Depending on peripheral capabilities, print SHA information at the end
of the probe function.

Signed-off-by: Nicolas Ferre 
---
 drivers/crypto/atmel-sha.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index ecfdf72..0618be0 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -1469,7 +1469,9 @@ static int atmel_sha_probe(struct platform_device *pdev)
if (err)
goto err_algs;
 
-   dev_info(dev, "Atmel SHA1/SHA256\n");
+   dev_info(dev, "Atmel SHA1/SHA256%s%s\n",
+   sha_dd->caps.has_sha224 ? "/SHA224" : "",
+   sha_dd->caps.has_sha_384_512 ? "/SHA384/SHA512" : "");
 
return 0;
 
-- 
1.8.2.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] crypto: atmel-sha - add support for Device Tree

2013-10-15 Thread Nicolas Ferre
Add support for Device Tree and use of the DMA DT API to
get the channels if needed.
Documentation is added for these DT nodes.

Initial code by: Nicolas Royer and Eukrea.

Signed-off-by: Nicolas Ferre 
---
 .../devicetree/bindings/crypto/atmel-crypto.txt| 22 +
 drivers/crypto/atmel-sha.c | 99 --
 2 files changed, 97 insertions(+), 24 deletions(-)

diff --git a/Documentation/devicetree/bindings/crypto/atmel-crypto.txt 
b/Documentation/devicetree/bindings/crypto/atmel-crypto.txt
index 9a24fd9..f2aab3d 100644
--- a/Documentation/devicetree/bindings/crypto/atmel-crypto.txt
+++ b/Documentation/devicetree/bindings/crypto/atmel-crypto.txt
@@ -44,3 +44,25 @@ tdes@f803c000 {
   <&dma1 2 21>;
dma-names = "tx", "rx";
 };
+
+* Secure Hash Algorithm (SHA)
+
+Required properties:
+- compatible : Should be "atmel,at91sam9g46-sha".
+- reg: Should contain SHA registers location and length.
+- interrupts: Should contain the IRQ line for the SHA.
+
+Optional properties:
+- dmas: One DMA specifiers as described in
+atmel-dma.txt and dma.txt files.
+- dma-names: Contains one identifier string for each DMA specifier
+ in the dmas property. Only one "tx" string needed.
+
+Example:
+sha@f8034000 {
+   compatible = "atmel,at91sam9g46-sha";
+   reg = <0xf8034000 0x100>;
+   interrupts = <42 4 0>;
+   dmas = <&dma1 2 17>;
+   dma-names = "tx";
+};
diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index eaed8bf..ecfdf72 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1263,32 +1264,29 @@ static int atmel_sha_dma_init(struct atmel_sha_dev *dd,
int err = -ENOMEM;
dma_cap_mask_t mask_in;
 
-   if (pdata && pdata->dma_slave->rxdata.dma_dev) {
-   /* Try to grab DMA channel */
-   dma_cap_zero(mask_in);
-   dma_cap_set(DMA_SLAVE, mask_in);
+   /* Try to grab DMA channel */
+   dma_cap_zero(mask_in);
+   dma_cap_set(DMA_SLAVE, mask_in);
 
-   dd->dma_lch_in.chan = dma_request_channel(mask_in,
-   atmel_sha_filter, &pdata->dma_slave->rxdata);
-
-   if (!dd->dma_lch_in.chan)
-   return err;
-
-   dd->dma_lch_in.dma_conf.direction = DMA_MEM_TO_DEV;
-   dd->dma_lch_in.dma_conf.dst_addr = dd->phys_base +
-   SHA_REG_DIN(0);
-   dd->dma_lch_in.dma_conf.src_maxburst = 1;
-   dd->dma_lch_in.dma_conf.src_addr_width =
-   DMA_SLAVE_BUSWIDTH_4_BYTES;
-   dd->dma_lch_in.dma_conf.dst_maxburst = 1;
-   dd->dma_lch_in.dma_conf.dst_addr_width =
-   DMA_SLAVE_BUSWIDTH_4_BYTES;
-   dd->dma_lch_in.dma_conf.device_fc = false;
-
-   return 0;
+   dd->dma_lch_in.chan = dma_request_slave_channel_compat(mask_in,
+   atmel_sha_filter, &pdata->dma_slave->rxdata, dd->dev, 
"tx");
+   if (!dd->dma_lch_in.chan) {
+   dev_warn(dd->dev, "no DMA channel available\n");
+   return err;
}
 
-   return -ENODEV;
+   dd->dma_lch_in.dma_conf.direction = DMA_MEM_TO_DEV;
+   dd->dma_lch_in.dma_conf.dst_addr = dd->phys_base +
+   SHA_REG_DIN(0);
+   dd->dma_lch_in.dma_conf.src_maxburst = 1;
+   dd->dma_lch_in.dma_conf.src_addr_width =
+   DMA_SLAVE_BUSWIDTH_4_BYTES;
+   dd->dma_lch_in.dma_conf.dst_maxburst = 1;
+   dd->dma_lch_in.dma_conf.dst_addr_width =
+   DMA_SLAVE_BUSWIDTH_4_BYTES;
+   dd->dma_lch_in.dma_conf.device_fc = false;
+
+   return 0;
 }
 
 static void atmel_sha_dma_cleanup(struct atmel_sha_dev *dd)
@@ -1326,6 +1324,48 @@ static void atmel_sha_get_cap(struct atmel_sha_dev *dd)
}
 }
 
+#if defined(CONFIG_OF)
+static const struct of_device_id atmel_sha_dt_ids[] = {
+   { .compatible = "atmel,at91sam9g46-sha" },
+   { /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, atmel_sha_dt_ids);
+
+static struct crypto_platform_data *atmel_sha_of_init(struct platform_device 
*pdev)
+{
+   struct device_node *np = pdev->dev.of_node;
+   struct crypto_platform_data *pdata;
+
+   if (!np) {
+   dev_err(&pdev->dev, "device node not found\n");
+   return ERR_PTR(-EINVAL);
+   }
+
+   pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata) {
+   dev_err(&pdev->dev, "could not allocate memory for pdata\n");
+   return ERR_PTR(-ENOMEM);
+   }
+
+   pdata->dma_slave = devm_kzalloc(&pdev->dev,
+   sizeof(*(pdata->dma_slave)),
+   GFP_KERNEL);
+   if (!pdata->dma_slave) {
+   dev_err(&pdev->dev, "could not allocate memor

[PATCH 1/3] crypto: atmel-tdes - add support for Device Tree

2013-10-15 Thread Nicolas Ferre
Add support for Device Tree and use of the DMA DT API to
get the channels if needed.
Documentation is added for these DT nodes.

Initial code by: Nicolas Royer and Eukrea.

Signed-off-by: Nicolas Ferre 
---
 .../devicetree/bindings/crypto/atmel-crypto.txt|  23 
 drivers/crypto/atmel-tdes.c| 143 ++---
 2 files changed, 117 insertions(+), 49 deletions(-)

diff --git a/Documentation/devicetree/bindings/crypto/atmel-crypto.txt 
b/Documentation/devicetree/bindings/crypto/atmel-crypto.txt
index d273f0b..9a24fd9 100644
--- a/Documentation/devicetree/bindings/crypto/atmel-crypto.txt
+++ b/Documentation/devicetree/bindings/crypto/atmel-crypto.txt
@@ -21,3 +21,26 @@ aes@f8038000 {
dmas = <&dma1 2 18>,
   <&dma1 2 19>;
dma-names = "tx", "rx";
+
+* Triple Data Encryption Standard (Triple DES)
+
+Required properties:
+- compatible : Should be "atmel,at91sam9g46-tdes".
+- reg: Should contain TDES registers location and length.
+- interrupts: Should contain the IRQ line for the TDES.
+
+Optional properties:
+- dmas: List of two DMA specifiers as described in
+atmel-dma.txt and dma.txt files.
+- dma-names: Contains one identifier string for each DMA specifier
+ in the dmas property.
+
+Example:
+tdes@f803c000 {
+   compatible = "atmel,at91sam9g46-tdes";
+   reg = <0xf803c000 0x100>;
+   interrupts = <44 4 0>;
+   dmas = <&dma1 2 20>,
+  <&dma1 2 21>;
+   dma-names = "tx", "rx";
+};
diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c
index 4a99564..6cde5b5 100644
--- a/drivers/crypto/atmel-tdes.c
+++ b/drivers/crypto/atmel-tdes.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -716,59 +717,50 @@ static int atmel_tdes_dma_init(struct atmel_tdes_dev *dd,
struct crypto_platform_data *pdata)
 {
int err = -ENOMEM;
-   dma_cap_mask_t mask_in, mask_out;
+   dma_cap_mask_t mask;
+
+   dma_cap_zero(mask);
+   dma_cap_set(DMA_SLAVE, mask);
+
+   /* Try to grab 2 DMA channels */
+   dd->dma_lch_in.chan = dma_request_slave_channel_compat(mask,
+   atmel_tdes_filter, &pdata->dma_slave->rxdata, dd->dev, 
"tx");
+   if (!dd->dma_lch_in.chan)
+   goto err_dma_in;
+
+   dd->dma_lch_in.dma_conf.direction = DMA_MEM_TO_DEV;
+   dd->dma_lch_in.dma_conf.dst_addr = dd->phys_base +
+   TDES_IDATA1R;
+   dd->dma_lch_in.dma_conf.src_maxburst = 1;
+   dd->dma_lch_in.dma_conf.src_addr_width =
+   DMA_SLAVE_BUSWIDTH_4_BYTES;
+   dd->dma_lch_in.dma_conf.dst_maxburst = 1;
+   dd->dma_lch_in.dma_conf.dst_addr_width =
+   DMA_SLAVE_BUSWIDTH_4_BYTES;
+   dd->dma_lch_in.dma_conf.device_fc = false;
+
+   dd->dma_lch_out.chan = dma_request_slave_channel_compat(mask,
+   atmel_tdes_filter, &pdata->dma_slave->txdata, dd->dev, 
"rx");
+   if (!dd->dma_lch_out.chan)
+   goto err_dma_out;
+
+   dd->dma_lch_out.dma_conf.direction = DMA_DEV_TO_MEM;
+   dd->dma_lch_out.dma_conf.src_addr = dd->phys_base +
+   TDES_ODATA1R;
+   dd->dma_lch_out.dma_conf.src_maxburst = 1;
+   dd->dma_lch_out.dma_conf.src_addr_width =
+   DMA_SLAVE_BUSWIDTH_4_BYTES;
+   dd->dma_lch_out.dma_conf.dst_maxburst = 1;
+   dd->dma_lch_out.dma_conf.dst_addr_width =
+   DMA_SLAVE_BUSWIDTH_4_BYTES;
+   dd->dma_lch_out.dma_conf.device_fc = false;
 
-   if (pdata && pdata->dma_slave->txdata.dma_dev &&
-   pdata->dma_slave->rxdata.dma_dev) {
-
-   /* Try to grab 2 DMA channels */
-   dma_cap_zero(mask_in);
-   dma_cap_set(DMA_SLAVE, mask_in);
-
-   dd->dma_lch_in.chan = dma_request_channel(mask_in,
-   atmel_tdes_filter, &pdata->dma_slave->rxdata);
-
-   if (!dd->dma_lch_in.chan)
-   goto err_dma_in;
-
-   dd->dma_lch_in.dma_conf.direction = DMA_MEM_TO_DEV;
-   dd->dma_lch_in.dma_conf.dst_addr = dd->phys_base +
-   TDES_IDATA1R;
-   dd->dma_lch_in.dma_conf.src_maxburst = 1;
-   dd->dma_lch_in.dma_conf.src_addr_width =
-   DMA_SLAVE_BUSWIDTH_4_BYTES;
-   dd->dma_lch_in.dma_conf.dst_maxburst = 1;
-   dd->dma_lch_in.dma_conf.dst_addr_width =
-   DMA_SLAVE_BUSWIDTH_4_BYTES;
-   dd->dma_lch_in.dma_conf.device_fc = false;
-
-   dma_cap_zero(mask_out);
-   dma_cap_set(DMA_SLAVE, mask_out);
-   dd->dma_lch_out.chan = dma_request_channel(mask_out,
-   atmel_tdes_filter, &pdata->dma_slave->txdata);
-
-   if (!dd->dma_lch_out.chan)
-   goto err_dma_out;
-
-   dd->dma_lch_out.dma_conf.direction =

[PATCH 3/5] crypto: ixp4xx - Simplify and harden key parsing

2013-10-15 Thread Mathias Krause
Use the common helper function crypto_authenc_extractkeys() for key
parsing. Also ensure the keys do fit into the corresponding buffers.
Otherwise memory corruption might occur.

Cc: Christian Hohnstaedt 
Cc: Herbert Xu 
Cc: "David S. Miller" 
Signed-off-by: Mathias Krause 
---
Not tested as I've no such hardware, nor the needed cross compiler!

 drivers/crypto/ixp4xx_crypto.c |   26 +-
 1 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 21180d6..153f73c 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -1159,32 +1159,24 @@ static int aead_setkey(struct crypto_aead *tfm, const 
u8 *key,
unsigned int keylen)
 {
struct ixp_ctx *ctx = crypto_aead_ctx(tfm);
-   struct rtattr *rta = (struct rtattr *)key;
-   struct crypto_authenc_key_param *param;
+   struct crypto_authenc_keys keys;
 
-   if (!RTA_OK(rta, keylen))
-   goto badkey;
-   if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM)
-   goto badkey;
-   if (RTA_PAYLOAD(rta) < sizeof(*param))
+   if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
goto badkey;
 
-   param = RTA_DATA(rta);
-   ctx->enckey_len = be32_to_cpu(param->enckeylen);
-
-   key += RTA_ALIGN(rta->rta_len);
-   keylen -= RTA_ALIGN(rta->rta_len);
+   if (keys.authkeylen > sizeof(ctx->authkey))
+   goto badkey;
 
-   if (keylen < ctx->enckey_len)
+   if (keys.enckeylen > sizeof(ctx->enckey))
goto badkey;
 
-   ctx->authkey_len = keylen - ctx->enckey_len;
-   memcpy(ctx->enckey, key + ctx->authkey_len, ctx->enckey_len);
-   memcpy(ctx->authkey, key, ctx->authkey_len);
+   memcpy(ctx->authkey, keys.authkey, keys.authkeylen);
+   memcpy(ctx->enckey, keys.enckey, keys.enckeylen);
+   ctx->authkey_len = keys.authkeylen;
+   ctx->enckey_len = keys.enckeylen;
 
return aead_setup(tfm, crypto_aead_authsize(tfm));
 badkey:
-   ctx->enckey_len = 0;
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
 }
-- 
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/5] crypto: authencesn - Simplify key parsing

2013-10-15 Thread Mathias Krause
Use the common helper function crypto_authenc_extractkeys() for key
parsing.

Cc: Herbert Xu 
Cc: "David S. Miller" 
Signed-off-by: Mathias Krause 
---
 crypto/authencesn.c |   26 --
 1 files changed, 4 insertions(+), 22 deletions(-)

diff --git a/crypto/authencesn.c b/crypto/authencesn.c
index ab53762..8ed5b47 100644
--- a/crypto/authencesn.c
+++ b/crypto/authencesn.c
@@ -59,37 +59,19 @@ static void authenc_esn_request_complete(struct 
aead_request *req, int err)
 static int crypto_authenc_esn_setkey(struct crypto_aead *authenc_esn, const u8 
*key,
 unsigned int keylen)
 {
-   unsigned int authkeylen;
-   unsigned int enckeylen;
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn);
struct crypto_ahash *auth = ctx->auth;
struct crypto_ablkcipher *enc = ctx->enc;
-   struct rtattr *rta = (void *)key;
-   struct crypto_authenc_key_param *param;
+   struct crypto_authenc_keys keys;
int err = -EINVAL;
 
-   if (!RTA_OK(rta, keylen))
+   if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
goto badkey;
-   if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM)
-   goto badkey;
-   if (RTA_PAYLOAD(rta) < sizeof(*param))
-   goto badkey;
-
-   param = RTA_DATA(rta);
-   enckeylen = be32_to_cpu(param->enckeylen);
-
-   key += RTA_ALIGN(rta->rta_len);
-   keylen -= RTA_ALIGN(rta->rta_len);
-
-   if (keylen < enckeylen)
-   goto badkey;
-
-   authkeylen = keylen - enckeylen;
 
crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK);
crypto_ahash_set_flags(auth, crypto_aead_get_flags(authenc_esn) &
 CRYPTO_TFM_REQ_MASK);
-   err = crypto_ahash_setkey(auth, key, authkeylen);
+   err = crypto_ahash_setkey(auth, keys.authkey, keys.authkeylen);
crypto_aead_set_flags(authenc_esn, crypto_ahash_get_flags(auth) &
   CRYPTO_TFM_RES_MASK);
 
@@ -99,7 +81,7 @@ static int crypto_authenc_esn_setkey(struct crypto_aead 
*authenc_esn, const u8 *
crypto_ablkcipher_clear_flags(enc, CRYPTO_TFM_REQ_MASK);
crypto_ablkcipher_set_flags(enc, crypto_aead_get_flags(authenc_esn) &
 CRYPTO_TFM_REQ_MASK);
-   err = crypto_ablkcipher_setkey(enc, key + authkeylen, enckeylen);
+   err = crypto_ablkcipher_setkey(enc, keys.enckey, keys.enckeylen);
crypto_aead_set_flags(authenc_esn, crypto_ablkcipher_get_flags(enc) &
   CRYPTO_TFM_RES_MASK);
 
-- 
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/5] Authenc key parsing consolidation

2013-10-15 Thread Mathias Krause
This series removes the code duplication of authenc key parsing by
introducing a common helper function crypto_authenc_extractkeys() in
patch 1. Patches 2 to 5 change all remaining places to use the new
helper. Patches 3 and 4 also fix potential memory corruptions by
ensuring the supplied keys won't overflow there respective buffers.

I was unable to test patches 3 to 5 as I don't have the needed hardware
for these devices -- not even a cross compiler for those architectures.

In case patches 3 and 4 are enqueued for stable, patch 1 needs to be as
well, as it's a prerequisite for those.

Please apply!

Mathias Krause (5):
  crypto: authenc - Export key parsing helper function
  crypto: authencesn - Simplify key parsing
  crypto: ixp4xx - Simplify and harden key parsing
  crypto: picoxcell - Simplify and harden key parsing
  crypto: talitos - Simplify key parsing

 crypto/authenc.c  |   48 +++--
 crypto/authencesn.c   |   26 +++-
 drivers/crypto/ixp4xx_crypto.c|   26 +++-
 drivers/crypto/picoxcell_crypto.c |   32 ++--
 drivers/crypto/talitos.c  |   35 ++
 include/crypto/authenc.h  |   12 -
 6 files changed, 70 insertions(+), 109 deletions(-)

-- 
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/5] crypto: talitos - Simplify key parsing

2013-10-15 Thread Mathias Krause
Use the common helper function crypto_authenc_extractkeys() for key
parsing.

Cc: Kim Phillips 
Cc: Herbert Xu 
Cc: "David S. Miller" 
Signed-off-by: Mathias Krause 
---
Not tested as I've no such hardware, nor the needed cross compiler!

 drivers/crypto/talitos.c |   35 ---
 1 files changed, 8 insertions(+), 27 deletions(-)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 661dc3e..f6f7c68 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -671,39 +671,20 @@ static int aead_setkey(struct crypto_aead *authenc,
   const u8 *key, unsigned int keylen)
 {
struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
-   struct rtattr *rta = (void *)key;
-   struct crypto_authenc_key_param *param;
-   unsigned int authkeylen;
-   unsigned int enckeylen;
-
-   if (!RTA_OK(rta, keylen))
-   goto badkey;
+   struct crypto_authenc_keys keys;
 
-   if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM)
+   if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
goto badkey;
 
-   if (RTA_PAYLOAD(rta) < sizeof(*param))
+   if (keys.authkeylen + keys.enckeylen > TALITOS_MAX_KEY_SIZE)
goto badkey;
 
-   param = RTA_DATA(rta);
-   enckeylen = be32_to_cpu(param->enckeylen);
-
-   key += RTA_ALIGN(rta->rta_len);
-   keylen -= RTA_ALIGN(rta->rta_len);
-
-   if (keylen < enckeylen)
-   goto badkey;
+   memcpy(ctx->key, keys.authkey, keys.authkeylen);
+   memcpy(&ctx->key[keys.authkeylen], keys.enckey, keys.enckeylen);
 
-   authkeylen = keylen - enckeylen;
-
-   if (keylen > TALITOS_MAX_KEY_SIZE)
-   goto badkey;
-
-   memcpy(&ctx->key, key, keylen);
-
-   ctx->keylen = keylen;
-   ctx->enckeylen = enckeylen;
-   ctx->authkeylen = authkeylen;
+   ctx->keylen = keys.authkeylen + keys.enckeylen;
+   ctx->enckeylen = keys.enckeylen;
+   ctx->authkeylen = keys.authkeylen;
 
return 0;
 
-- 
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/5] crypto: authenc - Export key parsing helper function

2013-10-15 Thread Mathias Krause
AEAD key parsing is duplicated to multiple places in the kernel. Add a
common helper function to consolidate that functionality.

Cc: Herbert Xu 
Cc: "David S. Miller" 
Signed-off-by: Mathias Krause 
---
 crypto/authenc.c |   48 -
 include/crypto/authenc.h |   12 ++-
 2 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/crypto/authenc.c b/crypto/authenc.c
index ffce19d..0fda5ba 100644
--- a/crypto/authenc.c
+++ b/crypto/authenc.c
@@ -52,40 +52,52 @@ static void authenc_request_complete(struct aead_request 
*req, int err)
aead_request_complete(req, err);
 }
 
-static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
-unsigned int keylen)
+int crypto_authenc_extractkeys(struct crypto_authenc_keys *keys, const u8 *key,
+  unsigned int keylen)
 {
-   unsigned int authkeylen;
-   unsigned int enckeylen;
-   struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
-   struct crypto_ahash *auth = ctx->auth;
-   struct crypto_ablkcipher *enc = ctx->enc;
-   struct rtattr *rta = (void *)key;
+   struct rtattr *rta = (struct rtattr *)key;
struct crypto_authenc_key_param *param;
-   int err = -EINVAL;
 
if (!RTA_OK(rta, keylen))
-   goto badkey;
+   return -EINVAL;
if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM)
-   goto badkey;
+   return -EINVAL;
if (RTA_PAYLOAD(rta) < sizeof(*param))
-   goto badkey;
+   return -EINVAL;
 
param = RTA_DATA(rta);
-   enckeylen = be32_to_cpu(param->enckeylen);
+   keys->enckeylen = be32_to_cpu(param->enckeylen);
 
key += RTA_ALIGN(rta->rta_len);
keylen -= RTA_ALIGN(rta->rta_len);
 
-   if (keylen < enckeylen)
-   goto badkey;
+   if (keylen < keys->enckeylen)
+   return -EINVAL;
 
-   authkeylen = keylen - enckeylen;
+   keys->authkeylen = keylen - keys->enckeylen;
+   keys->authkey = key;
+   keys->enckey = key + keys->authkeylen;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(crypto_authenc_extractkeys);
+
+static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
+unsigned int keylen)
+{
+   struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
+   struct crypto_ahash *auth = ctx->auth;
+   struct crypto_ablkcipher *enc = ctx->enc;
+   struct crypto_authenc_keys keys;
+   int err = -EINVAL;
+
+   if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
+   goto badkey;
 
crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK);
crypto_ahash_set_flags(auth, crypto_aead_get_flags(authenc) &
CRYPTO_TFM_REQ_MASK);
-   err = crypto_ahash_setkey(auth, key, authkeylen);
+   err = crypto_ahash_setkey(auth, keys.authkey, keys.authkeylen);
crypto_aead_set_flags(authenc, crypto_ahash_get_flags(auth) &
   CRYPTO_TFM_RES_MASK);
 
@@ -95,7 +107,7 @@ static int crypto_authenc_setkey(struct crypto_aead 
*authenc, const u8 *key,
crypto_ablkcipher_clear_flags(enc, CRYPTO_TFM_REQ_MASK);
crypto_ablkcipher_set_flags(enc, crypto_aead_get_flags(authenc) &
 CRYPTO_TFM_REQ_MASK);
-   err = crypto_ablkcipher_setkey(enc, key + authkeylen, enckeylen);
+   err = crypto_ablkcipher_setkey(enc, keys.enckey, keys.enckeylen);
crypto_aead_set_flags(authenc, crypto_ablkcipher_get_flags(enc) &
   CRYPTO_TFM_RES_MASK);
 
diff --git a/include/crypto/authenc.h b/include/crypto/authenc.h
index e47b044..6775059 100644
--- a/include/crypto/authenc.h
+++ b/include/crypto/authenc.h
@@ -23,5 +23,15 @@ struct crypto_authenc_key_param {
__be32 enckeylen;
 };
 
-#endif /* _CRYPTO_AUTHENC_H */
+struct crypto_authenc_keys {
+   const u8 *authkey;
+   const u8 *enckey;
+
+   unsigned int authkeylen;
+   unsigned int enckeylen;
+};
 
+int crypto_authenc_extractkeys(struct crypto_authenc_keys *keys, const u8 *key,
+  unsigned int keylen);
+
+#endif /* _CRYPTO_AUTHENC_H */
-- 
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/5] crypto: picoxcell - Simplify and harden key parsing

2013-10-15 Thread Mathias Krause
Use the common helper function crypto_authenc_extractkeys() for key
parsing. Also ensure the auth key won't overflow the hash_ctx buffer.

Cc: Jamie Iles 
Cc: Herbert Xu 
Cc: "David S. Miller" 
Signed-off-by: Mathias Krause 
---
Not tested as I've no such hardware, nor the needed cross compiler!

 drivers/crypto/picoxcell_crypto.c |   32 
 1 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/drivers/crypto/picoxcell_crypto.c 
b/drivers/crypto/picoxcell_crypto.c
index 888f7f4..a6175ba 100644
--- a/drivers/crypto/picoxcell_crypto.c
+++ b/drivers/crypto/picoxcell_crypto.c
@@ -495,45 +495,29 @@ static int spacc_aead_setkey(struct crypto_aead *tfm, 
const u8 *key,
 {
struct spacc_aead_ctx *ctx = crypto_aead_ctx(tfm);
struct spacc_alg *alg = to_spacc_alg(tfm->base.__crt_alg);
-   struct rtattr *rta = (void *)key;
-   struct crypto_authenc_key_param *param;
-   unsigned int authkeylen, enckeylen;
+   struct crypto_authenc_keys keys;
int err = -EINVAL;
 
-   if (!RTA_OK(rta, keylen))
+   if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
goto badkey;
 
-   if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM)
+   if (keys.enckeylen > AES_MAX_KEY_SIZE)
goto badkey;
 
-   if (RTA_PAYLOAD(rta) < sizeof(*param))
-   goto badkey;
-
-   param = RTA_DATA(rta);
-   enckeylen = be32_to_cpu(param->enckeylen);
-
-   key += RTA_ALIGN(rta->rta_len);
-   keylen -= RTA_ALIGN(rta->rta_len);
-
-   if (keylen < enckeylen)
-   goto badkey;
-
-   authkeylen = keylen - enckeylen;
-
-   if (enckeylen > AES_MAX_KEY_SIZE)
+   if (keys.authkeylen > sizeof(ctx->hash_ctx))
goto badkey;
 
if ((alg->ctrl_default & SPACC_CRYPTO_ALG_MASK) ==
SPA_CTRL_CIPH_ALG_AES)
-   err = spacc_aead_aes_setkey(tfm, key + authkeylen, enckeylen);
+   err = spacc_aead_aes_setkey(tfm, keys.enckey, keys.enckeylen);
else
-   err = spacc_aead_des_setkey(tfm, key + authkeylen, enckeylen);
+   err = spacc_aead_des_setkey(tfm, keys.enckey, keys.enckeylen);
 
if (err)
goto badkey;
 
-   memcpy(ctx->hash_ctx, key, authkeylen);
-   ctx->hash_key_len = authkeylen;
+   memcpy(ctx->hash_ctx, keys.authkey, keys.authkeylen);
+   ctx->hash_key_len = keys.authkeylen;
 
return 0;
 
-- 
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] ARM: at91/dt/trivial: before sama5d3, Atmel MPU were using at91 prefix

2013-10-15 Thread Nicolas Ferre

On 14/10/2013 19:09, Jean-Christophe PLAGNIOL-VILLARD :

On 18:46 Mon 14 Oct , Nicolas Ferre wrote:

Change the sha/aes/tdes compatibility string to match common
case for the at91sam9g45 family which is to keep the at91 prefix.

Signed-off-by: Nicolas Ferre 
---
  arch/arm/boot/dts/sama5d3.dtsi | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/dts/sama5d3.dtsi b/arch/arm/boot/dts/sama5d3.dtsi
index b2aabff..99bd4a6 100644
--- a/arch/arm/boot/dts/sama5d3.dtsi
+++ b/arch/arm/boot/dts/sama5d3.dtsi
@@ -342,19 +342,19 @@
};

sha@f8034000 {
-   compatible = "atmel,sam9g46-sha";
+   compatible = "atmel,at91sam9g46-sha";
reg = <0xf8034000 0x100>;
interrupts = <42 IRQ_TYPE_LEVEL_HIGH 0>;
};

aes@f8038000 {
-   compatible = "atmel,sam9g46-aes";
+   compatible = "atmel,at91sam9g46-aes";
reg = <0xf8038000 0x100>;
interrupts = <43 IRQ_TYPE_LEVEL_HIGH 0>;
};

tdes@f803c000 {
-   compatible = "atmel,sam9g46-tdes";
+   compatible = "atmel,at91sam9g46-tdes";
reg = <0xf803c000 0x100>;
interrupts = <44 IRQ_TYPE_LEVEL_HIGH 0>;

you keep the previous compatible in the driver too for backword compatiblity


No, as the consumer of the old compatibility string has never been sent 
to mainline (or even mailing-list) and as the "dma" property is not 
compatible with the one existing on our 3.6.9-based kernel.


So, anyway the DT has to be changed for a move from 3.6.9 => 3.10. As I 
do not want to bloat the DT forever, let's stick with this new 
compatibility string.


Bye,



};
--
1.8.2.2


___
linux-arm-kernel mailing list
linux-arm-ker...@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel





--
Nicolas Ferre
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html