From e298fbf19a9c17b9d8ca5dea40ef1ae1ec8f3a48 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 21 Mar 2025 18:31:11 +0000 Subject: [PATCH] Address PR comments for RSA encrypt/decrypt example Co-Authored-By: colton@wolfssl.com --- pkcs11/pkcs11_rsa.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkcs11/pkcs11_rsa.c b/pkcs11/pkcs11_rsa.c index 92953704..de9a16b0 100644 --- a/pkcs11/pkcs11_rsa.c +++ b/pkcs11/pkcs11_rsa.c @@ -320,19 +320,24 @@ static int rsa_sign_verify_pss(int devId) return ret; } #endif /* ifdef WC_RSA_PSS */ -#endif /* ifndef NO_RSA */ + +/* Define maximum RSA key size in bits */ +#define MAX_RSA_KEY_BITS 2048 + +#ifndef NO_RSA static int rsa_encrypt_decrypt(int devId) { int ret = 0; - byte plain[128], out[2048/8], dec[2048/8]; + byte plain[128], out[MAX_RSA_KEY_BITS/8], dec[MAX_RSA_KEY_BITS/8]; word32 plainSz, outSz, decSz; RsaKey pub; RsaKey priv; + /* Initialize plain text buffer with 9's as sample data */ memset(plain, 9, sizeof(plain)); - plainSz = sizeof(plain); - outSz = sizeof(out); - decSz = sizeof(dec); + plainSz = (word32)sizeof(plain); + outSz = (word32)sizeof(out); + decSz = (word32)sizeof(dec); /* Encrypt with public key */ ret = decode_public_key(&pub, devId); @@ -397,7 +402,7 @@ static int rsa_encrypt_decrypt(int devId) return ret; } - +#endif /* ifndef NO_RSA */ int main(int argc, char* argv[]) {