
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 6d8d5d5..3c8d148 100644 --- a/src/uadk.h +++ b/src/uadk.h @@ -17,9 +17,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 e4eff43..cf8b0cd 100644 --- a/src/uadk_async.c +++ b/src/uadk_async.c @@ -19,6 +19,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 dbcd142..fdfd32d 100644 --- a/src/uadk_async.h +++ b/src/uadk_async.h @@ -18,8 +18,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 7acaa73..c71e54c 100644 --- a/src/uadk_cipher.c +++ b/src/uadk_cipher.c @@ -21,6 +21,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 3ec3011..6065160 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 cfdc852..ba0876e 100644 --- a/src/uadk_digest.c +++ b/src/uadk_digest.c @@ -24,8 +24,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 b07b610..e341f5b 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 56ce3dc..e6edbc3 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 5dc1c60..e73a2fe 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 a5d5520..e7ab9ff 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 a6fe71f..af26690 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); -- 2.30.0