From c1ebe0509a1b4af4cc1f3a7a14ca463d32af918c Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Wed, 4 Dec 2019 10:21:06 +0000 Subject: [PATCH] Backport the RSA_get0_pss_params() function from master This is a missing accessor in order to obtain PSS parameters from an RSA key, which should also be available in 1.1.1. Reviewed-by: Richard Levitte Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/10568) --- crypto/rsa/rsa_lib.c | 5 +++++ doc/man3/RSA_get0_key.pod | 5 ++++- include/openssl/ossl_typ.h | 1 + include/openssl/rsa.h | 5 +++-- util/libcrypto.num | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c index cfee919352..63fd1a6db4 100644 --- a/crypto/rsa/rsa_lib.c +++ b/crypto/rsa/rsa_lib.c @@ -451,6 +451,11 @@ const BIGNUM *RSA_get0_iqmp(const RSA *r) return r->iqmp; } +const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r) +{ + return r->pss; +} + void RSA_clear_flags(RSA *r, int flags) { r->flags &= ~flags; diff --git a/doc/man3/RSA_get0_key.pod b/doc/man3/RSA_get0_key.pod index 358c2de256..b2bcae1138 100644 --- a/doc/man3/RSA_get0_key.pod +++ b/doc/man3/RSA_get0_key.pod @@ -5,7 +5,7 @@ RSA_set0_key, RSA_set0_factors, RSA_set0_crt_params, RSA_get0_key, RSA_get0_factors, RSA_get0_crt_params, RSA_get0_n, RSA_get0_e, RSA_get0_d, RSA_get0_p, RSA_get0_q, -RSA_get0_dmp1, RSA_get0_dmq1, RSA_get0_iqmp, +RSA_get0_dmp1, RSA_get0_dmq1, RSA_get0_iqmp, RSA_get0_pss_params, RSA_clear_flags, RSA_test_flags, RSA_set_flags, RSA_get0_engine, RSA_get_multi_prime_extra_count, RSA_get0_multi_prime_factors, RSA_get0_multi_prime_crt_params, @@ -33,6 +33,7 @@ RSA_set0_multi_prime_params, RSA_get_version const BIGNUM *RSA_get0_dmp1(const RSA *r); const BIGNUM *RSA_get0_dmq1(const RSA *r); const BIGNUM *RSA_get0_iqmp(const RSA *r); + const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r); void RSA_clear_flags(RSA *r, int flags); int RSA_test_flags(const RSA *r, int flags); void RSA_set_flags(RSA *r, int flags); @@ -98,6 +99,8 @@ retrieved separately by the corresponding function RSA_get0_n(), RSA_get0_e(), RSA_get0_d(), RSA_get0_p(), RSA_get0_q(), RSA_get0_dmp1(), RSA_get0_dmq1(), and RSA_get0_iqmp(), respectively. +RSA_get0_pss_params() is used to retrieve the RSA-PSS parameters. + RSA_set_flags() sets the flags in the B parameter on the RSA object. Multiple flags can be passed in one go (bitwise ORed together). Any flags that are already set are left set. RSA_test_flags() tests to diff --git a/include/openssl/ossl_typ.h b/include/openssl/ossl_typ.h index 7993ca28f3..e0edfaaf47 100644 --- a/include/openssl/ossl_typ.h +++ b/include/openssl/ossl_typ.h @@ -109,6 +109,7 @@ typedef struct dsa_method DSA_METHOD; typedef struct rsa_st RSA; typedef struct rsa_meth_st RSA_METHOD; +typedef struct rsa_pss_params_st RSA_PSS_PARAMS; typedef struct ec_key_st EC_KEY; typedef struct ec_key_method_st EC_KEY_METHOD; diff --git a/include/openssl/rsa.h b/include/openssl/rsa.h index cdce1264eb..5e76365c0d 100644 --- a/include/openssl/rsa.h +++ b/include/openssl/rsa.h @@ -224,6 +224,7 @@ const BIGNUM *RSA_get0_q(const RSA *d); const BIGNUM *RSA_get0_dmp1(const RSA *r); const BIGNUM *RSA_get0_dmq1(const RSA *r); const BIGNUM *RSA_get0_iqmp(const RSA *r); +const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r); void RSA_clear_flags(RSA *r, int flags); int RSA_test_flags(const RSA *r, int flags); void RSA_set_flags(RSA *r, int flags); @@ -279,14 +280,14 @@ int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2); DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey) DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey) -typedef struct rsa_pss_params_st { +struct rsa_pss_params_st { X509_ALGOR *hashAlgorithm; X509_ALGOR *maskGenAlgorithm; ASN1_INTEGER *saltLength; ASN1_INTEGER *trailerField; /* Decoded hash algorithm from maskGenAlgorithm */ X509_ALGOR *maskHash; -} RSA_PSS_PARAMS; +}; DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS) diff --git a/util/libcrypto.num b/util/libcrypto.num index 1dde397bed..876b7ca710 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -4586,3 +4586,4 @@ EVP_PKEY_meth_set_digestsign 4539 1_1_1e EXIST::FUNCTION: EVP_PKEY_meth_set_digestverify 4540 1_1_1e EXIST::FUNCTION: EVP_PKEY_meth_get_digestverify 4541 1_1_1e EXIST::FUNCTION: EVP_PKEY_meth_get_digestsign 4542 1_1_1e EXIST::FUNCTION: +RSA_get0_pss_params 4543 1_1_1e EXIST::FUNCTION:RSA -- 2.25.1