From d7303664b513f6b7bcb4c3f2276a10fe9c6297c4 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Thu, 19 Sep 2024 15:54:20 +0200 Subject: [PATCH] memmem is only being used in testing so move it there --- tests/api.c | 8 ++++---- wolfcrypt/src/wc_port.c | 19 ------------------- wolfssl/test.h | 19 +++++++++++++++++++ wolfssl/wolfcrypt/types.h | 1 - wolfssl/wolfcrypt/wc_port.h | 2 -- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/tests/api.c b/tests/api.c index 4df1c32ba5..c9d586420d 100644 --- a/tests/api.c +++ b/tests/api.c @@ -94147,10 +94147,10 @@ static int test_dtls13_basic_connection_id(void) size_t i; /* We check if the side included the CID in their output */ -#define CLIENT_CID() XMEMMEM(test_ctx.s_buff, test_ctx.s_len, \ - client_cid, sizeof(client_cid)) -#define SERVER_CID() XMEMMEM(test_ctx.c_buff, test_ctx.c_len, \ - server_cid, sizeof(server_cid)) +#define CLIENT_CID() mymemmem(test_ctx.s_buff, test_ctx.s_len, \ + client_cid, sizeof(client_cid)) +#define SERVER_CID() mymemmem(test_ctx.c_buff, test_ctx.c_len, \ + server_cid, sizeof(server_cid)) printf("\n"); for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) { diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 31773a2df0..a2e1dcdfed 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -3397,25 +3397,6 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n) } #endif -void *mymemmem(const void *haystack, size_t haystacklen, - const void *needle, size_t needlelen) -{ - size_t i, j; - const char* h = (const char*)haystack; - const char* n = (const char*)needle; - if (needlelen > haystacklen) - return NULL; - for (i = 0; i <= haystacklen - needlelen; i++) { - for (j = 0; j < needlelen; j++) { - if (h[i + j] != n[j]) - break; - } - if (j == needlelen) - return (void*)(h + i); - } - return NULL; -} - /* custom memory wrappers */ #ifdef WOLFSSL_NUCLEUS_1_2 diff --git a/wolfssl/test.h b/wolfssl/test.h index 27d29065da..60327d53a6 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -4853,4 +4853,23 @@ void DEBUG_WRITE_DER(const byte* der, int derSz, const char* fileName); #define DTLS_CID_BUFFER_SIZE 256 +static WC_MAYBE_UNUSED void *mymemmem(const void *haystack, size_t haystacklen, + const void *needle, size_t needlelen) +{ + size_t i, j; + const char* h = (const char*)haystack; + const char* n = (const char*)needle; + if (needlelen > haystacklen) + return NULL; + for (i = 0; i <= haystacklen - needlelen; i++) { + for (j = 0; j < needlelen; j++) { + if (h[i + j] != n[j]) + break; + } + if (j == needlelen) + return (void*)(h + i); + } + return NULL; +} + #endif /* wolfSSL_TEST_H */ diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index e7edbc5b36..6784ee6a27 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -730,7 +730,6 @@ typedef struct w64wrapper { #define XMEMSET(b,c,l) memset((b),(c),(l)) #define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n)) #define XMEMMOVE(d,s,l) memmove((d),(s),(l)) - #define XMEMMEM(h,hl,n,nl) mymemmem((h),(hl),(n),(nl)) #define XSTRLEN(s1) strlen((s1)) #define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n)) diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index cb36bfe7d2..ceb408d7a6 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -1214,8 +1214,6 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void); #ifndef WOLFSSL_LEANPSK char* mystrnstr(const char* s1, const char* s2, unsigned int n); #endif - WOLFSSL_API void *mymemmem(const void *haystack, size_t haystacklen, - const void *needle, size_t needlelen); #ifndef FILE_BUFFER_SIZE /* default static file buffer size for input, will use dynamic buffer if