Allow FIPS malloc callback setting. Automatically set some callbacks
[openssl.git] / fips / utl / fips_mem.c
index d8f197b..ff6e727 100644 (file)
@@ -51,6 +51,8 @@
  * ====================================================================
  */
 
+#define OPENSSL_FIPSAPI
+
 #include <openssl/err.h>
 #include <openssl/fips.h>
 
@@ -70,7 +72,7 @@ static void fips_free_def(void *x)
 
 static void *(*fips_malloc_cb)(int num, const char *file, int line) =
                fips_malloc_def;
-void (*fips_free_cb)(void *) =
+static void (*fips_free_cb)(void *) =
                fips_free_def;
 
 void *FIPS_malloc(int num, const char *file, int line)
@@ -82,3 +84,11 @@ void FIPS_free(void *x)
        {
        fips_free_cb(x);
        }
+
+void FIPS_set_malloc_callbacks(
+               void *(*malloc_cb)(int num, const char *file, int line),
+               void (*free_cb)(void *))
+       {
+       fips_malloc_cb = malloc_cb;
+       fips_free_cb = free_cb;
+       }