Skip to content

Conversation

@patch-king
Copy link

Add support for multiple RSA padding modes with OpenSSL provider mechanism.

  1. RSA_X931_PADDING and RSA_PKCS1_PSS_PADDING for signing and verification.
  2. RSA_PKCS1_OAEP_PADDING and RSA_PKCS1_WITH_TLS_PADDING for encryption and
    decryption.

@gaozhangfei
Copy link
Collaborator

编译很多warning, 看下ci log
https://github.com/Linaro/uadk_engine/actions/runs/20288108850/job/58266429039?pr=251
uadk_prov_rsa_utils.c:134:12: warning: 'ossl_digest_rsa_sign_get_md_nid' defined but not used [-Wunused-function]
134 | static int ossl_digest_rsa_sign_get_md_nid(OSSL_LIB_CTX *ctx, const EVP_MD *md,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uadk_prov_rsa_utils.c:89:20: warning: 'ossl_rsa_oaeppss_nid2name' defined but not used [-Wunused-function]
89 | static const char *ossl_rsa_oaeppss_nid2name(int md)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
uadk_prov_rsa_utils.c:62:12: warning: 'ossl_rsa_pss_params_30_hashalg' defined but not used [-Wunused-function]
62 | static int ossl_rsa_pss_params_30_hashalg(const struct rsa_pss_params_30_st *rsa_pss_params)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uadk_prov_rsa_utils.c:55:12: warning: 'ossl_rsa_pss_params_30_saltlen' defined but not used [-Wunused-function]
55 | static int ossl_rsa_pss_params_30_saltlen(const struct rsa_pss_params_30_st *rsa_pss_params)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uadk_prov_rsa_utils.c:48:12: warning: 'ossl_rsa_pss_params_30_maskgenhashalg' defined but not used [-Wunused-function]
48 | static int ossl_rsa_pss_params_30_maskgenhashalg(const struct rsa_pss_params_30_st *rsa_pss_params)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uadk_prov_rsa_utils.c:39:12: warning: 'ossl_rsa_pss_params_30_is_unrestricted' defined but not used [-Wunused-function]
39 | static int ossl_rsa_pss_params_30_is_unrestricted(const struct rsa_pss_params_30_st *rsa_pss_params)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uadk_prov_rsa_utils.c:24:37: warning: 'ossl_rsa_get0_pss_params_30' defined but not used [-Wunused-function]
24 | static struct rsa_pss_params_30_st *ossl_rsa_get0_pss_params_30(RSA *r)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~

uadk_prov_dh.c: In function 'uadk_keymgmt_dh_gen':
uadk_prov_dh.c:1388:12: warning: 'ret' may be used uninitialized [-Wmaybe-uninitialized]
1388 | if (ret == UADK_DO_SOFT)
| ^
uadk_prov_dh.c:1340:13: note: 'ret' was declared here
1340 | int ret;
| ^~~

lizhi and others added 11 commits December 18, 2025 14:43
For better code organization and maintainability, original RSA algorithm
is splited into four functional components, including key generation,
encryption/decryption, signing/verification, and public interface
functions.

Signed-off-by: lizhi <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
… padding modes

Several utility functions are introduced to the RSA implementation.
These functions are designed to adapt the existing RSA implementation
to support multiple padding modes, enhancing the Extensibility
of the cryptographic operations.

Signed-off-by: lizhi <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
…padding modes

Add support for RSA signature padding modes with OpenSSL provider
mechanism, including RSA_X931_PADDING and RSA_PKCS1_PSS_PADDING.

Test with:
openssl dgst -sha256 -sign privkey.pem -sigopt rsa_padding_mode:x931
-out signature.bin message.txt
openssl dgst -sha256 -verify pubkey.pem -sigopt rsa_padding_mode:x931
-signature signature.bin message.txt

openssl dgst -sha256 -sign privkey.pem -sigopt rsa_padding_mode:pss
-out signature.bin message.txt
openssl dgst -sha256 -verify pubkey.pem -sigopt rsa_padding_mode:pss
-signature signature.bin message.txt

Signed-off-by: lizhi <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
…H_TLS padding modes

Add support for RSA encryption padding modes with OpenSSL provider
mechanism, including RSA_PKCS1_OAEP_PADDING and
RSA_PKCS1_WITH_TLS_PADDING.

Test with:
openssl pkeyutl -encrypt -in test.txt -out encrypted.bin -pubin
-inkey public.pem -pkeyopt rsa_padding_mode:oaep
openssl pkeyutl -decrypt  -in encrypted.bin -out decrypted.txt
-inkey private.pem -pkeyopt rsa_padding_mode:oaep

openssl s_server -provider uadk_provider -accept 4333 -cert server.pem -www
-cipher AES256-SHA
openssl s_client -provider uadk_provider -connect localhost:4333

Signed-off-by: lizhi <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
…obal variables

Introduce global variables to cache hardware version,
reducing repeated device queries.

Signed-off-by: lizhi <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
Unified provider success and failure return values, and moved
return value macros to uadk_prov.h for better consistency and
maintainability.

Signed-off-by: lizhi <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
uadk_engine will support some algorithms in the OpenSSL 3.0 scenario.
Currently, the framework has adapted to some of these algorithms.
However, when executing the SM3 algorithm, an error related to SM2
is reported. This is because OpenSSL 3.0 has removed SM2 from
the engine scenario in methmods, causing the failure. A fix is needed.

At the same time, the differences in the pkey_ctx structure between
the two OpenSSL versions were resolved, enabling the engine
to support the x25519 and x448 algorithms on OpenSSL 3.0.

Signed-off-by: Zhushuai Yin <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
When creating new dh, set the flags from the method
and call the initialization function. In addition,
remove unnecessary parameter checks.

Signed-off-by: Weili Qian <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
add some general optimization compilation options,
security enhancement options, linker security options, etc.

Signed-off-by: Zhushuai Yin <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
Delete several unused functions in asymmetric encryption algorithm to
improve code clarity.

Signed-off-by: lizhi <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
Fix a null pointer dereference bug in RSA X931 mode.

Signed-off-by: lizhi <[email protected]>
Signed-off-by: JiangShui Yang <[email protected]>
@lizhi-promax
Copy link

ok

@gaozhangfei gaozhangfei merged commit 8b0fbf8 into Linaro:master Dec 18, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants