|
5 | 5 | #include "crypto/openssl/hash.h" |
6 | 6 | #include "crypto/openssl/rsa_key_pair.h" |
7 | 7 |
|
| 8 | +#include <climits> |
8 | 9 | #include <openssl/core_names.h> |
9 | 10 | #include <openssl/encoder.h> |
10 | 11 |
|
@@ -123,9 +124,9 @@ namespace ccf::crypto |
123 | 124 | { |
124 | 125 | Unique_EVP_PKEY_CTX ctx(key); |
125 | 126 | OpenSSL::CHECK1(EVP_PKEY_encrypt_init(ctx)); |
126 | | - EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING); |
127 | | - EVP_PKEY_CTX_set_rsa_oaep_md(ctx, EVP_sha256()); |
128 | | - EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, EVP_sha256()); |
| 127 | + CHECKPOSITIVE(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING)); |
| 128 | + CHECKPOSITIVE(EVP_PKEY_CTX_set_rsa_oaep_md(ctx, EVP_sha256())); |
| 129 | + CHECKPOSITIVE(EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, EVP_sha256())); |
129 | 130 |
|
130 | 131 | if (label != nullptr && label_size > 0) |
131 | 132 | { |
@@ -228,12 +229,17 @@ namespace ccf::crypto |
228 | 229 |
|
229 | 230 | Unique_EVP_PKEY_CTX pctx(key); |
230 | 231 | CHECK1(EVP_PKEY_verify_init(pctx)); |
231 | | - CHECK1(EVP_PKEY_CTX_set_rsa_padding(pctx, ossl_padding->second)); |
| 232 | + CHECKPOSITIVE(EVP_PKEY_CTX_set_rsa_padding(pctx, ossl_padding->second)); |
232 | 233 | if (ossl_padding->first == RSAPadding::PKCS_PSS) |
233 | 234 | { |
234 | | - CHECK1(EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, salt_length)); |
| 235 | + if (salt_length > INT_MAX) |
| 236 | + { |
| 237 | + throw std::invalid_argument(fmt::format( |
| 238 | + "salt_length {} exceeds maximum ({})", salt_length, INT_MAX)); |
| 239 | + } |
| 240 | + CHECKPOSITIVE(EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, salt_length)); |
235 | 241 | } |
236 | | - CHECK1(EVP_PKEY_CTX_set_signature_md(pctx, get_md_type(md_type))); |
| 242 | + CHECKPOSITIVE(EVP_PKEY_CTX_set_signature_md(pctx, get_md_type(md_type))); |
237 | 243 | return EVP_PKEY_verify(pctx, signature, signature_size, hash, hash_size) == |
238 | 244 | 1; |
239 | 245 | } |
|
0 commit comments