Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions benchmark/bench_modules/wh_bench_mod_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with wolfHSM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "wh_bench_mod.h"
#include "wolfhsm/wh_error.h"
#include "wolfhsm/wh_client.h"
Expand Down Expand Up @@ -384,10 +385,11 @@ int _benchRsaCrypt(whClientContext* client, whBenchOpContext* ctx, int id,
goto exit;
}

strcpy((char*)inBuf, inStr);
strncpy((char*)inBuf, inStr, sizeof(inBuf)-1);
inBuf[sizeof(inBuf)-1] = '\0';

/* Do an initial encryption to get the size of the output */
encSz = ret = wc_RsaPublicEncrypt(inBuf, sizeof(inStr), outBuf,
encSz = ret = wc_RsaPublicEncrypt(inBuf, strlen(inStr), outBuf,
sizeof(outBuf), rsa, rng);
if (ret < 0) {
WH_BENCH_PRINTF("Failed to wc_RsaPublicEncrypt %d\n", ret);
Expand All @@ -408,7 +410,7 @@ int _benchRsaCrypt(whClientContext* client, whBenchOpContext* ctx, int id,

if (operation == RSA_PUBLIC_ENCRYPT) {
benchStartRet = wh_Bench_StartOp(ctx, id);
opRet = wc_RsaPublicEncrypt(inBuf, sizeof(inStr), outBuf,
opRet = wc_RsaPublicEncrypt(inBuf, strlen(inStr), outBuf,
sizeof(outBuf), rsa, rng);
benchStopRet = wh_Bench_StopOp(ctx, id);
}
Expand Down
13 changes: 7 additions & 6 deletions benchmark/wh_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
/* Buffer sizes for transport */
/* Large enough to handle an RSA 4096 key */
#define BUFFER_SIZE \
sizeof(whTransportMemCsr) + sizeof(whCommHeader) + WOLFHSM_CFG_COMM_DATA_LEN
(sizeof(whTransportMemCsr) + sizeof(whCommHeader) + \
WOLFHSM_CFG_COMM_DATA_LEN)
#define FLASH_RAM_SIZE (1024 * 1024) /* 1MB */

typedef struct BenchModule {
Expand Down Expand Up @@ -826,14 +827,14 @@ static void _whBenchClientServerThreadTest(whClientConfig* c_conf,
rc = pthread_create(&cthread, NULL, _whBenchClientTask, &clientData);
if (rc == 0) {
/* Wait for client to finish, then cancel server */
pthread_join(cthread, &retval);
pthread_cancel(sthread);
pthread_join(sthread, &retval);
(void)pthread_join(cthread, &retval);
(void)pthread_cancel(sthread);
(void)pthread_join(sthread, &retval);
}
else {
/* If client thread creation failed, cancel server */
pthread_cancel(sthread);
pthread_join(sthread, &retval);
(void)pthread_cancel(sthread);
(void)pthread_join(sthread, &retval);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions benchmark/wh_bench_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,27 +346,27 @@ int wh_Bench_PrintResults(whBenchOpContext* ctx)

if (throughput < 1024.0) {
/* Bytes per second */
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f B/s",
throughput);
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f B/s",
throughput);
}
else if (throughput < 1024.0 * 1024.0) {
/* Kilobytes per second */
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f KB/s",
throughput / 1024.0);
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f KB/s",
throughput / 1024.0);
}
else {
/* Megabytes per second */
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f MB/s",
throughput / (1024.0 * 1024.0));
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f MB/s",
throughput / (1024.0 * 1024.0));
}
}
else if (ctx->ops[i].throughputType == BENCH_THROUGHPUT_OPS) {
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f ops/s",
ctx->ops[i].throughput);
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f ops/s",
ctx->ops[i].throughput);
}
else {
/* No throughput */
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "N/A");
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "N/A");
}
WH_BENCH_PRINTF("%-18s |\n", buffer);
}
Expand Down
12 changes: 8 additions & 4 deletions examples/demo/client/wh_demo_client_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ int wh_DemoClient_CryptoRsa(whClientContext* clientContext)
WC_RNG rng[1];

/* set the plainText to the test string */
strcpy((char*)plainText, plainString);
strncpy((char*)plainText, plainString, sizeof(plainText)-1);
plainText[sizeof(plainText)-1] = '\0';

/* initialize rng to make the rsa key */
ret = wc_InitRng_ex(rng, NULL, WH_DEV_ID);
Expand Down Expand Up @@ -144,7 +145,8 @@ int wh_DemoClient_CryptoRsaImport(whClientContext* clientContext)
WC_RNG rng[1];

/* set the plainText to the test string */
strcpy((char*)plainText, plainString);
strncpy((char*)plainText, plainString, sizeof(plainText)-1);
plainText[sizeof(plainText)-1] = '\0';

/* initialize rng to encrypt with the rsa key */
ret = wc_InitRng_ex(rng, NULL, WH_DEV_ID);
Expand Down Expand Up @@ -497,7 +499,8 @@ int wh_DemoClient_CryptoEcc(whClientContext* clientContext)
byte signature[128];

/* Set the message to the test string */
strcpy((char*)message, plainMessage);
strncpy((char*)message, plainMessage, sizeof(message)-1);
message[sizeof(message)-1] = '\0';

/* Initialize the rng to make the ecc keys */
ret = wc_InitRng_ex(rng, NULL, WH_DEV_ID);
Expand Down Expand Up @@ -627,7 +630,8 @@ int wh_DemoClient_CryptoEccImport(whClientContext* clientContext)
uint8_t keyBuf[256];

/* Set the message to the test string */
strcpy((char*)message, plainMessage);
strncpy((char*)message, plainMessage, sizeof(message)-1);
message[sizeof(message)-1] = '\0';

/* Initialize the rng for signature signing */
ret = wc_InitRng_ex(rng, NULL, WH_DEV_ID);
Expand Down
1 change: 1 addition & 0 deletions examples/posix/wh_posix_client/wh_posix_client_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ static unsigned int psk_tls12_client_cb(WOLFSSL* ssl, const char* hint,
printf("PSK server identity hint: %s\n", hint);
printf("PSK using identity: %s\n", exampleIdentity);
strncpy(identity, exampleIdentity, id_max_len);
identity[id_max_len-1] = '\0';

printf("Enter PSK password: ");
if (fgets((char*)key, key_max_len - 1, stdin) == NULL) {
Expand Down
8 changes: 4 additions & 4 deletions examples/posix/wh_posix_server/wh_posix_server_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ static void parseNvmInitFile(const char* filePath)
fclose(file);
exit(EXIT_FAILURE);
}
snprintf(label, sizeof(label), "%s", token);
(void)snprintf(label, sizeof(label), "%s", token);

/* Parse the file path */
token = strtok(NULL, " ");
Expand Down Expand Up @@ -508,9 +508,9 @@ static void processEntry(Entry* entry, int isKey, whNvmContext* nvmContext)
}

/* Get the file size */
fseek(file, 0, SEEK_END);
(void)fseek(file, 0, SEEK_END);
long fileSize = ftell(file);
fseek(file, 0, SEEK_SET);
(void)fseek(file, 0, SEEK_SET);

/* Allocate memory for the file data */
uint8_t* buffer = (uint8_t*)malloc(fileSize);
Expand Down Expand Up @@ -553,7 +553,7 @@ static void processEntry(Entry* entry, int isKey, whNvmContext* nvmContext)
meta.access = entry->access;
meta.flags = entry->flags;
meta.len = fileSize;
snprintf((char*)meta.label, WH_NVM_LABEL_LEN, "%s", entry->label);
(void)snprintf((char*)meta.label, WH_NVM_LABEL_LEN, "%s", entry->label);

int rc = wh_Nvm_AddObject(nvmContext, &meta, fileSize, buffer);
if (rc != 0) {
Expand Down
2 changes: 1 addition & 1 deletion port/posix/posix_flash_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum {
};

/** Local declarations */
#define MAX_OFFSET(_context) (_context->partition_size * 2)
#define MAX_OFFSET(_context) ((_context)->partition_size * 2)

/* Helper for pwrite like memset. Write the byte in c to filedes for size
* bytes starting at offset */
Expand Down
Loading
Loading