251 lines
6.6 KiB
Diff
251 lines
6.6 KiB
Diff
From 1dd1503428df2b33f679f81b1541a4314fe0aa11 Mon Sep 17 00:00:00 2001
|
|
From: Zhiqi Song <songzhiqi1@huawei.com>
|
|
Date: Sat, 22 Oct 2022 15:56:54 +0800
|
|
Subject: uadk_engine: cleanup header file
|
|
|
|
Remove redundant header file and modify magic number.
|
|
|
|
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
|
---
|
|
src/uadk.h | 3 ---
|
|
src/uadk_async.c | 1 +
|
|
src/uadk_async.h | 2 +-
|
|
src/uadk_cipher.c | 1 +
|
|
src/uadk_dh.c | 1 +
|
|
src/uadk_digest.c | 2 ++
|
|
src/uadk_ec.c | 1 +
|
|
src/uadk_ecx.c | 2 +-
|
|
src/uadk_pkey.c | 5 ++++-
|
|
src/uadk_rsa.c | 6 +++++-
|
|
src/uadk_sm2.c | 7 +++++--
|
|
11 files changed, 22 insertions(+), 9 deletions(-)
|
|
|
|
diff --git a/src/uadk.h b/src/uadk.h
|
|
index 99c65c7..30c099f 100644
|
|
--- a/src/uadk.h
|
|
+++ b/src/uadk.h
|
|
@@ -18,9 +18,6 @@
|
|
#ifndef UADK_H
|
|
#define UADK_H
|
|
#include <openssl/engine.h>
|
|
-#include <uadk/wd.h>
|
|
-#include <uadk/wd_sched.h>
|
|
-#include "uadk_utils.h"
|
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
|
#define ENV_STRING_LEN 256
|
|
diff --git a/src/uadk_async.c b/src/uadk_async.c
|
|
index 3f2e1db..2edd6ea 100644
|
|
--- a/src/uadk_async.c
|
|
+++ b/src/uadk_async.c
|
|
@@ -20,6 +20,7 @@
|
|
#include <string.h>
|
|
#include <sys/eventfd.h>
|
|
#include <unistd.h>
|
|
+#include <openssl/async.h>
|
|
#include "uadk.h"
|
|
#include "uadk_async.h"
|
|
|
|
diff --git a/src/uadk_async.h b/src/uadk_async.h
|
|
index 9bae3f4..8a4822e 100644
|
|
--- a/src/uadk_async.h
|
|
+++ b/src/uadk_async.h
|
|
@@ -19,8 +19,8 @@
|
|
#define UADK_ASYNC_H
|
|
|
|
#include <stdbool.h>
|
|
-#include <openssl/async.h>
|
|
#include <semaphore.h>
|
|
+#include <openssl/async.h>
|
|
|
|
#define ASYNC_QUEUE_TASK_NUM 1024
|
|
|
|
diff --git a/src/uadk_cipher.c b/src/uadk_cipher.c
|
|
index de5f078..cc06429 100644
|
|
--- a/src/uadk_cipher.c
|
|
+++ b/src/uadk_cipher.c
|
|
@@ -22,6 +22,7 @@
|
|
#include <dlfcn.h>
|
|
#include <openssl/engine.h>
|
|
#include <uadk/wd_cipher.h>
|
|
+#include <uadk/wd_sched.h>
|
|
#include "uadk.h"
|
|
#include "uadk_async.h"
|
|
|
|
diff --git a/src/uadk_dh.c b/src/uadk_dh.c
|
|
index 6356872..680564c 100644
|
|
--- a/src/uadk_dh.c
|
|
+++ b/src/uadk_dh.c
|
|
@@ -23,6 +23,7 @@
|
|
#include <openssl/dh.h>
|
|
#include <string.h>
|
|
#include <uadk/wd_dh.h>
|
|
+#include <uadk/wd_sched.h>
|
|
#include "uadk.h"
|
|
#include "uadk_async.h"
|
|
|
|
diff --git a/src/uadk_digest.c b/src/uadk_digest.c
|
|
index 9d009a9..26a6272 100644
|
|
--- a/src/uadk_digest.c
|
|
+++ b/src/uadk_digest.c
|
|
@@ -25,8 +25,10 @@
|
|
#include <openssl/evp.h>
|
|
#include <uadk/wd_cipher.h>
|
|
#include <uadk/wd_digest.h>
|
|
+#include <uadk/wd_sched.h>
|
|
#include "uadk.h"
|
|
#include "uadk_async.h"
|
|
+#include "uadk_utils.h"
|
|
|
|
#define UADK_DO_SOFT (-0xE0)
|
|
#define CTX_SYNC 0
|
|
diff --git a/src/uadk_ec.c b/src/uadk_ec.c
|
|
index 9b48ae7..6106083 100644
|
|
--- a/src/uadk_ec.c
|
|
+++ b/src/uadk_ec.c
|
|
@@ -23,6 +23,7 @@
|
|
#include <openssl/err.h>
|
|
#include <openssl/ec.h>
|
|
#include <uadk/wd_ecc.h>
|
|
+#include <uadk/wd_sched.h>
|
|
#include "uadk_pkey.h"
|
|
#include "uadk.h"
|
|
|
|
diff --git a/src/uadk_ecx.c b/src/uadk_ecx.c
|
|
index 67042a3..b62f81d 100644
|
|
--- a/src/uadk_ecx.c
|
|
+++ b/src/uadk_ecx.c
|
|
@@ -14,7 +14,6 @@
|
|
* limitations under the License.
|
|
*
|
|
*/
|
|
-#include <errno.h>
|
|
#include <string.h>
|
|
#include <openssl/bn.h>
|
|
#include <openssl/engine.h>
|
|
@@ -24,6 +23,7 @@
|
|
#include <openssl/ec.h>
|
|
#include <openssl/evp.h>
|
|
#include <uadk/wd_ecc.h>
|
|
+#include <uadk/wd_sched.h>
|
|
#include "uadk_pkey.h"
|
|
#include "uadk.h"
|
|
|
|
diff --git a/src/uadk_pkey.c b/src/uadk_pkey.c
|
|
index 6b5ae9a..7b7a345 100644
|
|
--- a/src/uadk_pkey.c
|
|
+++ b/src/uadk_pkey.c
|
|
@@ -17,6 +17,7 @@
|
|
#include <openssl/engine.h>
|
|
#include <uadk/wd.h>
|
|
#include <uadk/wd_ecc.h>
|
|
+#include <uadk/wd_sched.h>
|
|
#include "uadk_async.h"
|
|
#include "uadk.h"
|
|
#include "uadk_pkey.h"
|
|
@@ -381,6 +382,7 @@ int uadk_ecc_set_private_key(handle_t sess, const EC_KEY *eckey)
|
|
const EC_GROUP *group;
|
|
struct wd_dtb prikey;
|
|
const BIGNUM *d;
|
|
+ size_t degree;
|
|
int buflen;
|
|
int ret;
|
|
|
|
@@ -396,7 +398,8 @@ int uadk_ecc_set_private_key(handle_t sess, const EC_KEY *eckey)
|
|
return -EINVAL;
|
|
}
|
|
|
|
- buflen = BITS_TO_BYTES(EC_GROUP_get_degree(group));
|
|
+ degree = EC_GROUP_get_degree(group);
|
|
+ buflen = BITS_TO_BYTES(degree);
|
|
ecc_key = wd_ecc_get_key(sess);
|
|
prikey.data = (void *)bin;
|
|
prikey.dsize = BN_bn2binpad(d, bin, buflen);
|
|
diff --git a/src/uadk_rsa.c b/src/uadk_rsa.c
|
|
index e9a2c53..96c898f 100644
|
|
--- a/src/uadk_rsa.c
|
|
+++ b/src/uadk_rsa.c
|
|
@@ -20,6 +20,7 @@
|
|
#include <openssl/ossl_typ.h>
|
|
#include <openssl/rsa.h>
|
|
#include <uadk/wd_rsa.h>
|
|
+#include <uadk/wd_sched.h>
|
|
#include "uadk_async.h"
|
|
#include "uadk.h"
|
|
|
|
@@ -55,6 +56,7 @@
|
|
#define PRIME_RETRY_COUNT 4
|
|
#define GENCB_NEXT 2
|
|
#define GENCB_RETRY 3
|
|
+#define PRIME_CHECK_BIT_NUM 4
|
|
|
|
static RSA_METHOD *rsa_hw_meth;
|
|
|
|
@@ -210,7 +212,7 @@ static int check_rsa_prime_sufficient(int *num, const int *bitsr,
|
|
* key by using the modulus in a certificate. This is also covered
|
|
* by checking the length should not be less than 0x9.
|
|
*/
|
|
- if (!BN_rshift(param->r2, param->r1, *bitse - 4))
|
|
+ if (!BN_rshift(param->r2, param->r1, *bitse - PRIME_CHECK_BIT_NUM))
|
|
return BN_ERR;
|
|
|
|
bitst = BN_get_word(param->r2);
|
|
@@ -231,6 +233,7 @@ static int check_rsa_prime_sufficient(int *num, const int *bitsr,
|
|
ret = BN_GENCB_call(cb, GENCB_NEXT, *n++);
|
|
if (!ret)
|
|
return -1;
|
|
+
|
|
if (retries == PRIME_RETRY_COUNT) {
|
|
*num = -1;
|
|
*bitse = 0;
|
|
@@ -288,6 +291,7 @@ static int check_rsa_prime_useful(const int *n, struct rsa_prime_param *param,
|
|
BIGNUM *e_pub, BN_CTX *ctx, BN_GENCB *cb)
|
|
{
|
|
unsigned long err;
|
|
+
|
|
/*
|
|
* BN_sub(r,a,b) substracts b from a and place the result in r,
|
|
* r = a-b.
|
|
diff --git a/src/uadk_sm2.c b/src/uadk_sm2.c
|
|
index 578d2d8..b14fbcf 100644
|
|
--- a/src/uadk_sm2.c
|
|
+++ b/src/uadk_sm2.c
|
|
@@ -22,6 +22,7 @@
|
|
#include <openssl/ossl_typ.h>
|
|
#include <openssl/err.h>
|
|
#include <uadk/wd_ecc.h>
|
|
+#include <uadk/wd_sched.h>
|
|
#include "uadk.h"
|
|
#include "uadk_pkey.h"
|
|
|
|
@@ -550,6 +551,7 @@ static size_t ec_field_size(const EC_GROUP *group)
|
|
BIGNUM *a = BN_new();
|
|
BIGNUM *b = BN_new();
|
|
size_t field_size = 0;
|
|
+ size_t p_bits;
|
|
|
|
if (p == NULL || a == NULL || b == NULL)
|
|
goto done;
|
|
@@ -557,7 +559,8 @@ static size_t ec_field_size(const EC_GROUP *group)
|
|
if (!EC_GROUP_get_curve(group, p, a, b, NULL))
|
|
goto done;
|
|
|
|
- field_size = BITS_TO_BYTES(BN_num_bits(p));
|
|
+ p_bits = BN_num_bits(p);
|
|
+ field_size = BITS_TO_BYTES(p_bits);
|
|
|
|
done:
|
|
BN_free(p);
|
|
@@ -598,7 +601,7 @@ static int sm2_ciphertext_size(const EC_KEY *key,
|
|
* Integer and string are simple type; set constructed = 0, means
|
|
* primitive and definite length encoding.
|
|
*/
|
|
- sz = 2 * ASN1_object_size(0, field_size + 1, V_ASN1_INTEGER)
|
|
+ sz = ECC_POINT_SIZE(ASN1_object_size(0, field_size + 1, V_ASN1_INTEGER))
|
|
+ ASN1_object_size(0, md_size, V_ASN1_OCTET_STRING)
|
|
+ ASN1_object_size(0, msg_len, V_ASN1_OCTET_STRING);
|
|
*ct_size = ASN1_object_size(1, sz, V_ASN1_SEQUENCE);
|
|
--
|
|
1.8.3.1
|
|
|