Redirect FIPS memory allocation to FIPS_malloc() routine, remove OpenSSL malloc dependencies.
diff --git a/fips/dh/fips_dh_lib.c b/fips/dh/fips_dh_lib.c index 4a822cf..747d949 100644 --- a/fips/dh/fips_dh_lib.c +++ b/fips/dh/fips_dh_lib.c
@@ -56,9 +56,12 @@ * */ +#define OPENSSL_FIPSAPI + #include <string.h> #include <openssl/bn.h> #include <openssl/dh.h> +#include <openssl/fips.h> /* Minimal FIPS versions of FIPS_dh_new() and FIPS_dh_free(): to * reduce external dependencies.
diff --git a/fips/dsa/fips_dsa_lib.c b/fips/dsa/fips_dsa_lib.c index 2545966..06f8cab 100644 --- a/fips/dsa/fips_dsa_lib.c +++ b/fips/dsa/fips_dsa_lib.c
@@ -56,9 +56,12 @@ * */ +#define OPENSSL_FIPSAPI + #include <string.h> #include <openssl/dsa.h> #include <openssl/bn.h> +#include <openssl/fips.h> /* Minimal FIPS versions of FIPS_dsa_new() and FIPS_dsa_free: to * reduce external dependencies.
diff --git a/fips/fips.h b/fips/fips.h index 2ef955a..5452db9 100644 --- a/fips/fips.h +++ b/fips/fips.h
@@ -113,8 +113,13 @@ void FIPS_set_locking_callback (void (*func)(int mode, int type, const char *file,int line)); +void *FIPS_malloc(int num, const char *file, int line); +void FIPS_free(void *); + #if defined(OPENSSL_FIPSCANISTER) && defined(OPENSSL_FIPSAPI) #define CRYPTO_lock FIPS_lock +#define CRYPTO_malloc FIPS_malloc +#define CRYPTO_free FIPS_free #endif /* BEGIN ERROR CODES */
diff --git a/fips/fips_utl.h b/fips/fips_utl.h index b3162d6..76ae4f8 100644 --- a/fips/fips_utl.h +++ b/fips/fips_utl.h
@@ -47,6 +47,9 @@ * */ +#define OPENSSL_FIPSAPI +#include <openssl/fips.h> + int hex2bin(const char *in, unsigned char *out); unsigned char *hex2bin_m(const char *in, long *plen); int do_hex2bn(BIGNUM **pr, const char *in);
diff --git a/fips/hmac/fips_hmactest.c b/fips/hmac/fips_hmactest.c index 575f652..8c51fe5 100644 --- a/fips/hmac/fips_hmactest.c +++ b/fips/hmac/fips_hmactest.c
@@ -77,7 +77,6 @@ #else -#include <openssl/fips.h> #include "fips_utl.h" static int hmac_test(const EVP_MD *md, FILE *out, FILE *in);
diff --git a/fips/rand/fips_randtest.c b/fips/rand/fips_randtest.c index 88fb860..31c51d3 100644 --- a/fips/rand/fips_randtest.c +++ b/fips/rand/fips_randtest.c
@@ -123,6 +123,8 @@ #else +#define OPENSSL_FIPSAPI + #include <openssl/fips.h> #include "fips_utl.h"
diff --git a/fips/rsa/fips_rsa_lib.c b/fips/rsa/fips_rsa_lib.c index a37ad3e..77c0cb8 100644 --- a/fips/rsa/fips_rsa_lib.c +++ b/fips/rsa/fips_rsa_lib.c
@@ -56,11 +56,14 @@ * */ +#define OPENSSL_FIPSAPI + #include <string.h> #include <openssl/evp.h> #include <openssl/rsa.h> #include <openssl/bn.h> #include <openssl/err.h> +#include <openssl/fips.h> /* Minimal FIPS versions of FIPS_rsa_new() and FIPS_rsa_free: to * reduce external dependencies. @@ -95,7 +98,6 @@ if (r->iqmp != NULL) BN_clear_free(r->iqmp); if (r->blinding != NULL) BN_BLINDING_free(r->blinding); if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_blinding); - if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data); OPENSSL_free(r); }
diff --git a/fips/rsa/fips_rsa_sign.c b/fips/rsa/fips_rsa_sign.c index d07111b..4e5b4bf 100644 --- a/fips/rsa/fips_rsa_sign.c +++ b/fips/rsa/fips_rsa_sign.c
@@ -63,6 +63,7 @@ #include <openssl/rsa.h> #include <openssl/err.h> #include <openssl/sha.h> +#include <openssl/fips.h> #ifdef OPENSSL_FIPS
diff --git a/fips/utl/Makefile b/fips/utl/Makefile index 577578e..8542b32 100644 --- a/fips/utl/Makefile +++ b/fips/utl/Makefile
@@ -22,8 +22,8 @@ APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= fips_err.c fips_md.c fips_enc.c fips_lck.c -LIBOBJ= fips_err.o fips_md.o fips_enc.o fips_lck.o +LIBSRC= fips_err.c fips_md.c fips_enc.c fips_lck.c fips_mem.c +LIBOBJ= fips_err.o fips_md.o fips_enc.o fips_lck.o fips_mem.o SRC= $(LIBSRC)
diff --git a/fips/utl/fips_enc.c b/fips/utl/fips_enc.c index 23ba5dd..93647a0 100644 --- a/fips/utl/fips_enc.c +++ b/fips/utl/fips_enc.c
@@ -56,11 +56,13 @@ * [including the GNU Public Licence.] */ +#define OPENSSL_FIPSAPI + #include <stdio.h> #include <string.h> #include <openssl/evp.h> #include <openssl/err.h> -#include <openssl/rand.h> +#include <openssl/fips.h> void FIPS_cipher_ctx_init(EVP_CIPHER_CTX *ctx) {
diff --git a/fips/utl/fips_md.c b/fips/utl/fips_md.c index 6e33e84..0038646 100644 --- a/fips/utl/fips_md.c +++ b/fips/utl/fips_md.c
@@ -111,11 +111,14 @@ /* Minimal standalone FIPS versions of Digest operations */ +#define OPENSSL_FIPSAPI + #include <stdio.h> #include <string.h> #include <openssl/objects.h> #include <openssl/evp.h> #include <openssl/err.h> +#include <openssl/fips.h> void FIPS_md_ctx_init(EVP_MD_CTX *ctx) {