Commit d5e6b48f authored by Herbert Xu's avatar Herbert Xu

crypto: stm32 - Use new crypto_engine_op interface

Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 982213e4
...@@ -5,22 +5,24 @@ ...@@ -5,22 +5,24 @@
* Ux500 support taken from snippets in the old Ux500 cryp driver * Ux500 support taken from snippets in the old Ux500 cryp driver
*/ */
#include <crypto/aes.h>
#include <crypto/engine.h>
#include <crypto/internal/aead.h>
#include <crypto/internal/des.h>
#include <crypto/internal/skcipher.h>
#include <crypto/scatterwalk.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/interrupt.h> #include <linux/err.h>
#include <linux/iopoll.h> #include <linux/iopoll.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/reset.h> #include <linux/reset.h>
#include <linux/string.h>
#include <crypto/aes.h>
#include <crypto/internal/des.h>
#include <crypto/engine.h>
#include <crypto/scatterwalk.h>
#include <crypto/internal/aead.h>
#include <crypto/internal/skcipher.h>
#define DRIVER_NAME "stm32-cryp" #define DRIVER_NAME "stm32-cryp"
...@@ -156,7 +158,6 @@ struct stm32_cryp_caps { ...@@ -156,7 +158,6 @@ struct stm32_cryp_caps {
}; };
struct stm32_cryp_ctx { struct stm32_cryp_ctx {
struct crypto_engine_ctx enginectx;
struct stm32_cryp *cryp; struct stm32_cryp *cryp;
int keylen; int keylen;
__be32 key[AES_KEYSIZE_256 / sizeof(u32)]; __be32 key[AES_KEYSIZE_256 / sizeof(u32)];
...@@ -828,11 +829,8 @@ static int stm32_cryp_cipher_one_req(struct crypto_engine *engine, void *areq); ...@@ -828,11 +829,8 @@ static int stm32_cryp_cipher_one_req(struct crypto_engine *engine, void *areq);
static int stm32_cryp_init_tfm(struct crypto_skcipher *tfm) static int stm32_cryp_init_tfm(struct crypto_skcipher *tfm)
{ {
struct stm32_cryp_ctx *ctx = crypto_skcipher_ctx(tfm);
crypto_skcipher_set_reqsize(tfm, sizeof(struct stm32_cryp_reqctx)); crypto_skcipher_set_reqsize(tfm, sizeof(struct stm32_cryp_reqctx));
ctx->enginectx.op.do_one_request = stm32_cryp_cipher_one_req;
return 0; return 0;
} }
...@@ -840,12 +838,8 @@ static int stm32_cryp_aead_one_req(struct crypto_engine *engine, void *areq); ...@@ -840,12 +838,8 @@ static int stm32_cryp_aead_one_req(struct crypto_engine *engine, void *areq);
static int stm32_cryp_aes_aead_init(struct crypto_aead *tfm) static int stm32_cryp_aes_aead_init(struct crypto_aead *tfm)
{ {
struct stm32_cryp_ctx *ctx = crypto_aead_ctx(tfm);
tfm->reqsize = sizeof(struct stm32_cryp_reqctx); tfm->reqsize = sizeof(struct stm32_cryp_reqctx);
ctx->enginectx.op.do_one_request = stm32_cryp_aead_one_req;
return 0; return 0;
} }
...@@ -1686,8 +1680,9 @@ static irqreturn_t stm32_cryp_irq(int irq, void *arg) ...@@ -1686,8 +1680,9 @@ static irqreturn_t stm32_cryp_irq(int irq, void *arg)
return IRQ_WAKE_THREAD; return IRQ_WAKE_THREAD;
} }
static struct skcipher_alg crypto_algs[] = { static struct skcipher_engine_alg crypto_algs[] = {
{ {
.base = {
.base.cra_name = "ecb(aes)", .base.cra_name = "ecb(aes)",
.base.cra_driver_name = "stm32-ecb-aes", .base.cra_driver_name = "stm32-ecb-aes",
.base.cra_priority = 200, .base.cra_priority = 200,
...@@ -1703,8 +1698,13 @@ static struct skcipher_alg crypto_algs[] = { ...@@ -1703,8 +1698,13 @@ static struct skcipher_alg crypto_algs[] = {
.setkey = stm32_cryp_aes_setkey, .setkey = stm32_cryp_aes_setkey,
.encrypt = stm32_cryp_aes_ecb_encrypt, .encrypt = stm32_cryp_aes_ecb_encrypt,
.decrypt = stm32_cryp_aes_ecb_decrypt, .decrypt = stm32_cryp_aes_ecb_decrypt,
},
.op = {
.do_one_request = stm32_cryp_cipher_one_req,
},
}, },
{ {
.base = {
.base.cra_name = "cbc(aes)", .base.cra_name = "cbc(aes)",
.base.cra_driver_name = "stm32-cbc-aes", .base.cra_driver_name = "stm32-cbc-aes",
.base.cra_priority = 200, .base.cra_priority = 200,
...@@ -1721,8 +1721,13 @@ static struct skcipher_alg crypto_algs[] = { ...@@ -1721,8 +1721,13 @@ static struct skcipher_alg crypto_algs[] = {
.setkey = stm32_cryp_aes_setkey, .setkey = stm32_cryp_aes_setkey,
.encrypt = stm32_cryp_aes_cbc_encrypt, .encrypt = stm32_cryp_aes_cbc_encrypt,
.decrypt = stm32_cryp_aes_cbc_decrypt, .decrypt = stm32_cryp_aes_cbc_decrypt,
},
.op = {
.do_one_request = stm32_cryp_cipher_one_req,
},
}, },
{ {
.base = {
.base.cra_name = "ctr(aes)", .base.cra_name = "ctr(aes)",
.base.cra_driver_name = "stm32-ctr-aes", .base.cra_driver_name = "stm32-ctr-aes",
.base.cra_priority = 200, .base.cra_priority = 200,
...@@ -1739,8 +1744,13 @@ static struct skcipher_alg crypto_algs[] = { ...@@ -1739,8 +1744,13 @@ static struct skcipher_alg crypto_algs[] = {
.setkey = stm32_cryp_aes_setkey, .setkey = stm32_cryp_aes_setkey,
.encrypt = stm32_cryp_aes_ctr_encrypt, .encrypt = stm32_cryp_aes_ctr_encrypt,
.decrypt = stm32_cryp_aes_ctr_decrypt, .decrypt = stm32_cryp_aes_ctr_decrypt,
},
.op = {
.do_one_request = stm32_cryp_cipher_one_req,
},
}, },
{ {
.base = {
.base.cra_name = "ecb(des)", .base.cra_name = "ecb(des)",
.base.cra_driver_name = "stm32-ecb-des", .base.cra_driver_name = "stm32-ecb-des",
.base.cra_priority = 200, .base.cra_priority = 200,
...@@ -1756,8 +1766,13 @@ static struct skcipher_alg crypto_algs[] = { ...@@ -1756,8 +1766,13 @@ static struct skcipher_alg crypto_algs[] = {
.setkey = stm32_cryp_des_setkey, .setkey = stm32_cryp_des_setkey,
.encrypt = stm32_cryp_des_ecb_encrypt, .encrypt = stm32_cryp_des_ecb_encrypt,
.decrypt = stm32_cryp_des_ecb_decrypt, .decrypt = stm32_cryp_des_ecb_decrypt,
},
.op = {
.do_one_request = stm32_cryp_cipher_one_req,
},
}, },
{ {
.base = {
.base.cra_name = "cbc(des)", .base.cra_name = "cbc(des)",
.base.cra_driver_name = "stm32-cbc-des", .base.cra_driver_name = "stm32-cbc-des",
.base.cra_priority = 200, .base.cra_priority = 200,
...@@ -1774,8 +1789,13 @@ static struct skcipher_alg crypto_algs[] = { ...@@ -1774,8 +1789,13 @@ static struct skcipher_alg crypto_algs[] = {
.setkey = stm32_cryp_des_setkey, .setkey = stm32_cryp_des_setkey,
.encrypt = stm32_cryp_des_cbc_encrypt, .encrypt = stm32_cryp_des_cbc_encrypt,
.decrypt = stm32_cryp_des_cbc_decrypt, .decrypt = stm32_cryp_des_cbc_decrypt,
},
.op = {
.do_one_request = stm32_cryp_cipher_one_req,
},
}, },
{ {
.base = {
.base.cra_name = "ecb(des3_ede)", .base.cra_name = "ecb(des3_ede)",
.base.cra_driver_name = "stm32-ecb-des3", .base.cra_driver_name = "stm32-ecb-des3",
.base.cra_priority = 200, .base.cra_priority = 200,
...@@ -1791,8 +1811,13 @@ static struct skcipher_alg crypto_algs[] = { ...@@ -1791,8 +1811,13 @@ static struct skcipher_alg crypto_algs[] = {
.setkey = stm32_cryp_tdes_setkey, .setkey = stm32_cryp_tdes_setkey,
.encrypt = stm32_cryp_tdes_ecb_encrypt, .encrypt = stm32_cryp_tdes_ecb_encrypt,
.decrypt = stm32_cryp_tdes_ecb_decrypt, .decrypt = stm32_cryp_tdes_ecb_decrypt,
},
.op = {
.do_one_request = stm32_cryp_cipher_one_req,
},
}, },
{ {
.base = {
.base.cra_name = "cbc(des3_ede)", .base.cra_name = "cbc(des3_ede)",
.base.cra_driver_name = "stm32-cbc-des3", .base.cra_driver_name = "stm32-cbc-des3",
.base.cra_priority = 200, .base.cra_priority = 200,
...@@ -1809,20 +1834,24 @@ static struct skcipher_alg crypto_algs[] = { ...@@ -1809,20 +1834,24 @@ static struct skcipher_alg crypto_algs[] = {
.setkey = stm32_cryp_tdes_setkey, .setkey = stm32_cryp_tdes_setkey,
.encrypt = stm32_cryp_tdes_cbc_encrypt, .encrypt = stm32_cryp_tdes_cbc_encrypt,
.decrypt = stm32_cryp_tdes_cbc_decrypt, .decrypt = stm32_cryp_tdes_cbc_decrypt,
},
.op = {
.do_one_request = stm32_cryp_cipher_one_req,
},
}, },
}; };
static struct aead_alg aead_algs[] = { static struct aead_engine_alg aead_algs[] = {
{ {
.setkey = stm32_cryp_aes_aead_setkey, .base.setkey = stm32_cryp_aes_aead_setkey,
.setauthsize = stm32_cryp_aes_gcm_setauthsize, .base.setauthsize = stm32_cryp_aes_gcm_setauthsize,
.encrypt = stm32_cryp_aes_gcm_encrypt, .base.encrypt = stm32_cryp_aes_gcm_encrypt,
.decrypt = stm32_cryp_aes_gcm_decrypt, .base.decrypt = stm32_cryp_aes_gcm_decrypt,
.init = stm32_cryp_aes_aead_init, .base.init = stm32_cryp_aes_aead_init,
.ivsize = 12, .base.ivsize = 12,
.maxauthsize = AES_BLOCK_SIZE, .base.maxauthsize = AES_BLOCK_SIZE,
.base = { .base.base = {
.cra_name = "gcm(aes)", .cra_name = "gcm(aes)",
.cra_driver_name = "stm32-gcm-aes", .cra_driver_name = "stm32-gcm-aes",
.cra_priority = 200, .cra_priority = 200,
...@@ -1832,17 +1861,20 @@ static struct aead_alg aead_algs[] = { ...@@ -1832,17 +1861,20 @@ static struct aead_alg aead_algs[] = {
.cra_alignmask = 0, .cra_alignmask = 0,
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
}, },
.op = {
.do_one_request = stm32_cryp_aead_one_req,
},
}, },
{ {
.setkey = stm32_cryp_aes_aead_setkey, .base.setkey = stm32_cryp_aes_aead_setkey,
.setauthsize = stm32_cryp_aes_ccm_setauthsize, .base.setauthsize = stm32_cryp_aes_ccm_setauthsize,
.encrypt = stm32_cryp_aes_ccm_encrypt, .base.encrypt = stm32_cryp_aes_ccm_encrypt,
.decrypt = stm32_cryp_aes_ccm_decrypt, .base.decrypt = stm32_cryp_aes_ccm_decrypt,
.init = stm32_cryp_aes_aead_init, .base.init = stm32_cryp_aes_aead_init,
.ivsize = AES_BLOCK_SIZE, .base.ivsize = AES_BLOCK_SIZE,
.maxauthsize = AES_BLOCK_SIZE, .base.maxauthsize = AES_BLOCK_SIZE,
.base = { .base.base = {
.cra_name = "ccm(aes)", .cra_name = "ccm(aes)",
.cra_driver_name = "stm32-ccm-aes", .cra_driver_name = "stm32-ccm-aes",
.cra_priority = 200, .cra_priority = 200,
...@@ -1852,6 +1884,9 @@ static struct aead_alg aead_algs[] = { ...@@ -1852,6 +1884,9 @@ static struct aead_alg aead_algs[] = {
.cra_alignmask = 0, .cra_alignmask = 0,
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
}, },
.op = {
.do_one_request = stm32_cryp_aead_one_req,
},
}, },
}; };
...@@ -2013,14 +2048,14 @@ static int stm32_cryp_probe(struct platform_device *pdev) ...@@ -2013,14 +2048,14 @@ static int stm32_cryp_probe(struct platform_device *pdev)
goto err_engine2; goto err_engine2;
} }
ret = crypto_register_skciphers(crypto_algs, ARRAY_SIZE(crypto_algs)); ret = crypto_engine_register_skciphers(crypto_algs, ARRAY_SIZE(crypto_algs));
if (ret) { if (ret) {
dev_err(dev, "Could not register algs\n"); dev_err(dev, "Could not register algs\n");
goto err_algs; goto err_algs;
} }
if (cryp->caps->aeads_support) { if (cryp->caps->aeads_support) {
ret = crypto_register_aeads(aead_algs, ARRAY_SIZE(aead_algs)); ret = crypto_engine_register_aeads(aead_algs, ARRAY_SIZE(aead_algs));
if (ret) if (ret)
goto err_aead_algs; goto err_aead_algs;
} }
...@@ -2032,7 +2067,7 @@ static int stm32_cryp_probe(struct platform_device *pdev) ...@@ -2032,7 +2067,7 @@ static int stm32_cryp_probe(struct platform_device *pdev)
return 0; return 0;
err_aead_algs: err_aead_algs:
crypto_unregister_skciphers(crypto_algs, ARRAY_SIZE(crypto_algs)); crypto_engine_unregister_skciphers(crypto_algs, ARRAY_SIZE(crypto_algs));
err_algs: err_algs:
err_engine2: err_engine2:
crypto_engine_exit(cryp->engine); crypto_engine_exit(cryp->engine);
...@@ -2062,8 +2097,8 @@ static int stm32_cryp_remove(struct platform_device *pdev) ...@@ -2062,8 +2097,8 @@ static int stm32_cryp_remove(struct platform_device *pdev)
return ret; return ret;
if (cryp->caps->aeads_support) if (cryp->caps->aeads_support)
crypto_unregister_aeads(aead_algs, ARRAY_SIZE(aead_algs)); crypto_engine_unregister_aeads(aead_algs, ARRAY_SIZE(aead_algs));
crypto_unregister_skciphers(crypto_algs, ARRAY_SIZE(crypto_algs)); crypto_engine_unregister_skciphers(crypto_algs, ARRAY_SIZE(crypto_algs));
crypto_engine_exit(cryp->engine); crypto_engine_exit(cryp->engine);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment