Skip to content

Commit e298fbf

Browse files
Address PR comments for RSA encrypt/decrypt example
Co-Authored-By: colton@wolfssl.com <colton@wolfssl.com>
1 parent 0d3766d commit e298fbf

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

pkcs11/pkcs11_rsa.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,19 +320,24 @@ static int rsa_sign_verify_pss(int devId)
320320
return ret;
321321
}
322322
#endif /* ifdef WC_RSA_PSS */
323-
#endif /* ifndef NO_RSA */
323+
324+
/* Define maximum RSA key size in bits */
325+
#define MAX_RSA_KEY_BITS 2048
326+
327+
#ifndef NO_RSA
324328
static int rsa_encrypt_decrypt(int devId)
325329
{
326330
int ret = 0;
327-
byte plain[128], out[2048/8], dec[2048/8];
331+
byte plain[128], out[MAX_RSA_KEY_BITS/8], dec[MAX_RSA_KEY_BITS/8];
328332
word32 plainSz, outSz, decSz;
329333
RsaKey pub;
330334
RsaKey priv;
331335

336+
/* Initialize plain text buffer with 9's as sample data */
332337
memset(plain, 9, sizeof(plain));
333-
plainSz = sizeof(plain);
334-
outSz = sizeof(out);
335-
decSz = sizeof(dec);
338+
plainSz = (word32)sizeof(plain);
339+
outSz = (word32)sizeof(out);
340+
decSz = (word32)sizeof(dec);
336341

337342
/* Encrypt with public key */
338343
ret = decode_public_key(&pub, devId);
@@ -397,7 +402,7 @@ static int rsa_encrypt_decrypt(int devId)
397402

398403
return ret;
399404
}
400-
405+
#endif /* ifndef NO_RSA */
401406

402407
int main(int argc, char* argv[])
403408
{

0 commit comments

Comments
 (0)