summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-11-07 15:45:41 +0000
committertb <>2023-11-07 15:45:41 +0000
commita708d2161971398e204c82107e26fd3f23f91219 (patch)
tree8630a80e4f9381fca62218bbba685db12b8545ae /src/lib
parentbddecb1f8da1b8bc67c5ad14fa7e638f4a64dff5 (diff)
downloadopenbsd-a708d2161971398e204c82107e26fd3f23f91219.tar.gz
openbsd-a708d2161971398e204c82107e26fd3f23f91219.tar.bz2
openbsd-a708d2161971398e204c82107e26fd3f23f91219.zip
Add a helper to set RSA PKCS #1 v1.5 padding OID
This removes a few duplicated and unchecked X509_ALGOR_set0() calls and factors them into a helper function that sets the AlgorithmIdentifier on the recipient info or signer info to rsaEncryption with null parameters. ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/rsa/rsa_ameth.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_ameth.c b/src/lib/libcrypto/rsa/rsa_ameth.c
index 43f52f749a..35adcb391e 100644
--- a/src/lib/libcrypto/rsa/rsa_ameth.c
+++ b/src/lib/libcrypto/rsa/rsa_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_ameth.c,v 1.34 2023/10/26 07:57:54 tb Exp $ */ 1/* $OpenBSD: rsa_ameth.c,v 1.35 2023/11/07 15:45:41 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -83,6 +83,8 @@ static int rsa_cms_encrypt(CMS_RecipientInfo *ri);
83 83
84static RSA_PSS_PARAMS *rsa_pss_decode(const X509_ALGOR *alg); 84static RSA_PSS_PARAMS *rsa_pss_decode(const X509_ALGOR *alg);
85 85
86static int rsa_alg_set_pkcs1_padding(X509_ALGOR *alg);
87
86/* Set any parameters associated with pkey */ 88/* Set any parameters associated with pkey */
87static int 89static int
88rsa_param_encode(const EVP_PKEY *pkey, ASN1_STRING **pstr, int *pstrtype) 90rsa_param_encode(const EVP_PKEY *pkey, ASN1_STRING **pstr, int *pstrtype)
@@ -568,9 +570,8 @@ rsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
568 return -2; 570 return -2;
569 } 571 }
570 572
571 if (alg) 573 if (alg != NULL)
572 X509_ALGOR_set0(alg, OBJ_nid2obj(NID_rsaEncryption), 574 return rsa_alg_set_pkcs1_padding(alg);
573 V_ASN1_NULL, 0);
574 575
575 return 1; 576 return 1;
576} 577}
@@ -887,6 +888,12 @@ rsa_item_verify(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
887 return -1; 888 return -1;
888} 889}
889 890
891static int
892rsa_alg_set_pkcs1_padding(X509_ALGOR *alg)
893{
894 return X509_ALGOR_set0_by_nid(alg, NID_rsaEncryption, V_ASN1_NULL, NULL);
895}
896
890#ifndef OPENSSL_NO_CMS 897#ifndef OPENSSL_NO_CMS
891static int 898static int
892rsa_cms_sign(CMS_SignerInfo *si) 899rsa_cms_sign(CMS_SignerInfo *si)
@@ -901,10 +908,8 @@ rsa_cms_sign(CMS_SignerInfo *si)
901 if (EVP_PKEY_CTX_get_rsa_padding(pkctx, &pad_mode) <= 0) 908 if (EVP_PKEY_CTX_get_rsa_padding(pkctx, &pad_mode) <= 0)
902 return 0; 909 return 0;
903 } 910 }
904 if (pad_mode == RSA_PKCS1_PADDING) { 911 if (pad_mode == RSA_PKCS1_PADDING)
905 X509_ALGOR_set0(alg, OBJ_nid2obj(NID_rsaEncryption), V_ASN1_NULL, 0); 912 return rsa_alg_set_pkcs1_padding(alg);
906 return 1;
907 }
908 /* We don't support it */ 913 /* We don't support it */
909 if (pad_mode != RSA_PKCS1_PSS_PADDING) 914 if (pad_mode != RSA_PKCS1_PSS_PADDING)
910 return 0; 915 return 0;
@@ -1067,10 +1072,8 @@ rsa_cms_encrypt(CMS_RecipientInfo *ri)
1067 if (EVP_PKEY_CTX_get_rsa_padding(pkctx, &pad_mode) <= 0) 1072 if (EVP_PKEY_CTX_get_rsa_padding(pkctx, &pad_mode) <= 0)
1068 return 0; 1073 return 0;
1069 } 1074 }
1070 if (pad_mode == RSA_PKCS1_PADDING) { 1075 if (pad_mode == RSA_PKCS1_PADDING)
1071 X509_ALGOR_set0(alg, OBJ_nid2obj(NID_rsaEncryption), V_ASN1_NULL, 0); 1076 return rsa_alg_set_pkcs1_padding(alg);
1072 return 1;
1073 }
1074 /* Not supported */ 1077 /* Not supported */
1075 if (pad_mode != RSA_PKCS1_OAEP_PADDING) 1078 if (pad_mode != RSA_PKCS1_OAEP_PADDING)
1076 return 0; 1079 return 0;