Prohibit use of low level digest APIs in FIPS mode.

This commit is contained in:
Dr. Stephen Henson 2011-06-01 13:39:45 +00:00
parent 9ddc574f9a
commit 65300dcfb0
27 changed files with 99 additions and 12 deletions

View File

@ -4,6 +4,11 @@
Changes between 1.0.0d and 1.0.1 [xx XXX xxxx] Changes between 1.0.0d and 1.0.1 [xx XXX xxxx]
*) Low level digest APIs are not approved in FIPS mode: any attempt
to use these will cause a fatal error. Applications that *really* want
to use them can use the private_* version instead.
[Steve Henson]
*) Redirect cipher operations to FIPS module for FIPS builds. *) Redirect cipher operations to FIPS module for FIPS builds.
[Steve Henson] [Steve Henson]

View File

@ -552,6 +552,22 @@ int FIPS_mode_set(int r);
void OPENSSL_init(void); void OPENSSL_init(void);
#define fips_md_init(alg) fips_md_init_ctx(alg, alg)
#ifdef OPENSSL_FIPS
#define fips_md_init_ctx(alg, cx) \
int alg##_Init(cx##_CTX *c) \
{ \
if (FIPS_mode()) OpenSSLDie(__FILE__, __LINE__, \
"Low level API call to digest " #alg " forbidden in FIPS mode!"); \
return private_##alg##_Init(c); \
} \
int private_##alg##_Init(cx##_CTX *c)
#else
#define fips_md_init_ctx(alg, cx) \
int alg##_Init(cx##_CTX *c)
#endif
/* BEGIN ERROR CODES */ /* BEGIN ERROR CODES */
/* The following lines are auto generated by the script mkerr.pl. Any changes /* The following lines are auto generated by the script mkerr.pl. Any changes
* made after this point may be overwritten when the script is next run. * made after this point may be overwritten when the script is next run.

View File

@ -343,3 +343,18 @@ struct evp_pkey_method_st
} /* EVP_PKEY_METHOD */; } /* EVP_PKEY_METHOD */;
void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx); void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);
#ifdef OPENSSL_FIPS
#define RIPEMD160_Init private_RIPEMD160_Init
#define WHIRLPOOL_Init private_WHIRLPOOL_Init
#define MD5_Init private_MD5_Init
#define MD4_Init private_MD4_Init
#define MD2_Init private_MD2_Init
#define MDC2_Init private_MDC2_Init
#define SHA_Init private_SHA_Init
#define SHA1_Init private_SHA1_Init
#define SHA224_Init private_SHA224_Init
#define SHA256_Init private_SHA256_Init
#define SHA384_Init private_SHA384_Init
#define SHA512_Init private_SHA512_Init
#endif

View File

@ -69,6 +69,8 @@
#include <openssl/rsa.h> #include <openssl/rsa.h>
#endif #endif
#include "evp_locl.h"
static int init(EVP_MD_CTX *ctx) static int init(EVP_MD_CTX *ctx)
{ return MD4_Init(ctx->md_data); } { return MD4_Init(ctx->md_data); }

View File

@ -68,6 +68,7 @@
#ifndef OPENSSL_NO_RSA #ifndef OPENSSL_NO_RSA
#include <openssl/rsa.h> #include <openssl/rsa.h>
#endif #endif
#include "evp_locl.h"
static int init(EVP_MD_CTX *ctx) static int init(EVP_MD_CTX *ctx)
{ return MD5_Init(ctx->md_data); } { return MD5_Init(ctx->md_data); }

View File

@ -69,6 +69,8 @@
#include <openssl/rsa.h> #include <openssl/rsa.h>
#endif #endif
#include "evp_locl.h"
static int init(EVP_MD_CTX *ctx) static int init(EVP_MD_CTX *ctx)
{ return MDC2_Init(ctx->md_data); } { return MDC2_Init(ctx->md_data); }

View File

@ -68,6 +68,7 @@
#ifndef OPENSSL_NO_RSA #ifndef OPENSSL_NO_RSA
#include <openssl/rsa.h> #include <openssl/rsa.h>
#endif #endif
#include "evp_locl.h"
static int init(EVP_MD_CTX *ctx) static int init(EVP_MD_CTX *ctx)
{ return RIPEMD160_Init(ctx->md_data); } { return RIPEMD160_Init(ctx->md_data); }

View File

@ -67,6 +67,7 @@
#ifndef OPENSSL_NO_RSA #ifndef OPENSSL_NO_RSA
#include <openssl/rsa.h> #include <openssl/rsa.h>
#endif #endif
#include "evp_locl.h"
static int init(EVP_MD_CTX *ctx) static int init(EVP_MD_CTX *ctx)
{ return SHA_Init(ctx->md_data); } { return SHA_Init(ctx->md_data); }

View File

@ -9,6 +9,7 @@
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/whrlpool.h> #include <openssl/whrlpool.h>
#include "evp_locl.h"
static int init(EVP_MD_CTX *ctx) static int init(EVP_MD_CTX *ctx)
{ return WHIRLPOOL_Init(ctx->md_data); } { return WHIRLPOOL_Init(ctx->md_data); }

View File

@ -81,6 +81,9 @@ typedef struct MD2state_st
} MD2_CTX; } MD2_CTX;
const char *MD2_options(void); const char *MD2_options(void);
#ifdef OPENSSL_FIPS
int private_MD2_Init(MD2_CTX *c);
#endif
int MD2_Init(MD2_CTX *c); int MD2_Init(MD2_CTX *c);
int MD2_Update(MD2_CTX *c, const unsigned char *data, size_t len); int MD2_Update(MD2_CTX *c, const unsigned char *data, size_t len);
int MD2_Final(unsigned char *md, MD2_CTX *c); int MD2_Final(unsigned char *md, MD2_CTX *c);

View File

@ -116,7 +116,7 @@ const char *MD2_options(void)
return("md2(int)"); return("md2(int)");
} }
int MD2_Init(MD2_CTX *c) fips_md_init(MD2)
{ {
c->num=0; c->num=0;
memset(c->state,0,sizeof c->state); memset(c->state,0,sizeof c->state);

View File

@ -105,6 +105,9 @@ typedef struct MD4state_st
unsigned int num; unsigned int num;
} MD4_CTX; } MD4_CTX;
#ifdef OPENSSL_FIPS
int private_MD4_Init(MD4_CTX *c);
#endif
int MD4_Init(MD4_CTX *c); int MD4_Init(MD4_CTX *c);
int MD4_Update(MD4_CTX *c, const void *data, size_t len); int MD4_Update(MD4_CTX *c, const void *data, size_t len);
int MD4_Final(unsigned char *md, MD4_CTX *c); int MD4_Final(unsigned char *md, MD4_CTX *c);

View File

@ -57,8 +57,9 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include "md4_locl.h"
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
#include <openssl/crypto.h>
#include "md4_locl.h"
const char MD4_version[]="MD4" OPENSSL_VERSION_PTEXT; const char MD4_version[]="MD4" OPENSSL_VERSION_PTEXT;
@ -70,7 +71,7 @@ const char MD4_version[]="MD4" OPENSSL_VERSION_PTEXT;
#define INIT_DATA_C (unsigned long)0x98badcfeL #define INIT_DATA_C (unsigned long)0x98badcfeL
#define INIT_DATA_D (unsigned long)0x10325476L #define INIT_DATA_D (unsigned long)0x10325476L
int MD4_Init(MD4_CTX *c) fips_md_init(MD4)
{ {
memset (c,0,sizeof(*c)); memset (c,0,sizeof(*c));
c->A=INIT_DATA_A; c->A=INIT_DATA_A;

View File

@ -105,6 +105,9 @@ typedef struct MD5state_st
unsigned int num; unsigned int num;
} MD5_CTX; } MD5_CTX;
#ifdef OPENSSL_FIPS
int private_MD5_Init(MD5_CTX *c);
#endif
int MD5_Init(MD5_CTX *c); int MD5_Init(MD5_CTX *c);
int MD5_Update(MD5_CTX *c, const void *data, size_t len); int MD5_Update(MD5_CTX *c, const void *data, size_t len);
int MD5_Final(unsigned char *md, MD5_CTX *c); int MD5_Final(unsigned char *md, MD5_CTX *c);

View File

@ -59,6 +59,7 @@
#include <stdio.h> #include <stdio.h>
#include "md5_locl.h" #include "md5_locl.h"
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
#include <openssl/crypto.h>
const char MD5_version[]="MD5" OPENSSL_VERSION_PTEXT; const char MD5_version[]="MD5" OPENSSL_VERSION_PTEXT;
@ -70,7 +71,7 @@ const char MD5_version[]="MD5" OPENSSL_VERSION_PTEXT;
#define INIT_DATA_C (unsigned long)0x98badcfeL #define INIT_DATA_C (unsigned long)0x98badcfeL
#define INIT_DATA_D (unsigned long)0x10325476L #define INIT_DATA_D (unsigned long)0x10325476L
int MD5_Init(MD5_CTX *c) fips_md_init(MD5)
{ {
memset (c,0,sizeof(*c)); memset (c,0,sizeof(*c));
c->A=INIT_DATA_A; c->A=INIT_DATA_A;

View File

@ -81,6 +81,9 @@ typedef struct mdc2_ctx_st
} MDC2_CTX; } MDC2_CTX;
#ifdef OPENSSL_FIPS
int private_MDC2_Init(MDC2_CTX *c);
#endif
int MDC2_Init(MDC2_CTX *c); int MDC2_Init(MDC2_CTX *c);
int MDC2_Update(MDC2_CTX *c, const unsigned char *data, size_t len); int MDC2_Update(MDC2_CTX *c, const unsigned char *data, size_t len);
int MDC2_Final(unsigned char *md, MDC2_CTX *c); int MDC2_Final(unsigned char *md, MDC2_CTX *c);

View File

@ -61,6 +61,7 @@
#include <string.h> #include <string.h>
#include <openssl/des.h> #include <openssl/des.h>
#include <openssl/mdc2.h> #include <openssl/mdc2.h>
#include <openssl/crypto.h>
#undef c2l #undef c2l
#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ #define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
@ -75,7 +76,7 @@
*((c)++)=(unsigned char)(((l)>>24L)&0xff)) *((c)++)=(unsigned char)(((l)>>24L)&0xff))
static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len); static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len);
int MDC2_Init(MDC2_CTX *c) fips_md_init(MDC2)
{ {
c->num=0; c->num=0;
c->pad_type=1; c->pad_type=1;

View File

@ -91,6 +91,9 @@ typedef struct RIPEMD160state_st
unsigned int num; unsigned int num;
} RIPEMD160_CTX; } RIPEMD160_CTX;
#ifdef OPENSSL_FIPS
int private_RIPEMD160_Init(RIPEMD160_CTX *c);
#endif
int RIPEMD160_Init(RIPEMD160_CTX *c); int RIPEMD160_Init(RIPEMD160_CTX *c);
int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len); int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len);
int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);

View File

@ -59,6 +59,7 @@
#include <stdio.h> #include <stdio.h>
#include "rmd_locl.h" #include "rmd_locl.h"
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
#include <openssl/crypto.h>
const char RMD160_version[]="RIPE-MD160" OPENSSL_VERSION_PTEXT; const char RMD160_version[]="RIPE-MD160" OPENSSL_VERSION_PTEXT;
@ -69,7 +70,7 @@ const char RMD160_version[]="RIPE-MD160" OPENSSL_VERSION_PTEXT;
void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,size_t num); void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,size_t num);
# endif # endif
int RIPEMD160_Init(RIPEMD160_CTX *c) fips_md_init(RIPEMD160)
{ {
memset (c,0,sizeof(*c)); memset (c,0,sizeof(*c));
c->A=RIPEMD160_A; c->A=RIPEMD160_A;

View File

@ -106,6 +106,9 @@ typedef struct SHAstate_st
} SHA_CTX; } SHA_CTX;
#ifndef OPENSSL_NO_SHA0 #ifndef OPENSSL_NO_SHA0
#ifdef OPENSSL_FIPS
int private_SHA_Init(SHA_CTX *c);
#endif
int SHA_Init(SHA_CTX *c); int SHA_Init(SHA_CTX *c);
int SHA_Update(SHA_CTX *c, const void *data, size_t len); int SHA_Update(SHA_CTX *c, const void *data, size_t len);
int SHA_Final(unsigned char *md, SHA_CTX *c); int SHA_Final(unsigned char *md, SHA_CTX *c);
@ -113,6 +116,9 @@ unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md);
void SHA_Transform(SHA_CTX *c, const unsigned char *data); void SHA_Transform(SHA_CTX *c, const unsigned char *data);
#endif #endif
#ifndef OPENSSL_NO_SHA1 #ifndef OPENSSL_NO_SHA1
#ifdef OPENSSL_FIPS
int private_SHA1_Init(SHA_CTX *c);
#endif
int SHA1_Init(SHA_CTX *c); int SHA1_Init(SHA_CTX *c);
int SHA1_Update(SHA_CTX *c, const void *data, size_t len); int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
int SHA1_Final(unsigned char *md, SHA_CTX *c); int SHA1_Final(unsigned char *md, SHA_CTX *c);
@ -135,6 +141,10 @@ typedef struct SHA256state_st
} SHA256_CTX; } SHA256_CTX;
#ifndef OPENSSL_NO_SHA256 #ifndef OPENSSL_NO_SHA256
#ifdef OPENSSL_FIPS
int private_SHA224_Init(SHA256_CTX *c);
int private_SHA256_Init(SHA256_CTX *c);
#endif
int SHA224_Init(SHA256_CTX *c); int SHA224_Init(SHA256_CTX *c);
int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
int SHA224_Final(unsigned char *md, SHA256_CTX *c); int SHA224_Final(unsigned char *md, SHA256_CTX *c);
@ -182,6 +192,10 @@ typedef struct SHA512state_st
#endif #endif
#ifndef OPENSSL_NO_SHA512 #ifndef OPENSSL_NO_SHA512
#ifdef OPENSSL_FIPS
int private_SHA384_Init(SHA512_CTX *c);
int private_SHA512_Init(SHA512_CTX *c);
#endif
int SHA384_Init(SHA512_CTX *c); int SHA384_Init(SHA512_CTX *c);
int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
int SHA384_Final(unsigned char *md, SHA512_CTX *c); int SHA384_Final(unsigned char *md, SHA512_CTX *c);

View File

@ -57,6 +57,7 @@
*/ */
#include <openssl/opensslconf.h> #include <openssl/opensslconf.h>
#include <openssl/crypto.h>
#if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_NO_SHA) #if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_NO_SHA)
#undef SHA_0 #undef SHA_0

View File

@ -16,7 +16,7 @@
const char SHA256_version[]="SHA-256" OPENSSL_VERSION_PTEXT; const char SHA256_version[]="SHA-256" OPENSSL_VERSION_PTEXT;
int SHA224_Init (SHA256_CTX *c) fips_md_init_ctx(SHA224, SHA256)
{ {
memset (c,0,sizeof(*c)); memset (c,0,sizeof(*c));
c->h[0]=0xc1059ed8UL; c->h[1]=0x367cd507UL; c->h[0]=0xc1059ed8UL; c->h[1]=0x367cd507UL;
@ -27,7 +27,7 @@ int SHA224_Init (SHA256_CTX *c)
return 1; return 1;
} }
int SHA256_Init (SHA256_CTX *c) fips_md_init(SHA256)
{ {
memset (c,0,sizeof(*c)); memset (c,0,sizeof(*c));
c->h[0]=0x6a09e667UL; c->h[1]=0xbb67ae85UL; c->h[0]=0x6a09e667UL; c->h[1]=0xbb67ae85UL;

View File

@ -59,7 +59,7 @@ const char SHA512_version[]="SHA-512" OPENSSL_VERSION_PTEXT;
#define SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA #define SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA
#endif #endif
int SHA384_Init (SHA512_CTX *c) fips_md_init_ctx(SHA384, SHA512)
{ {
#if defined(SHA512_ASM) && (defined(__arm__) || defined(__arm)) #if defined(SHA512_ASM) && (defined(__arm__) || defined(__arm))
/* maintain dword order required by assembler module */ /* maintain dword order required by assembler module */
@ -88,7 +88,7 @@ int SHA384_Init (SHA512_CTX *c)
return 1; return 1;
} }
int SHA512_Init (SHA512_CTX *c) fips_md_init(SHA512)
{ {
#if defined(SHA512_ASM) && (defined(__arm__) || defined(__arm)) #if defined(SHA512_ASM) && (defined(__arm__) || defined(__arm))
/* maintain dword order required by assembler module */ /* maintain dword order required by assembler module */

View File

@ -57,6 +57,7 @@
*/ */
#include <openssl/opensslconf.h> #include <openssl/opensslconf.h>
#include <openssl/crypto.h>
#if !defined(OPENSSL_NO_SHA0) && !defined(OPENSSL_NO_SHA) #if !defined(OPENSSL_NO_SHA0) && !defined(OPENSSL_NO_SHA)
#undef SHA_1 #undef SHA_1

View File

@ -122,7 +122,11 @@ void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num);
#define INIT_DATA_h3 0x10325476UL #define INIT_DATA_h3 0x10325476UL
#define INIT_DATA_h4 0xc3d2e1f0UL #define INIT_DATA_h4 0xc3d2e1f0UL
int HASH_INIT (SHA_CTX *c) #ifdef SHA_0
fips_md_init(SHA)
#else
fips_md_init_ctx(SHA1, SHA)
#endif
{ {
memset (c,0,sizeof(*c)); memset (c,0,sizeof(*c));
c->h0=INIT_DATA_h0; c->h0=INIT_DATA_h0;

View File

@ -24,6 +24,9 @@ typedef struct {
} WHIRLPOOL_CTX; } WHIRLPOOL_CTX;
#ifndef OPENSSL_NO_WHIRLPOOL #ifndef OPENSSL_NO_WHIRLPOOL
#ifdef OPENSSL_FIPS
int private_WHIRLPOOL_Init(WHIRLPOOL_CTX *c);
#endif
int WHIRLPOOL_Init (WHIRLPOOL_CTX *c); int WHIRLPOOL_Init (WHIRLPOOL_CTX *c);
int WHIRLPOOL_Update (WHIRLPOOL_CTX *c,const void *inp,size_t bytes); int WHIRLPOOL_Update (WHIRLPOOL_CTX *c,const void *inp,size_t bytes);
void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *inp,size_t bits); void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *inp,size_t bits);

View File

@ -52,9 +52,10 @@
*/ */
#include "wp_locl.h" #include "wp_locl.h"
#include <openssl/crypto.h>
#include <string.h> #include <string.h>
int WHIRLPOOL_Init (WHIRLPOOL_CTX *c) fips_md_init(WHIRLPOOL)
{ {
memset (c,0,sizeof(*c)); memset (c,0,sizeof(*c));
return(1); return(1);