Redirect FIPS memory allocation to FIPS_malloc() routine, remove

OpenSSL malloc dependencies.
This commit is contained in:
Dr. Stephen Henson 2011-01-27 17:23:43 +00:00
parent e36d6b8f79
commit 7cc684f4f7
23 changed files with 80 additions and 6 deletions

View File

@ -313,7 +313,6 @@ FIPS_EX_OBJ= ../crypto/aes/aes_cfb.o \
../crypto/evp/e_des3.o \ ../crypto/evp/e_des3.o \
../crypto/evp/m_sha1.o \ ../crypto/evp/m_sha1.o \
../crypto/hmac/hmac.o \ ../crypto/hmac/hmac.o \
../crypto/mem.o \
../crypto/modes/cfb128.o \ ../crypto/modes/cfb128.o \
../crypto/modes/ctr128.o \ ../crypto/modes/ctr128.o \
../crypto/modes/ofb128.o \ ../crypto/modes/ofb128.o \

View File

@ -113,6 +113,12 @@
#include "cryptlib.h" #include "cryptlib.h"
#include "bn_lcl.h" #include "bn_lcl.h"
#define OPENSSL_FIPSAPI
#ifdef OPENSSL_FIPS
#include <openssl/fips.h>
#endif
#define BN_BLINDING_COUNTER 32 #define BN_BLINDING_COUNTER 32
struct bn_blinding_st struct bn_blinding_st

View File

@ -60,12 +60,18 @@
#endif #endif
#endif #endif
#define OPENSSL_FIPSAPI
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include "cryptlib.h" #include "cryptlib.h"
#include "bn_lcl.h" #include "bn_lcl.h"
#ifdef OPENSSL_FIPS
#include <openssl/fips.h>
#endif
/* TODO list /* TODO list
* *
* 1. Check a bunch of "(words+1)" type hacks in various bignum functions and * 1. Check a bunch of "(words+1)" type hacks in various bignum functions and

View File

@ -113,6 +113,11 @@
#include "cryptlib.h" #include "cryptlib.h"
#include "bn_lcl.h" #include "bn_lcl.h"
#define OPENSSL_FIPSAPI
#ifdef OPENSSL_FIPS
#include <openssl/fips.h>
#endif
/* maximum precomputation table size for *variable* sliding windows */ /* maximum precomputation table size for *variable* sliding windows */
#define TABLE_SIZE 32 #define TABLE_SIZE 32

View File

@ -67,6 +67,11 @@
#include "cryptlib.h" #include "cryptlib.h"
#include "bn_lcl.h" #include "bn_lcl.h"
#define OPENSSL_FIPSAPI
#ifdef OPENSSL_FIPS
#include <openssl/fips.h>
#endif
const char BN_version[]="Big Number" OPENSSL_VERSION_PTEXT; const char BN_version[]="Big Number" OPENSSL_VERSION_PTEXT;
/* This stuff appears to be completely unused, so is deprecated */ /* This stuff appears to be completely unused, so is deprecated */

View File

@ -115,6 +115,11 @@
#include "bn_lcl.h" #include "bn_lcl.h"
#include <openssl/rand.h> #include <openssl/rand.h>
#define OPENSSL_FIPSAPI
#ifdef OPENSSL_FIPS
#include <openssl/fips.h>
#endif
static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom) static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
{ {
unsigned char *buf=NULL; unsigned char *buf=NULL;

View File

@ -60,6 +60,11 @@
#include "cryptlib.h" #include "cryptlib.h"
#include "bn_lcl.h" #include "bn_lcl.h"
#define OPENSSL_FIPSAPI
#ifdef OPENSSL_FIPS
#include <openssl/fips.h>
#endif
void BN_RECP_CTX_init(BN_RECP_CTX *recp) void BN_RECP_CTX_init(BN_RECP_CTX *recp)
{ {
BN_init(&(recp->N)); BN_init(&(recp->N));

View File

@ -60,6 +60,11 @@
#include "cryptlib.h" #include "cryptlib.h"
#include <openssl/buffer.h> #include <openssl/buffer.h>
#define OPENSSL_FIPSAPI
#ifdef OPENSSL_FIPS
#include <openssl/fips.h>
#endif
char *BUF_strdup(const char *str) char *BUF_strdup(const char *str)
{ {
if (str == NULL) return(NULL); if (str == NULL) return(NULL);

View File

@ -63,6 +63,11 @@
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#define OPENSSL_FIPSAPI
#ifdef OPENSSL_FIPS
#include <openssl/fips.h>
#endif
DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
{ {
return dsa->meth->dsa_do_sign(dgst, dlen, dsa); return dsa->meth->dsa_do_sign(dgst, dlen, dsa);

View File

@ -70,6 +70,8 @@
#ifdef OPENSSL_FIPS #ifdef OPENSSL_FIPS
#define OPENSSL_FIPSAPI
#include <openssl/fips.h> #include <openssl/fips.h>
#include <openssl/evp.h> #include <openssl/evp.h>

View File

@ -30,6 +30,10 @@
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/sha.h> #include <openssl/sha.h>
#ifdef OPENSSL_FIPS
#include <openssl/fips.h>
#endif
static int MGF1(unsigned char *mask, long len, static int MGF1(unsigned char *mask, long len,
const unsigned char *seed, long seedlen); const unsigned char *seed, long seedlen);

View File

@ -67,6 +67,10 @@
#include <openssl/sha.h> #include <openssl/sha.h>
#include "rsa_locl.h" #include "rsa_locl.h"
#ifdef OPENSSL_FIPS
#include <openssl/fips.h>
#endif
static const unsigned char zeroes[] = {0,0,0,0,0,0,0,0}; static const unsigned char zeroes[] = {0,0,0,0,0,0,0,0};
#if defined(_MSC_VER) && defined(_ARM_) #if defined(_MSC_VER) && defined(_ARM_)

View File

@ -56,9 +56,12 @@
* *
*/ */
#define OPENSSL_FIPSAPI
#include <string.h> #include <string.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/dh.h> #include <openssl/dh.h>
#include <openssl/fips.h>
/* Minimal FIPS versions of FIPS_dh_new() and FIPS_dh_free(): to /* Minimal FIPS versions of FIPS_dh_new() and FIPS_dh_free(): to
* reduce external dependencies. * reduce external dependencies.

View File

@ -56,9 +56,12 @@
* *
*/ */
#define OPENSSL_FIPSAPI
#include <string.h> #include <string.h>
#include <openssl/dsa.h> #include <openssl/dsa.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/fips.h>
/* Minimal FIPS versions of FIPS_dsa_new() and FIPS_dsa_free: to /* Minimal FIPS versions of FIPS_dsa_new() and FIPS_dsa_free: to
* reduce external dependencies. * reduce external dependencies.

View File

@ -113,8 +113,13 @@ void FIPS_lock(int mode, int type,const char *file,int line);
void FIPS_set_locking_callback (void (*func)(int mode, int type, void FIPS_set_locking_callback (void (*func)(int mode, int type,
const char *file,int line)); 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) #if defined(OPENSSL_FIPSCANISTER) && defined(OPENSSL_FIPSAPI)
#define CRYPTO_lock FIPS_lock #define CRYPTO_lock FIPS_lock
#define CRYPTO_malloc FIPS_malloc
#define CRYPTO_free FIPS_free
#endif #endif
/* BEGIN ERROR CODES */ /* BEGIN ERROR CODES */

View File

@ -47,6 +47,9 @@
* *
*/ */
#define OPENSSL_FIPSAPI
#include <openssl/fips.h>
int hex2bin(const char *in, unsigned char *out); int hex2bin(const char *in, unsigned char *out);
unsigned char *hex2bin_m(const char *in, long *plen); unsigned char *hex2bin_m(const char *in, long *plen);
int do_hex2bn(BIGNUM **pr, const char *in); int do_hex2bn(BIGNUM **pr, const char *in);

View File

@ -77,7 +77,6 @@ int main(int argc, char *argv[])
#else #else
#include <openssl/fips.h>
#include "fips_utl.h" #include "fips_utl.h"
static int hmac_test(const EVP_MD *md, FILE *out, FILE *in); static int hmac_test(const EVP_MD *md, FILE *out, FILE *in);

View File

@ -123,6 +123,8 @@ int main(int argc, char *argv[])
#else #else
#define OPENSSL_FIPSAPI
#include <openssl/fips.h> #include <openssl/fips.h>
#include "fips_utl.h" #include "fips_utl.h"

View File

@ -56,11 +56,14 @@
* *
*/ */
#define OPENSSL_FIPSAPI
#include <string.h> #include <string.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/fips.h>
/* Minimal FIPS versions of FIPS_rsa_new() and FIPS_rsa_free: to /* Minimal FIPS versions of FIPS_rsa_new() and FIPS_rsa_free: to
* reduce external dependencies. * reduce external dependencies.
@ -95,7 +98,6 @@ void FIPS_rsa_free(RSA *r)
if (r->iqmp != NULL) BN_clear_free(r->iqmp); if (r->iqmp != NULL) BN_clear_free(r->iqmp);
if (r->blinding != NULL) BN_BLINDING_free(r->blinding); if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_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); OPENSSL_free(r);
} }

View File

@ -63,6 +63,7 @@
#include <openssl/rsa.h> #include <openssl/rsa.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/sha.h> #include <openssl/sha.h>
#include <openssl/fips.h>
#ifdef OPENSSL_FIPS #ifdef OPENSSL_FIPS

View File

@ -22,8 +22,8 @@ TEST=
APPS= APPS=
LIB=$(TOP)/libcrypto.a LIB=$(TOP)/libcrypto.a
LIBSRC= fips_err.c fips_md.c fips_enc.c fips_lck.c 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 LIBOBJ= fips_err.o fips_md.o fips_enc.o fips_lck.o fips_mem.o
SRC= $(LIBSRC) SRC= $(LIBSRC)

View File

@ -56,11 +56,13 @@
* [including the GNU Public Licence.] * [including the GNU Public Licence.]
*/ */
#define OPENSSL_FIPSAPI
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/rand.h> #include <openssl/fips.h>
void FIPS_cipher_ctx_init(EVP_CIPHER_CTX *ctx) void FIPS_cipher_ctx_init(EVP_CIPHER_CTX *ctx)
{ {

View File

@ -111,11 +111,14 @@
/* Minimal standalone FIPS versions of Digest operations */ /* Minimal standalone FIPS versions of Digest operations */
#define OPENSSL_FIPSAPI
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/fips.h>
void FIPS_md_ctx_init(EVP_MD_CTX *ctx) void FIPS_md_ctx_init(EVP_MD_CTX *ctx)
{ {