Skip to content

Commit 9ca32e2

Browse files
committed
linuxkm/linuxkm-fips-hash.c: cosmetic bikeshedding (AI-prompted);
linuxkm/linuxkm_memory.c and linuxkm/linuxkm_memory.h: set up and use WOLFSSL_TEXT_SEGMENT_CANONICALIZER_BUFSIZ.
1 parent 10ba02f commit 9ca32e2

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

linuxkm/linuxkm-fips-hash.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,7 @@ extern const char coreKey[FIPS_IN_CORE_KEY_SZ*2 + 1];
6262
#endif
6363

6464
static int hmac_setkey_cb(Hmac *hmac, const byte *key, word32 key_len) {
65-
int ret;
66-
67-
ret = wc_HmacSetKey(hmac, FIPS_IN_CORE_HASH_TYPE, key, key_len);
68-
if (ret != 0)
69-
return ret;
70-
return 0;
65+
return wc_HmacSetKey(hmac, FIPS_IN_CORE_HASH_TYPE, key, key_len);
7166
}
7267

7368
static int hmac_update_cb(Hmac *hmac, const byte *in, word32 in_len) {
@@ -89,7 +84,7 @@ int main(int argc, char **argv)
8984
int ret;
9085
struct wc_reloc_table_segments seg_map = WC_RELOC_TABLE_SEGMENTS_INITIALIZER;
9186
word32 new_verifyCore_size = FIPS_IN_CORE_DIGEST_SIZE*2 + 1;
92-
char new_verifyCore[new_verifyCore_size];
87+
char new_verifyCore[FIPS_IN_CORE_DIGEST_SIZE*2 + 1];
9388
const char *progname = strchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0];
9489
const char *mod_path = NULL;
9590
const char *user_coreKey = NULL;
@@ -134,13 +129,6 @@ int main(int argc, char **argv)
134129
{ }
135130
};
136131

137-
ret = wolfCrypt_Init();
138-
if (ret < 0) {
139-
fprintf(stderr, "%s: wolfCrypt_Init() failed: %s.\n",
140-
progname, wc_GetErrorString(ret));
141-
exit(1);
142-
}
143-
144132
for (;;) {
145133
int option_index = 0;
146134
int c = getopt_long(argc, argv, "f:ik:qvh", long_options, &option_index);
@@ -292,7 +280,8 @@ int main(int argc, char **argv)
292280

293281
mod_map = (byte *)mmap(NULL, st.st_size,
294282
inplace ? PROT_READ | PROT_WRITE : PROT_READ,
295-
MAP_SHARED | MAP_POPULATE, mod_fd, 0);
283+
(inplace ? MAP_SHARED : MAP_PRIVATE) | MAP_POPULATE,
284+
mod_fd, 0);
296285
if (mod_map == MAP_FAILED) {
297286
fprintf(stderr, "%s: mmap() of %s, length %zu: %m.\n",
298287
progname, mod_path, st.st_size);
@@ -323,6 +312,13 @@ int main(int argc, char **argv)
323312
seg_map.bss_start += (unsigned long)mod_map;
324313
seg_map.bss_end += (unsigned long)mod_map;
325314

315+
ret = wolfCrypt_Init();
316+
if (ret < 0) {
317+
fprintf(stderr, "%s: wolfCrypt_Init() failed: %s.\n",
318+
progname, wc_GetErrorString(ret));
319+
exit(1);
320+
}
321+
326322
ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
327323
if (ret != 0) {
328324
fprintf(stderr, "%s: wc_HmacInit() failed: %s.\n",

linuxkm/linuxkm_memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ int wc_fips_generate_hash(
730730
{
731731
ssize_t cur_reloc_index = -1;
732732
const byte *text_p = (const byte *)seg_map->fips_text_start;
733-
byte *buf = XMALLOC(8192, NULL, DYNAMIC_TYPE_TMP_BUFFER);
733+
byte *buf = XMALLOC(WOLFSSL_TEXT_SEGMENT_CANONICALIZER_BUFSIZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
734734

735735
if (! buf) {
736736
ret = MEMORY_E;
@@ -744,7 +744,7 @@ int wc_fips_generate_hash(
744744
*/
745745
ssize_t progress = wc_reloc_normalize_text(
746746
text_p,
747-
min(8192, (word32)((const byte *)seg_map->fips_text_end - text_p)),
747+
min(WOLFSSL_TEXT_SEGMENT_CANONICALIZER_BUFSIZ, (word32)((const byte *)seg_map->fips_text_end - text_p)),
748748
buf,
749749
&cur_reloc_index,
750750
seg_map,

linuxkm/linuxkm_memory.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ struct wc_reloc_counts {
200200

201201
#if defined(WC_SYM_RELOC_TABLES) || defined(WC_SYM_RELOC_TABLES_SUPPORT)
202202

203+
#ifndef WOLFSSL_TEXT_SEGMENT_CANONICALIZER_BUFSIZ
204+
#define WOLFSSL_TEXT_SEGMENT_CANONICALIZER_BUFSIZ 8192
205+
#endif
206+
203207
WOLFSSL_API ssize_t wc_reloc_normalize_text(
204208
const byte *text_in,
205209
size_t text_in_len,

0 commit comments

Comments
 (0)