Commit 530d7b00 authored by Herbert Xu's avatar Herbert Xu

crypto: keembay - 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 67b7702c
...@@ -7,30 +7,27 @@ ...@@ -7,30 +7,27 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <crypto/ecc_curve.h>
#include <crypto/ecdh.h>
#include <crypto/engine.h>
#include <crypto/internal/ecc.h>
#include <crypto/internal/kpp.h>
#include <crypto/kpp.h>
#include <crypto/rng.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/crypto.h> #include <linux/err.h>
#include <linux/delay.h>
#include <linux/fips.h> #include <linux/fips.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/iopoll.h> #include <linux/iopoll.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/slab.h> #include <linux/string.h>
#include <linux/types.h>
#include <crypto/ecc_curve.h>
#include <crypto/ecdh.h>
#include <crypto/engine.h>
#include <crypto/kpp.h>
#include <crypto/rng.h>
#include <crypto/internal/ecc.h>
#include <crypto/internal/kpp.h>
#define DRV_NAME "keembay-ocs-ecc" #define DRV_NAME "keembay-ocs-ecc"
...@@ -95,13 +92,11 @@ struct ocs_ecc_dev { ...@@ -95,13 +92,11 @@ struct ocs_ecc_dev {
/** /**
* struct ocs_ecc_ctx - Transformation context. * struct ocs_ecc_ctx - Transformation context.
* @engine_ctx: Crypto engine ctx.
* @ecc_dev: The ECC driver associated with this context. * @ecc_dev: The ECC driver associated with this context.
* @curve: The elliptic curve used by this transformation. * @curve: The elliptic curve used by this transformation.
* @private_key: The private key. * @private_key: The private key.
*/ */
struct ocs_ecc_ctx { struct ocs_ecc_ctx {
struct crypto_engine_ctx engine_ctx;
struct ocs_ecc_dev *ecc_dev; struct ocs_ecc_dev *ecc_dev;
const struct ecc_curve *curve; const struct ecc_curve *curve;
u64 private_key[KMB_ECC_VLI_MAX_DIGITS]; u64 private_key[KMB_ECC_VLI_MAX_DIGITS];
...@@ -794,8 +789,6 @@ static int kmb_ecc_tctx_init(struct ocs_ecc_ctx *tctx, unsigned int curve_id) ...@@ -794,8 +789,6 @@ static int kmb_ecc_tctx_init(struct ocs_ecc_ctx *tctx, unsigned int curve_id)
if (!tctx->curve) if (!tctx->curve)
return -EOPNOTSUPP; return -EOPNOTSUPP;
tctx->engine_ctx.op.do_one_request = kmb_ocs_ecc_do_one_request;
return 0; return 0;
} }
...@@ -828,36 +821,38 @@ static unsigned int kmb_ocs_ecdh_max_size(struct crypto_kpp *tfm) ...@@ -828,36 +821,38 @@ static unsigned int kmb_ocs_ecdh_max_size(struct crypto_kpp *tfm)
return digits_to_bytes(tctx->curve->g.ndigits) * 2; return digits_to_bytes(tctx->curve->g.ndigits) * 2;
} }
static struct kpp_alg ocs_ecdh_p256 = { static struct kpp_engine_alg ocs_ecdh_p256 = {
.set_secret = kmb_ocs_ecdh_set_secret, .base.set_secret = kmb_ocs_ecdh_set_secret,
.generate_public_key = kmb_ocs_ecdh_generate_public_key, .base.generate_public_key = kmb_ocs_ecdh_generate_public_key,
.compute_shared_secret = kmb_ocs_ecdh_compute_shared_secret, .base.compute_shared_secret = kmb_ocs_ecdh_compute_shared_secret,
.init = kmb_ocs_ecdh_nist_p256_init_tfm, .base.init = kmb_ocs_ecdh_nist_p256_init_tfm,
.exit = kmb_ocs_ecdh_exit_tfm, .base.exit = kmb_ocs_ecdh_exit_tfm,
.max_size = kmb_ocs_ecdh_max_size, .base.max_size = kmb_ocs_ecdh_max_size,
.base = { .base.base = {
.cra_name = "ecdh-nist-p256", .cra_name = "ecdh-nist-p256",
.cra_driver_name = "ecdh-nist-p256-keembay-ocs", .cra_driver_name = "ecdh-nist-p256-keembay-ocs",
.cra_priority = KMB_OCS_ECC_PRIORITY, .cra_priority = KMB_OCS_ECC_PRIORITY,
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
.cra_ctxsize = sizeof(struct ocs_ecc_ctx), .cra_ctxsize = sizeof(struct ocs_ecc_ctx),
}, },
.op.do_one_request = kmb_ocs_ecc_do_one_request,
}; };
static struct kpp_alg ocs_ecdh_p384 = { static struct kpp_engine_alg ocs_ecdh_p384 = {
.set_secret = kmb_ocs_ecdh_set_secret, .base.set_secret = kmb_ocs_ecdh_set_secret,
.generate_public_key = kmb_ocs_ecdh_generate_public_key, .base.generate_public_key = kmb_ocs_ecdh_generate_public_key,
.compute_shared_secret = kmb_ocs_ecdh_compute_shared_secret, .base.compute_shared_secret = kmb_ocs_ecdh_compute_shared_secret,
.init = kmb_ocs_ecdh_nist_p384_init_tfm, .base.init = kmb_ocs_ecdh_nist_p384_init_tfm,
.exit = kmb_ocs_ecdh_exit_tfm, .base.exit = kmb_ocs_ecdh_exit_tfm,
.max_size = kmb_ocs_ecdh_max_size, .base.max_size = kmb_ocs_ecdh_max_size,
.base = { .base.base = {
.cra_name = "ecdh-nist-p384", .cra_name = "ecdh-nist-p384",
.cra_driver_name = "ecdh-nist-p384-keembay-ocs", .cra_driver_name = "ecdh-nist-p384-keembay-ocs",
.cra_priority = KMB_OCS_ECC_PRIORITY, .cra_priority = KMB_OCS_ECC_PRIORITY,
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
.cra_ctxsize = sizeof(struct ocs_ecc_ctx), .cra_ctxsize = sizeof(struct ocs_ecc_ctx),
}, },
.op.do_one_request = kmb_ocs_ecc_do_one_request,
}; };
static irqreturn_t ocs_ecc_irq_handler(int irq, void *dev_id) static irqreturn_t ocs_ecc_irq_handler(int irq, void *dev_id)
...@@ -939,14 +934,14 @@ static int kmb_ocs_ecc_probe(struct platform_device *pdev) ...@@ -939,14 +934,14 @@ static int kmb_ocs_ecc_probe(struct platform_device *pdev)
} }
/* Register the KPP algo. */ /* Register the KPP algo. */
rc = crypto_register_kpp(&ocs_ecdh_p256); rc = crypto_engine_register_kpp(&ocs_ecdh_p256);
if (rc) { if (rc) {
dev_err(dev, dev_err(dev,
"Could not register OCS algorithms with Crypto API\n"); "Could not register OCS algorithms with Crypto API\n");
goto cleanup; goto cleanup;
} }
rc = crypto_register_kpp(&ocs_ecdh_p384); rc = crypto_engine_register_kpp(&ocs_ecdh_p384);
if (rc) { if (rc) {
dev_err(dev, dev_err(dev,
"Could not register OCS algorithms with Crypto API\n"); "Could not register OCS algorithms with Crypto API\n");
...@@ -956,7 +951,7 @@ static int kmb_ocs_ecc_probe(struct platform_device *pdev) ...@@ -956,7 +951,7 @@ static int kmb_ocs_ecc_probe(struct platform_device *pdev)
return 0; return 0;
ocs_ecdh_p384_error: ocs_ecdh_p384_error:
crypto_unregister_kpp(&ocs_ecdh_p256); crypto_engine_unregister_kpp(&ocs_ecdh_p256);
cleanup: cleanup:
crypto_engine_exit(ecc_dev->engine); crypto_engine_exit(ecc_dev->engine);
...@@ -975,8 +970,8 @@ static int kmb_ocs_ecc_remove(struct platform_device *pdev) ...@@ -975,8 +970,8 @@ static int kmb_ocs_ecc_remove(struct platform_device *pdev)
ecc_dev = platform_get_drvdata(pdev); ecc_dev = platform_get_drvdata(pdev);
crypto_unregister_kpp(&ocs_ecdh_p384); crypto_engine_unregister_kpp(&ocs_ecdh_p384);
crypto_unregister_kpp(&ocs_ecdh_p256); crypto_engine_unregister_kpp(&ocs_ecdh_p256);
spin_lock(&ocs_ecc.lock); spin_lock(&ocs_ecc.lock);
list_del(&ecc_dev->list); list_del(&ecc_dev->list);
......
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