aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssl/providers/implementations/asymciphers/rsa_enc.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssl/providers/implementations/asymciphers/rsa_enc.c')
-rw-r--r--crypto/openssl/providers/implementations/asymciphers/rsa_enc.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/crypto/openssl/providers/implementations/asymciphers/rsa_enc.c b/crypto/openssl/providers/implementations/asymciphers/rsa_enc.c
index 6ee127caff80..e6b676d0f8fa 100644
--- a/crypto/openssl/providers/implementations/asymciphers/rsa_enc.c
+++ b/crypto/openssl/providers/implementations/asymciphers/rsa_enc.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2025 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -151,6 +151,7 @@ static int rsa_encrypt(void *vprsactx, unsigned char *out, size_t *outlen,
size_t outsize, const unsigned char *in, size_t inlen)
{
PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
+ size_t len = RSA_size(prsactx->rsa);
int ret;
if (!ossl_prov_is_running())
@@ -168,17 +169,21 @@ static int rsa_encrypt(void *vprsactx, unsigned char *out, size_t *outlen,
}
#endif
- if (out == NULL) {
- size_t len = RSA_size(prsactx->rsa);
+ if (len == 0) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY);
+ return 0;
+ }
- if (len == 0) {
- ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY);
- return 0;
- }
+ if (out == NULL) {
*outlen = len;
return 1;
}
+ if (outsize < len) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
+ return 0;
+ }
+
if (prsactx->pad_mode == RSA_PKCS1_OAEP_PADDING) {
int rsasize = RSA_size(prsactx->rsa);
unsigned char *tbuf;