Update some patch for uadk_engine from mainline. Signed-off-by: Yang Shen <shenyang39@huawei.com> (cherry picked from commit 6ae4d8c0999343eddb153c4e4e879a6b66ef528f)
122 lines
3.2 KiB
Diff
122 lines
3.2 KiB
Diff
From c8dbfbdd80ea8b8d422a50c634e057dd37ac9aea Mon Sep 17 00:00:00 2001
|
|
From: Zhiqi Song <songzhiqi1@huawei.com>
|
|
Date: Sat, 23 Jul 2022 16:45:03 +0800
|
|
Subject: [PATCH 46/57] ecc: cleanup of static code check
|
|
|
|
1. Use macros instead of specific numbers to represent
|
|
the key size.
|
|
2. Global variable 'sm2_order' only used in function
|
|
'sm2_update_sess' should be declared in function scope.
|
|
3. Remove unused structure 'uadk_ecc_sess'.
|
|
|
|
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
|
---
|
|
src/uadk_ec.c | 22 +++++++++++-----------
|
|
src/uadk_pkey.c | 9 ---------
|
|
src/uadk_sm2.c | 21 ++++++---------------
|
|
3 files changed, 17 insertions(+), 35 deletions(-)
|
|
|
|
diff --git a/src/uadk_ec.c b/src/uadk_ec.c
|
|
index e219bdf..d78658b 100644
|
|
--- a/src/uadk_ec.c
|
|
+++ b/src/uadk_ec.c
|
|
@@ -129,18 +129,18 @@ err:
|
|
static int get_smallest_hw_keybits(int bits)
|
|
{
|
|
/* ec curve order width */
|
|
- if (bits > 384)
|
|
- return 521;
|
|
- else if (bits > 320)
|
|
- return 384;
|
|
- else if (bits > 256)
|
|
- return 320;
|
|
- else if (bits > 192)
|
|
- return 256;
|
|
- else if (bits > 128)
|
|
- return 192;
|
|
+ if (bits > ECC384BITS)
|
|
+ return ECC521BITS;
|
|
+ else if (bits > ECC320BITS)
|
|
+ return ECC384BITS;
|
|
+ else if (bits > ECC256BITS)
|
|
+ return ECC320BITS;
|
|
+ else if (bits > ECC192BITS)
|
|
+ return ECC256BITS;
|
|
+ else if (bits > ECC128BITS)
|
|
+ return ECC192BITS;
|
|
else
|
|
- return 128;
|
|
+ return ECC128BITS;
|
|
}
|
|
|
|
static handle_t ecc_alloc_sess(const EC_KEY *eckey, char *alg)
|
|
diff --git a/src/uadk_pkey.c b/src/uadk_pkey.c
|
|
index 2616c5e..a0b74af 100644
|
|
--- a/src/uadk_pkey.c
|
|
+++ b/src/uadk_pkey.c
|
|
@@ -44,15 +44,6 @@ struct ecc_res_config {
|
|
int numa_id;
|
|
};
|
|
|
|
-typedef struct uadk_ecc_sess {
|
|
- handle_t sess;
|
|
- struct wd_ecc_sess_setup setup;
|
|
- struct wd_ecc_req req;
|
|
- int is_pubkey_ready;
|
|
- int is_privkey_ready;
|
|
- int key_size;
|
|
-} uadk_ecc_sess_t;
|
|
-
|
|
/* ecc global hardware resource is saved here */
|
|
struct ecc_res {
|
|
struct wd_ctx_config *ctx_res;
|
|
diff --git a/src/uadk_sm2.c b/src/uadk_sm2.c
|
|
index a478a94..fcca9f2 100644
|
|
--- a/src/uadk_sm2.c
|
|
+++ b/src/uadk_sm2.c
|
|
@@ -46,15 +46,6 @@ struct sm2_ctx {
|
|
bool is_init;
|
|
};
|
|
|
|
-typedef struct uadk_ecc_sess {
|
|
- handle_t sess;
|
|
- struct wd_ecc_sess_setup setup;
|
|
- struct wd_ecc_req req;
|
|
- int is_pubkey_ready;
|
|
- int is_privkey_ready;
|
|
- int key_size;
|
|
-} uadk_ecc_sess_t;
|
|
-
|
|
typedef struct sm2_ciphertext {
|
|
BIGNUM *C1x;
|
|
BIGNUM *C1y;
|
|
@@ -115,12 +106,6 @@ typedef int (*PFUNC_DEC)(EVP_PKEY_CTX *ctx,
|
|
const unsigned char *in,
|
|
size_t inlen);
|
|
|
|
-const unsigned char sm2_order[] = {
|
|
- 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\
|
|
- 0xff, 0xff, 0xff, 0xff, 0x72, 0x03, 0xdf, 0x6b, 0x21, 0xc6, 0x05, 0x2b,\
|
|
- 0x53, 0xbb, 0xf4, 0x09, 0x39, 0xd5, 0x41, 0x23
|
|
-};
|
|
-
|
|
static int get_hash_type(int nid_hash)
|
|
{
|
|
switch (nid_hash) {
|
|
@@ -166,6 +151,12 @@ static int compute_hash(const char *in, size_t in_len,
|
|
|
|
static int sm2_update_sess(struct sm2_ctx *smctx)
|
|
{
|
|
+ const unsigned char sm2_order[] = {
|
|
+ 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff,
|
|
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
+ 0x72, 0x03, 0xdf, 0x6b, 0x21, 0xc6, 0x05, 0x2b,
|
|
+ 0x53, 0xbb, 0xf4, 0x09, 0x39, 0xd5, 0x41, 0x23
|
|
+ };
|
|
int nid_hash = smctx->ctx.md ? EVP_MD_type(smctx->ctx.md) : NID_sm3;
|
|
struct wd_ecc_sess_setup setup;
|
|
handle_t sess;
|
|
--
|
|
2.27.0
|
|
|