|
|
3da501 |
From 0879fac692cb1bff0ec4c196cb364d970ad3ecec Mon Sep 17 00:00:00 2001
|
|
|
3da501 |
From: Clemens Lang <cllang@redhat.com>
|
|
|
3da501 |
Date: Mon, 21 Nov 2022 14:33:57 +0100
|
|
|
3da501 |
Subject: [PATCH 2/3] Obtain PSS salt length from provider
|
|
|
3da501 |
|
|
|
3da501 |
Rather than computing the PSS salt length again in core using
|
|
|
3da501 |
ossl_rsa_ctx_to_pss_string, which calls rsa_ctx_to_pss and computes the
|
|
|
3da501 |
salt length, obtain it from the provider using the
|
|
|
3da501 |
OSSL_SIGNATURE_PARAM_ALGORITHM_ID param to handle the case where the
|
|
|
3da501 |
interpretation of the magic constants in the provider differs from that
|
|
|
3da501 |
of OpenSSL core.
|
|
|
3da501 |
|
|
|
3da501 |
Signed-off-by: Clemens Lang <cllang@redhat.com>
|
|
|
3da501 |
---
|
|
|
3da501 |
crypto/cms/cms_rsa.c | 19 +++++++++++++++----
|
|
|
3da501 |
crypto/rsa/rsa_ameth.c | 34 +++++++++++++++++++++-------------
|
|
|
3da501 |
2 files changed, 36 insertions(+), 17 deletions(-)
|
|
|
3da501 |
|
|
|
3da501 |
diff --git a/crypto/cms/cms_rsa.c b/crypto/cms/cms_rsa.c
|
|
|
3da501 |
index 20ed816918..997567fdbf 100644
|
|
|
3da501 |
--- a/crypto/cms/cms_rsa.c
|
|
|
3da501 |
+++ b/crypto/cms/cms_rsa.c
|
|
|
3da501 |
@@ -10,6 +10,7 @@
|
|
|
3da501 |
#include <assert.h>
|
|
|
3da501 |
#include <openssl/cms.h>
|
|
|
3da501 |
#include <openssl/err.h>
|
|
|
3da501 |
+#include <openssl/core_names.h>
|
|
|
3da501 |
#include "crypto/asn1.h"
|
|
|
3da501 |
#include "crypto/rsa.h"
|
|
|
3da501 |
#include "cms_local.h"
|
|
|
3da501 |
@@ -191,7 +192,10 @@ static int rsa_cms_sign(CMS_SignerInfo *si)
|
|
|
3da501 |
int pad_mode = RSA_PKCS1_PADDING;
|
|
|
3da501 |
X509_ALGOR *alg;
|
|
|
3da501 |
EVP_PKEY_CTX *pkctx = CMS_SignerInfo_get0_pkey_ctx(si);
|
|
|
3da501 |
- ASN1_STRING *os = NULL;
|
|
|
3da501 |
+ unsigned char aid[128];
|
|
|
3da501 |
+ const unsigned char *pp = aid;
|
|
|
3da501 |
+ size_t aid_len = 0;
|
|
|
3da501 |
+ OSSL_PARAM params[2];
|
|
|
3da501 |
|
|
|
3da501 |
CMS_SignerInfo_get0_algs(si, NULL, NULL, NULL, &alg;;
|
|
|
3da501 |
if (pkctx != NULL) {
|
|
|
3da501 |
@@ -205,10 +209,17 @@ static int rsa_cms_sign(CMS_SignerInfo *si)
|
|
|
3da501 |
/* We don't support it */
|
|
|
3da501 |
if (pad_mode != RSA_PKCS1_PSS_PADDING)
|
|
|
3da501 |
return 0;
|
|
|
3da501 |
- os = ossl_rsa_ctx_to_pss_string(pkctx);
|
|
|
3da501 |
- if (os == NULL)
|
|
|
3da501 |
+
|
|
|
3da501 |
+ params[0] = OSSL_PARAM_construct_octet_string(
|
|
|
3da501 |
+ OSSL_SIGNATURE_PARAM_ALGORITHM_ID, aid, sizeof(aid));
|
|
|
3da501 |
+ params[1] = OSSL_PARAM_construct_end();
|
|
|
3da501 |
+
|
|
|
3da501 |
+ if (EVP_PKEY_CTX_get_params(pkctx, params) <= 0)
|
|
|
3da501 |
+ return 0;
|
|
|
3da501 |
+ if ((aid_len = params[0].return_size) == 0)
|
|
|
3da501 |
+ return 0;
|
|
|
3da501 |
+ if (d2i_X509_ALGOR(&alg, &pp, aid_len) == NULL)
|
|
|
3da501 |
return 0;
|
|
|
3da501 |
- X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_PKEY_RSA_PSS), V_ASN1_SEQUENCE, os);
|
|
|
3da501 |
return 1;
|
|
|
3da501 |
}
|
|
|
3da501 |
|
|
|
3da501 |
diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c
|
|
|
3da501 |
index c15554505b..61ec53d424 100644
|
|
|
3da501 |
--- a/crypto/rsa/rsa_ameth.c
|
|
|
3da501 |
+++ b/crypto/rsa/rsa_ameth.c
|
|
|
3da501 |
@@ -637,22 +637,30 @@ static int rsa_item_sign(EVP_MD_CTX *ctx, const ASN1_ITEM *it, const void *asn,
|
|
|
3da501 |
if (pad_mode == RSA_PKCS1_PADDING)
|
|
|
3da501 |
return 2;
|
|
|
3da501 |
if (pad_mode == RSA_PKCS1_PSS_PADDING) {
|
|
|
3da501 |
- ASN1_STRING *os1 = NULL;
|
|
|
3da501 |
- os1 = ossl_rsa_ctx_to_pss_string(pkctx);
|
|
|
3da501 |
- if (!os1)
|
|
|
3da501 |
+ unsigned char aid[128];
|
|
|
3da501 |
+ size_t aid_len = 0;
|
|
|
3da501 |
+ OSSL_PARAM params[2];
|
|
|
3da501 |
+
|
|
|
3da501 |
+ params[0] = OSSL_PARAM_construct_octet_string(
|
|
|
3da501 |
+ OSSL_SIGNATURE_PARAM_ALGORITHM_ID, aid, sizeof(aid));
|
|
|
3da501 |
+ params[1] = OSSL_PARAM_construct_end();
|
|
|
3da501 |
+
|
|
|
3da501 |
+ if (EVP_PKEY_CTX_get_params(pkctx, params) <= 0)
|
|
|
3da501 |
return 0;
|
|
|
3da501 |
- /* Duplicate parameters if we have to */
|
|
|
3da501 |
- if (alg2) {
|
|
|
3da501 |
- ASN1_STRING *os2 = ASN1_STRING_dup(os1);
|
|
|
3da501 |
- if (!os2) {
|
|
|
3da501 |
- ASN1_STRING_free(os1);
|
|
|
3da501 |
+ if ((aid_len = params[0].return_size) == 0)
|
|
|
3da501 |
+ return 0;
|
|
|
3da501 |
+
|
|
|
3da501 |
+ if (alg1 != NULL) {
|
|
|
3da501 |
+ const unsigned char *pp = aid;
|
|
|
3da501 |
+ if (d2i_X509_ALGOR(&alg1, &pp, aid_len) == NULL)
|
|
|
3da501 |
+ return 0;
|
|
|
3da501 |
+ }
|
|
|
3da501 |
+ if (alg2 != NULL) {
|
|
|
3da501 |
+ const unsigned char *pp = aid;
|
|
|
3da501 |
+ if (d2i_X509_ALGOR(&alg2, &pp, aid_len) == NULL)
|
|
|
3da501 |
return 0;
|
|
|
3da501 |
- }
|
|
|
3da501 |
- X509_ALGOR_set0(alg2, OBJ_nid2obj(EVP_PKEY_RSA_PSS),
|
|
|
3da501 |
- V_ASN1_SEQUENCE, os2);
|
|
|
3da501 |
}
|
|
|
3da501 |
- X509_ALGOR_set0(alg1, OBJ_nid2obj(EVP_PKEY_RSA_PSS),
|
|
|
3da501 |
- V_ASN1_SEQUENCE, os1);
|
|
|
3da501 |
+
|
|
|
3da501 |
return 3;
|
|
|
3da501 |
}
|
|
|
3da501 |
return 2;
|
|
|
3da501 |
--
|
|
|
3da501 |
2.38.1
|
|
|
3da501 |
|