update example to handle larger inputs

pull/429/head
JacobBarthelmeh 2024-03-22 02:40:11 +07:00
parent 5238018ba7
commit f0e18b6c4c
1 changed files with 10 additions and 10 deletions

View File

@ -101,11 +101,11 @@ static int load_certs(byte* cert, word32* certSz, byte* key, word32* keySz)
} }
static int envelopedData_encrypt(byte* cert, word32 certSz, byte* key, static size_t envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
word32 keySz, byte* out, word32 outSz, word32 keySz, byte* out, word32 outSz,
word32 contentSz, byte useStreamMode) word32 contentSz, byte useStreamMode)
{ {
int ret; size_t ret;
PKCS7* pkcs7; PKCS7* pkcs7;
pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID); pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
@ -125,7 +125,7 @@ static int envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
/* add recipient using RSA certificate (KTRI type) */ /* add recipient using RSA certificate (KTRI type) */
ret = wc_PKCS7_AddRecipient_KTRI(pkcs7, cert, certSz, 0); ret = wc_PKCS7_AddRecipient_KTRI(pkcs7, cert, certSz, 0);
if (ret < 0) { if (ret < 0) {
printf("wc_PKCS7_AddRecipient_KTRI() failed, ret = %d\n", ret); printf("wc_PKCS7_AddRecipient_KTRI() failed, ret = %zu\n", ret);
wc_PKCS7_Free(pkcs7); wc_PKCS7_Free(pkcs7);
return -1; return -1;
} }
@ -133,7 +133,7 @@ static int envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
/* encode envelopedData, returns size */ /* encode envelopedData, returns size */
ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz); ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz);
if (ret <= 0) { if (ret <= 0) {
printf("ERROR: wc_PKCS7_EncodeEnvelopedData() failed, ret = %d\n", ret); printf("ERROR: wc_PKCS7_EncodeEnvelopedData() failed, ret = %zu\n", ret);
wc_PKCS7_Free(pkcs7); wc_PKCS7_Free(pkcs7);
return -1; return -1;
@ -147,11 +147,11 @@ static int envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
return ret; return ret;
} }
static int envelopedData_decrypt(byte* in, word32 inSz, byte* cert, static size_t envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
word32 certSz, byte* key, word32 keySz, word32 certSz, byte* key, word32 keySz,
byte* out, word32 outSz) byte* out, word32 outSz)
{ {
int ret; size_t ret;
PKCS7* pkcs7; PKCS7* pkcs7;
pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID); pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
@ -175,7 +175,7 @@ static int envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
/* decode envelopedData, returns size */ /* decode envelopedData, returns size */
ret = wc_PKCS7_DecodeEnvelopedData(pkcs7, in, inSz, out, outSz); ret = wc_PKCS7_DecodeEnvelopedData(pkcs7, in, inSz, out, outSz);
if (ret <= 0) { if (ret <= 0) {
printf("Failed to decode EnvelopedData bundle (%s), error %d\n", printf("Failed to decode EnvelopedData bundle (%s), error %zu\n",
encodedFileKTRI, ret); encodedFileKTRI, ret);
wc_PKCS7_Free(pkcs7); wc_PKCS7_Free(pkcs7);
return -1; return -1;
@ -197,7 +197,7 @@ static int envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int ret = 0; int ret = 0;
int encryptedSz = 0, decryptedSz; size_t encryptedSz = 0, decryptedSz;
word32 certSz, keySz, contentSz = 0; word32 certSz, keySz, contentSz = 0;
byte cert[DEFAULT_EXAMPLE_BUFFER_SIZE]; byte cert[DEFAULT_EXAMPLE_BUFFER_SIZE];
@ -242,7 +242,7 @@ int main(int argc, char** argv)
fseek(testIO.fileIn, 0, SEEK_END); fseek(testIO.fileIn, 0, SEEK_END);
contentSz = ftell(testIO.fileIn); contentSz = ftell(testIO.fileIn);
fseek(testIO.fileIn, 0, SEEK_SET); fseek(testIO.fileIn, 0, SEEK_SET);
printf("contentSz = %d\n", contentSz); printf("contentSz = %u\n", contentSz);
certSz = sizeof(cert); certSz = sizeof(cert);
keySz = sizeof(key); keySz = sizeof(key);
@ -279,7 +279,7 @@ int main(int argc, char** argv)
printf("error reading file %s\n", encodedFileKTRI); printf("error reading file %s\n", encodedFileKTRI);
ret = -1; ret = -1;
} }
printf("Read %d bytes for encrypted file found\n", encryptedSz); printf("Read %ld bytes for encrypted file found\n", encryptedSz);
} }
if (ret == 0) { if (ret == 0) {