126 lines
4.5 KiB
Diff
126 lines
4.5 KiB
Diff
From e6dae9e2197dad6173f9ec7fbc55373adcfbb29e Mon Sep 17 00:00:00 2001
|
|
From: Zhangfei Gao <zhangfei.gao@linaro.org>
|
|
Date: Tue, 6 Jun 2023 06:12:23 +0000
|
|
Subject: [PATCH 3/7] v1: some code clean
|
|
|
|
remove #if 0, print address, etc
|
|
|
|
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
|
|
---
|
|
src/v1/alg/ciphers/sec_ciphers_soft.c | 15 ++++-----------
|
|
src/v1/alg/pkey/hpre_rsa.c | 20 +-------------------
|
|
src/v1/alg/pkey/hpre_rsa_utils.c | 5 ++---
|
|
3 files changed, 7 insertions(+), 33 deletions(-)
|
|
|
|
diff --git a/src/v1/alg/ciphers/sec_ciphers_soft.c b/src/v1/alg/ciphers/sec_ciphers_soft.c
|
|
index 71fbb33..9c597b5 100644
|
|
--- a/src/v1/alg/ciphers/sec_ciphers_soft.c
|
|
+++ b/src/v1/alg/ciphers/sec_ciphers_soft.c
|
|
@@ -110,11 +110,11 @@ int sec_ciphers_sw_impl_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
|
|
|
/* allowed iv to be empty. */
|
|
if (unlikely(key == NULL)) {
|
|
- US_ERR("kae sw init parameter is NULL. key=%p", key);
|
|
+ US_ERR("kae sw init parameter is NULL");
|
|
return KAE_FAIL;
|
|
}
|
|
if (unlikely(ctx == NULL)) {
|
|
- US_ERR("kae sw init parameter is NULL. ctx=%p", ctx);
|
|
+ US_ERR("kae sw init parameter is NULL");
|
|
return KAE_FAIL;
|
|
}
|
|
|
|
@@ -155,11 +155,10 @@ int sec_ciphers_sw_impl_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
|
ret = EVP_CIPHER_meth_get_init(sw_cipher)(ctx, key, iv, enc);
|
|
EVP_CIPHER_CTX_set_cipher_data(ctx, priv_ctx);
|
|
if (ret != OPENSSL_SUCCESS) {
|
|
- US_ERR("OPENSSL init key failed. ctx=%p", ctx);
|
|
+ US_ERR("OPENSSL init key failed.");
|
|
kae_free(priv_ctx->sw_ctx_data);
|
|
return KAE_FAIL;
|
|
}
|
|
- US_DEBUG("kae sw init impl success. ctx=%p", ctx);
|
|
|
|
return KAE_SUCCESS;
|
|
}
|
|
@@ -185,18 +184,14 @@ int sec_ciphers_sw_impl_cleanup(EVP_CIPHER_CTX *ctx)
|
|
|
|
kae_free(priv_ctx->sw_ctx_data);
|
|
|
|
- US_DEBUG("kae sw cleanup impl success, ctx=%p", ctx);
|
|
-
|
|
return KAE_SUCCESS;
|
|
}
|
|
|
|
static int sec_ciphers_sw_impl_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
const unsigned char *in, size_t inl)
|
|
{
|
|
- if (unlikely((ctx == NULL) || (out == NULL) || (in == NULL))) {
|
|
- US_ERR("kae sw cipher parameter is null.ctx=%p, in=%p, out=%p, inl=%d", ctx, out, in, (int)inl);
|
|
+ if (unlikely((ctx == NULL) || (out == NULL) || (in == NULL)))
|
|
return KAE_FAIL;
|
|
- }
|
|
|
|
cipher_priv_ctx_t *priv_ctx = (cipher_priv_ctx_t *)EVP_CIPHER_CTX_get_cipher_data(ctx);
|
|
|
|
@@ -277,8 +272,6 @@ int sec_ciphers_sw_hw_ctx_sync(EVP_CIPHER_CTX *ctx, sec_cipher_priv_ctx_syncto_t
|
|
}
|
|
}
|
|
|
|
- US_DEBUG("state sync success, direct=%d[1:SW_TO_HW, 2:HW_TO_SW], offset=%d", direction, num);
|
|
-
|
|
return KAE_SUCCESS;
|
|
}
|
|
|
|
diff --git a/src/v1/alg/pkey/hpre_rsa.c b/src/v1/alg/pkey/hpre_rsa.c
|
|
index 6c1d96d..4e21dde 100644
|
|
--- a/src/v1/alg/pkey/hpre_rsa.c
|
|
+++ b/src/v1/alg/pkey/hpre_rsa.c
|
|
@@ -67,25 +67,7 @@ RSA_METHOD *hpre_get_rsa_methods(void)
|
|
return g_hpre_rsa_method;
|
|
if (g_soft_rsa_method != NULL)
|
|
return g_soft_rsa_method;
|
|
-#if 0
|
|
- if (!kae_get_device(g_hpre_device)) {
|
|
- const RSA_METHOD *default_soft_method = RSA_PKCS1_OpenSSL();
|
|
-
|
|
- g_soft_rsa_method = RSA_meth_new("SOFT RSA METHOD", 0);
|
|
- ret &= RSA_meth_set_pub_enc(g_soft_rsa_method, RSA_meth_get_pub_enc(default_soft_method));
|
|
- ret &= RSA_meth_set_priv_enc(g_soft_rsa_method, RSA_meth_get_priv_enc(default_soft_method));
|
|
- ret &= RSA_meth_set_pub_dec(g_soft_rsa_method, RSA_meth_get_pub_dec(default_soft_method));
|
|
- ret &= RSA_meth_set_priv_dec(g_soft_rsa_method, RSA_meth_get_priv_dec(default_soft_method));
|
|
- ret &= RSA_meth_set_keygen(g_soft_rsa_method, hpre_rsa_soft_genkey);
|
|
- ret &= RSA_meth_set_mod_exp(g_soft_rsa_method, RSA_meth_get_mod_exp(default_soft_method));
|
|
- ret &= RSA_meth_set_bn_mod_exp(g_soft_rsa_method, RSA_meth_get_bn_mod_exp(default_soft_method));
|
|
- if (ret == 0) {
|
|
- US_ERR("Failed to set SOFT RSA methods");
|
|
- return NULL;
|
|
- }
|
|
- return g_soft_rsa_method;
|
|
- }
|
|
-#endif
|
|
+
|
|
g_hpre_rsa_method = RSA_meth_new("HPRE RSA method", 0);
|
|
if (g_hpre_rsa_method == NULL) {
|
|
KAEerr(KAE_F_HPRE_GET_RSA_METHODS, KAE_R_MALLOC_FAILURE);
|
|
diff --git a/src/v1/alg/pkey/hpre_rsa_utils.c b/src/v1/alg/pkey/hpre_rsa_utils.c
|
|
index 0630b28..317a5a0 100644
|
|
--- a/src/v1/alg/pkey/hpre_rsa_utils.c
|
|
+++ b/src/v1/alg/pkey/hpre_rsa_utils.c
|
|
@@ -44,10 +44,9 @@ void hpre_free_bn_ctx_buf(BN_CTX *bn_ctx, unsigned char *in_buf, int num)
|
|
int hpre_rsa_check_para(int flen, const unsigned char *from,
|
|
unsigned char *to, RSA *rsa)
|
|
{
|
|
- if ((rsa == NULL || from == NULL || to == NULL || flen <= 0)) {
|
|
- US_ERR("RSA key %p, input %p or output %p are NULL, or flen invalid length.\n", rsa, from, to);
|
|
+ if ((rsa == NULL || from == NULL || to == NULL || flen <= 0))
|
|
return HPRE_CRYPTO_FAIL;
|
|
- }
|
|
+
|
|
return HPRE_CRYPTO_SUCC;
|
|
}
|
|
|
|
--
|
|
2.25.1
|
|
|