@@ -217,3 +217,195 @@ int wolfSSL_StaticBufferSz(byte* buffer, word32 sz, int flag);
217217 \sa wolfSSL_Free
218218*/
219219int wolfSSL_MemoryPaddingSz (void );
220+
221+ /*!
222+ \ingroup Memory
223+
224+ \brief This function is used to set aside static memory for a CTX.
225+ Memory set aside is then used for the CTX’s lifetime and for any SSL objects created
226+ from the CTX. By passing in a NULL ctx pointer and a wolfSSL_method_func function the creation
227+ of the CTX itself will also use static memory. wolfSSL_method_func has the function signature
228+ of WOLFSSL_METHOD* (*wolfSSL_method_func)(void* heap);.
229+ Passing in 0 for max makes it behave as if not set and no max concurrent use restrictions
230+ is in place.
231+ The flag value passed in determines how the memory is used and behavior while operating.
232+ Available flags are the following.
233+
234+ 0 - default general memory
235+
236+ WOLFMEM_IO_POOL - used for input/output buffer when sending receiving messages.
237+ Overrides general memory, so all memory in buffer passed in is used for IO.
238+ WOLFMEM_IO_FIXED - same as WOLFMEM_IO_POOL but each SSL now keeps two
239+ buffers to themselves for their lifetime.
240+ WOLFMEM_TRACK_STATS - each SSL keeps track of memory stats while running.
241+
242+ \return If successful, SSL_SUCCESS will be returned.
243+ \return All unsuccessful return values will be less than 0 or equal to SSL_FAILURE.
244+
245+ \param ctx address of pointer to a WOLFSSL_CTX structure.
246+ \param method function to create protocol. (should be NULL if ctx is not also NULL)
247+ \param buf memory to use for all operations.
248+ \param sz size of memory buffer being passed in.
249+ \param flag type of memory.
250+ \param max max concurrent operations.
251+
252+ _Example_
253+ \code
254+ WOLFSSL_CTX* ctx;
255+ WOLFSSL* ssl;
256+ int ret;
257+ unsigned char memory[MAX];
258+ int memorySz = MAX;
259+ unsigned char IO[MAX];
260+ int IOSz = MAX;
261+ int flag = WOLFMEM_IO_FIXED | WOLFMEM_TRACK_STATS;
262+ ...
263+ // create ctx also using static memory, start with general memory to use
264+ ctx = NULL:
265+ ret = wolfSSL_CTX_load_static_memory(&ctx, wolfSSLv23_server_method_ex, memory, memorySz, 0,
266+ MAX_CONCURRENT_HANDSHAKES);
267+ if (ret != SSL_SUCCESS) {
268+ // handle error case
269+ }
270+ // load in memory for use with IO
271+ ret = wolfSSL_CTX_load_static_memory(&ctx, NULL, IO, IOSz, flag, MAX_CONCURRENT_IO);
272+ if (ret != SSL_SUCCESS) {
273+ // handle error case
274+ }
275+ ...
276+ \endcode
277+
278+ \sa wolfSSL_CTX_new
279+ \sa wolfSSL_CTX_is_static_memory
280+ \sa wolfSSL_is_static_memory
281+ */
282+ int wolfSSL_CTX_load_static_memory (WOLFSSL_CTX * * ctx , wolfSSL_method_func method ,
283+ unsigned char * buf , unsigned int sz , int flag , int max );
284+
285+ /*!
286+ \ingroup Memory
287+
288+ \brief This function does not change any of the connections behavior and is used only for
289+ gathering information about the static memory usage.
290+
291+ \return A value of 1 is returned if using static memory for the CTX is true.
292+ \return 0 is returned if not using static memory.
293+
294+ \param ctx a pointer to a WOLFSSL_CTX structure, created using wolfSSL_CTX_new().
295+ \param mem_stats structure to hold information about staic memory usage.
296+
297+ _Example_
298+ \code
299+ WOLFSSL_CTX* ctx;
300+ int ret;
301+ WOLFSSL_MEM_STATS mem_stats;
302+ ...
303+ //get information about static memory with CTX
304+
305+ ret = wolfSSL_CTX_is_static_memory(ctx, &mem_stats);
306+
307+ if (ret == 1) {
308+ // handle case of is using static memory
309+ // print out or inspect elements of mem_stats
310+ }
311+
312+ if (ret == 0) {
313+ //handle case of ctx not using static memory
314+ }
315+ ...
316+ \endcode
317+
318+ \sa wolfSSL_CTX_new
319+ \sa wolfSSL_CTX_load_static_memory
320+ \sa wolfSSL_is_static_memory
321+ */
322+ int wolfSSL_CTX_is_static_memory (WOLFSSL_CTX * ctx , WOLFSSL_MEM_STATS * mem_stats );
323+
324+ /*!
325+ \ingroup Memory
326+
327+ \brief wolfSSL_is_static_memory is used to gather information about a SSL’s static
328+ memory usage. The return value indicates if static memory is being used and
329+ WOLFSSL_MEM_CONN_STATS will be filled out if and only if the flag WOLFMEM_TRACK_STATS was
330+ passed to the parent CTX when loading in static memory.
331+
332+ \return A value of 1 is returned if using static memory for the CTX is true.
333+ \return 0 is returned if not using static memory.
334+
335+ \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
336+ \param mem_stats structure to contain static memory usage
337+
338+ _Example_
339+ \code
340+ WOLFSSL* ssl;
341+ int ret;
342+ WOLFSSL_MEM_CONN_STATS mem_stats;
343+
344+ ...
345+
346+ ret = wolfSSL_is_static_memory(ssl, mem_stats);
347+
348+ if (ret == 1) {
349+ // handle case when is static memory
350+ // investigate elements in mem_stats if WOLFMEM_TRACK_STATS flag
351+ }
352+ ...
353+ \endcode
354+
355+ \sa wolfSSL_new
356+ \sa wolfSSL_CTX_is_static_memory
357+ */
358+ int wolfSSL_is_static_memory (WOLFSSL * ssl , WOLFSSL_MEM_CONN_STATS * mem_stats );
359+
360+ /*!
361+ \ingroup Memory
362+
363+ \brief This function is used to set aside static memory for wolfCrypt use. Memory can be
364+ used by passing the created heap hint into functions. An example of this is when calling
365+ wc_InitRng_ex. The flag value passed in determines how the memory is used and behavior
366+ while operating, in general wolfCrypt operations will use memory from a WOLFMEM_GENERAL pool.
367+ Available flags are the following.
368+
369+ WOLFMEM_GENERAL - default general memory
370+
371+ WOLFMEM_IO_POOL - used for input/output buffer when sending receiving messages.
372+ Overrides general memory, so all memory in buffer passed in is used for IO.
373+ WOLFMEM_IO_FIXED - same as WOLFMEM_IO_POOL but each SSL now keeps two
374+ buffers to themselves for their lifetime.
375+ WOLFMEM_TRACK_STATS - each SSL keeps track of memory stats while running
376+
377+ \return If successful, 0 will be returned.
378+ \return All unsuccessful return values will be less than 0.
379+
380+ \param hint WOLFSSL_HEAP_HINT structure to use
381+ \param buf memory to use for all operations.
382+ \param sz size of memory buffer being passed in.
383+ \param flag type of memory.
384+ \param max max concurrent operations (handshakes, IO).
385+
386+ _Example_
387+ \code
388+ WOLFSSL_HEAP_HINT hint;
389+ int ret;
390+ unsigned char memory[MAX];
391+ int memorySz = MAX;
392+ int flag = WOLFMEM_GENERAL | WOLFMEM_TRACK_STATS;
393+ ...
394+
395+ // load in memory for use
396+
397+ ret = wc_LoadStaticMemory(&hint, memory, memorySz, flag, 0);
398+ if (ret != SSL_SUCCESS) {
399+ // handle error case
400+ }
401+ ...
402+
403+ ret = wc_InitRng_ex(&rng, hint, 0);
404+
405+ // check ret value
406+ \endcode
407+
408+ \sa none
409+ */
410+ int wc_LoadStaticMemory (WOLFSSL_HEAP_HINT * hint , unsigned char * buf , unsigned int sz ,
411+ int flag , int max );
0 commit comments