[git commit] tls: remove unnecessary malloc/free in psRsaDecryptPriv()

Denys Vlasenko vda.linux at googlemail.com
Sun Feb 15 14:16:26 UTC 2026


commit: https://git.busybox.net/busybox/commit/?id=2ab2c258479ef140ea59481fb493b113219201b9
branch: https://git.busybox.net/busybox/log/?h=master

function                                             old     new   delta
.rodata                                           108007  108023     +16
psRsaDecryptPriv                                     200     171     -29
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 16/-29)            Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/tls_rsa.c | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/networking/tls_rsa.c b/networking/tls_rsa.c
index 8a9c0c6db..cb1ff11b2 100644
--- a/networking/tls_rsa.c
+++ b/networking/tls_rsa.c
@@ -280,35 +280,23 @@ int32 FAST_FUNC psRsaDecryptPriv(psPool_t *pool, psRsaKey_t *key,
 						unsigned char *out, uint32 outlen, void *data)
 {
 	int32 err;
-	uint32 size, ptLen;
-	unsigned char *tmp;
+	uint32 ptLen;
 
-	size = key->size;
-	if (inlen != size) {
-		psTraceCrypto("psRsaDecryptPriv: input size mismatch\n");
+	if (inlen != key->size) {
+		psTraceCrypto("Error on bad inlen parameter to psRsaDecryptPriv\n");
 		return PS_ARG_FAIL;
 	}
-
-	/* Allocate temp buffer for decrypted padded data */
-	tmp = xmalloc(size);
-
-	/* Perform RSA decryption */
-	ptLen = size;
-	if ((err = psRsaCrypt(pool, in, inlen, tmp, &ptLen, key,
+	ptLen = inlen;
+	if ((err = psRsaCrypt(pool, in, inlen, in, &ptLen, key,
 			PRIVKEY_TYPE, data)) < PS_SUCCESS) {
 		psTraceCrypto("Error performing psRsaDecryptPriv\n");
-		free(tmp);
 		return err;
 	}
-
-	/* Remove PKCS#1 padding */
-	err = pkcs1Unpad(tmp, ptLen, out, outlen);
-	free(tmp);
-
-	if (err < 0) {
-		psTraceCrypto("Error unpadding in psRsaDecryptPriv\n");
+	if (ptLen != inlen) {
+		psTraceCrypto("Decrypted size error in psRsaDecryptPriv\n");
 		return PS_FAILURE;
 	}
-
-	return err;  /* Return length of unpadded message */
+	err = pkcs1Unpad(in, inlen, out, outlen);
+	memset(in, 0x0, inlen);
+	return err;
 }


More information about the busybox-cvs mailing list