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,7 +2008,8 @@ static struct kpp_alg dh = { ...@@ -2008,7 +2008,8 @@ static struct kpp_alg dh = {
}, },
}; };
static struct kpp_alg ecdh_nist_p192 = { static struct kpp_alg ecdh_curves[] = {
{
.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,
...@@ -2023,9 +2024,7 @@ static struct kpp_alg ecdh_nist_p192 = { ...@@ -2023,9 +2024,7 @@ static struct kpp_alg ecdh_nist_p192 = {
.cra_driver_name = "hpre-ecdh-nist-p192", .cra_driver_name = "hpre-ecdh-nist-p192",
.cra_module = THIS_MODULE, .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,
...@@ -2040,9 +2039,7 @@ static struct kpp_alg ecdh_nist_p256 = { ...@@ -2040,9 +2039,7 @@ static struct kpp_alg 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,
}, },
}; }, {
static struct kpp_alg ecdh_nist_p384 = {
.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,
...@@ -2057,6 +2054,7 @@ static struct kpp_alg ecdh_nist_p384 = { ...@@ -2057,6 +2054,7 @@ static struct kpp_alg ecdh_nist_p384 = {
.cra_driver_name = "hpre-ecdh-nist-p384", .cra_driver_name = "hpre-ecdh-nist-p384",
.cra_module = THIS_MODULE, .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++) {
ret = crypto_register_kpp(&ecdh_curves[i]);
if (ret) { if (ret) {
dev_err(&qm->pdev->dev, "failed to register ecdh_nist_p192 (%d)!\n", ret); dev_err(&qm->pdev->dev, "failed to register %s (%d)!\n",
return ret; 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