Commit b1be70a8 authored by Zhiqi Song's avatar Zhiqi Song Committed by Herbert Xu

crypto: hisilicon/hpre - optimize registration of ecdh

Use table to store the different ecdh curve configuration,
making the registration of ecdh clearer and expansion more
convenient.
Signed-off-by: default avatarZhiqi Song <songzhiqi1@huawei.com>
Signed-off-by: default avatarWeili Qian <qianweili@huawei.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent f214d59a
...@@ -2008,55 +2008,53 @@ static struct kpp_alg dh = { ...@@ -2008,55 +2008,53 @@ static struct kpp_alg dh = {
}, },
}; };
static struct kpp_alg ecdh_nist_p192 = { static struct kpp_alg ecdh_curves[] = {
.set_secret = hpre_ecdh_set_secret, {
.generate_public_key = hpre_ecdh_compute_value, .set_secret = hpre_ecdh_set_secret,
.compute_shared_secret = hpre_ecdh_compute_value, .generate_public_key = hpre_ecdh_compute_value,
.max_size = hpre_ecdh_max_size, .compute_shared_secret = hpre_ecdh_compute_value,
.init = hpre_ecdh_nist_p192_init_tfm, .max_size = hpre_ecdh_max_size,
.exit = hpre_ecdh_exit_tfm, .init = hpre_ecdh_nist_p192_init_tfm,
.reqsize = sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ, .exit = hpre_ecdh_exit_tfm,
.base = { .reqsize = sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ,
.cra_ctxsize = sizeof(struct hpre_ctx), .base = {
.cra_priority = HPRE_CRYPTO_ALG_PRI, .cra_ctxsize = sizeof(struct hpre_ctx),
.cra_name = "ecdh-nist-p192", .cra_priority = HPRE_CRYPTO_ALG_PRI,
.cra_driver_name = "hpre-ecdh-nist-p192", .cra_name = "ecdh-nist-p192",
.cra_module = THIS_MODULE, .cra_driver_name = "hpre-ecdh-nist-p192",
}, .cra_module = THIS_MODULE,
}; },
}, {
static struct kpp_alg ecdh_nist_p256 = { .set_secret = hpre_ecdh_set_secret,
.set_secret = hpre_ecdh_set_secret, .generate_public_key = hpre_ecdh_compute_value,
.generate_public_key = hpre_ecdh_compute_value, .compute_shared_secret = hpre_ecdh_compute_value,
.compute_shared_secret = hpre_ecdh_compute_value, .max_size = hpre_ecdh_max_size,
.max_size = hpre_ecdh_max_size, .init = hpre_ecdh_nist_p256_init_tfm,
.init = hpre_ecdh_nist_p256_init_tfm, .exit = hpre_ecdh_exit_tfm,
.exit = hpre_ecdh_exit_tfm, .reqsize = sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ,
.reqsize = sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ, .base = {
.base = { .cra_ctxsize = sizeof(struct hpre_ctx),
.cra_ctxsize = sizeof(struct hpre_ctx), .cra_priority = HPRE_CRYPTO_ALG_PRI,
.cra_priority = HPRE_CRYPTO_ALG_PRI, .cra_name = "ecdh-nist-p256",
.cra_name = "ecdh-nist-p256", .cra_driver_name = "hpre-ecdh-nist-p256",
.cra_driver_name = "hpre-ecdh-nist-p256", .cra_module = THIS_MODULE,
.cra_module = THIS_MODULE, },
}, }, {
}; .set_secret = hpre_ecdh_set_secret,
.generate_public_key = hpre_ecdh_compute_value,
static struct kpp_alg ecdh_nist_p384 = { .compute_shared_secret = hpre_ecdh_compute_value,
.set_secret = hpre_ecdh_set_secret, .max_size = hpre_ecdh_max_size,
.generate_public_key = hpre_ecdh_compute_value, .init = hpre_ecdh_nist_p384_init_tfm,
.compute_shared_secret = hpre_ecdh_compute_value, .exit = hpre_ecdh_exit_tfm,
.max_size = hpre_ecdh_max_size, .reqsize = sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ,
.init = hpre_ecdh_nist_p384_init_tfm, .base = {
.exit = hpre_ecdh_exit_tfm, .cra_ctxsize = sizeof(struct hpre_ctx),
.reqsize = sizeof(struct hpre_asym_request) + HPRE_ALIGN_SZ, .cra_priority = HPRE_CRYPTO_ALG_PRI,
.base = { .cra_name = "ecdh-nist-p384",
.cra_ctxsize = sizeof(struct hpre_ctx), .cra_driver_name = "hpre-ecdh-nist-p384",
.cra_priority = HPRE_CRYPTO_ALG_PRI, .cra_module = THIS_MODULE,
.cra_name = "ecdh-nist-p384", },
.cra_driver_name = "hpre-ecdh-nist-p384", }
.cra_module = THIS_MODULE,
},
}; };
static struct kpp_alg curve25519_alg = { static struct kpp_alg curve25519_alg = {
...@@ -2123,46 +2121,38 @@ static void hpre_unregister_dh(struct hisi_qm *qm) ...@@ -2123,46 +2121,38 @@ static void hpre_unregister_dh(struct hisi_qm *qm)
static int hpre_register_ecdh(struct hisi_qm *qm) static int hpre_register_ecdh(struct hisi_qm *qm)
{ {
int ret; int ret, i;
if (!hpre_check_alg_support(qm, HPRE_DRV_ECDH_MASK_CAP)) if (!hpre_check_alg_support(qm, HPRE_DRV_ECDH_MASK_CAP))
return 0; return 0;
ret = crypto_register_kpp(&ecdh_nist_p192); for (i = 0; i < ARRAY_SIZE(ecdh_curves); i++) {
if (ret) { ret = crypto_register_kpp(&ecdh_curves[i]);
dev_err(&qm->pdev->dev, "failed to register ecdh_nist_p192 (%d)!\n", ret); if (ret) {
return ret; dev_err(&qm->pdev->dev, "failed to register %s (%d)!\n",
} ecdh_curves[i].base.cra_name, ret);
goto unreg_kpp;
ret = crypto_register_kpp(&ecdh_nist_p256); }
if (ret) {
dev_err(&qm->pdev->dev, "failed to register ecdh_nist_p256 (%d)!\n", ret);
goto unregister_ecdh_p192;
}
ret = crypto_register_kpp(&ecdh_nist_p384);
if (ret) {
dev_err(&qm->pdev->dev, "failed to register ecdh_nist_p384 (%d)!\n", ret);
goto unregister_ecdh_p256;
} }
return 0; return 0;
unregister_ecdh_p256: unreg_kpp:
crypto_unregister_kpp(&ecdh_nist_p256); for (--i; i >= 0; --i)
unregister_ecdh_p192: crypto_unregister_kpp(&ecdh_curves[i]);
crypto_unregister_kpp(&ecdh_nist_p192);
return ret; return ret;
} }
static void hpre_unregister_ecdh(struct hisi_qm *qm) static void hpre_unregister_ecdh(struct hisi_qm *qm)
{ {
int i;
if (!hpre_check_alg_support(qm, HPRE_DRV_ECDH_MASK_CAP)) if (!hpre_check_alg_support(qm, HPRE_DRV_ECDH_MASK_CAP))
return; return;
crypto_unregister_kpp(&ecdh_nist_p384); for (i = ARRAY_SIZE(ecdh_curves) - 1; i >= 0; --i)
crypto_unregister_kpp(&ecdh_nist_p256); crypto_unregister_kpp(&ecdh_curves[i]);
crypto_unregister_kpp(&ecdh_nist_p192);
} }
static int hpre_register_x25519(struct hisi_qm *qm) static int hpre_register_x25519(struct hisi_qm *qm)
......
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