• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

TLS/SSL and crypto library


Commit MetaInfo

Revision03b7b4690c772a1f92f57969e08ff4ac1fb7570d (tree)
Time2007-08-19 21:49:07
AuthorDr. Stephen Henson <steve@open...>
CommiterDr. Stephen Henson

Log Message

Cleaner check of self test status.

Change Summary

Incremental Difference

--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -120,9 +120,6 @@
120120
121121 void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
122122 {
123-#ifdef OPENSSL_FIPS
124- FIPS_selftest_check();
125-#endif
126123 memset(ctx,'\0',sizeof *ctx);
127124 }
128125
@@ -265,6 +262,14 @@ static int do_evp_md_engine(EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl)
265262 int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
266263 {
267264 M_EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
265+#ifdef OPENSSL_FIPS
266+ if(FIPS_selftest_failed())
267+ {
268+ FIPSerr(FIPS_F_EVP_DIGESTINIT_EX,FIPS_R_FIPS_SELFTEST_FAILED);
269+ ctx->digest = &bad_md;
270+ return 0;
271+ }
272+#endif
268273 #ifndef OPENSSL_NO_ENGINE
269274 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
270275 * so this context may already have an ENGINE! Try to avoid releasing
@@ -305,6 +310,9 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
305310 int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
306311 size_t count)
307312 {
313+#ifdef OPENSSL_FIPS
314+ FIPS_selftest_check();
315+#endif
308316 return ctx->digest->update(ctx,data,count);
309317 }
310318
@@ -321,6 +329,9 @@ int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
321329 int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
322330 {
323331 int ret;
332+#ifdef OPENSSL_FIPS
333+ FIPS_selftest_check();
334+#endif
324335
325336 OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE);
326337 ret=ctx->digest->final(ctx,md);
--- a/crypto/evp/enc_min.c
+++ b/crypto/evp/enc_min.c
@@ -199,6 +199,14 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp
199199 enc = 1;
200200 ctx->encrypt = enc;
201201 }
202+#ifdef OPENSSL_NO_FIPS
203+ if(FIPS_selftest_failed())
204+ {
205+ FIPSerr(FIPS_F_EVP_CIPHERINIT_EX,FIPS_R_FIPS_SELFTEST_FAILED);
206+ ctx->cipher = &bad_cipher;
207+ return 0;
208+ }
209+#endif
202210 #ifndef OPENSSL_NO_ENGINE
203211 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
204212 * so this context may already have an ENGINE! Try to avoid releasing
@@ -339,6 +347,9 @@ int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
339347
340348 int EVP_Cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl)
341349 {
350+#ifdef OPENSSL_FIPS
351+ FIPS_selftest_check();
352+#endif
342353 return ctx->cipher->do_cipher(ctx,out,in,inl);
343354 }
344355
--- a/crypto/evp/evp_enc.c
+++ b/crypto/evp/evp_enc.c
@@ -66,6 +66,14 @@
6666 #endif
6767 #include "evp_locl.h"
6868
69+#ifdef OPENSSL_FIPS
70+ #define M_do_cipher(ctx, out, in, inl) \
71+ EVP_Cipher(ctx,out,in,inl)
72+#else
73+ #define M_do_cipher(ctx, out, in, inl) \
74+ ctx->cipher->do_cipher(ctx,out,in,inl)
75+#endif
76+
6977 const char EVP_version[]="EVP" OPENSSL_VERSION_PTEXT;
7078
7179 EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
@@ -138,7 +146,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
138146 OPENSSL_assert(inl > 0);
139147 if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0)
140148 {
141- if(ctx->cipher->do_cipher(ctx,out,in,inl))
149+ if(M_do_cipher(ctx,out,in,inl))
142150 {
143151 *outl=inl;
144152 return 1;
@@ -165,7 +173,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
165173 {
166174 j=bl-i;
167175 memcpy(&(ctx->buf[i]),in,j);
168- if(!ctx->cipher->do_cipher(ctx,out,ctx->buf,bl)) return 0;
176+ if(!M_do_cipher(ctx,out,ctx->buf,bl)) return 0;
169177 inl-=j;
170178 in+=j;
171179 out+=bl;
@@ -178,7 +186,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
178186 inl-=i;
179187 if (inl > 0)
180188 {
181- if(!ctx->cipher->do_cipher(ctx,out,in,inl)) return 0;
189+ if(!M_do_cipher(ctx,out,in,inl)) return 0;
182190 *outl+=inl;
183191 }
184192
@@ -222,7 +230,7 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
222230 n=b-bl;
223231 for (i=bl; i<b; i++)
224232 ctx->buf[i]=n;
225- ret=ctx->cipher->do_cipher(ctx,out,ctx->buf,b);
233+ ret=M_do_cipher(ctx,out,ctx->buf,b);
226234
227235
228236 if(ret)
--- a/crypto/fips_err.h
+++ b/crypto/fips_err.h
@@ -74,6 +74,8 @@ static ERR_STRING_DATA FIPS_str_functs[]=
7474 {ERR_FUNC(FIPS_F_DSA_BUILTIN_PARAMGEN), "DSA_BUILTIN_PARAMGEN"},
7575 {ERR_FUNC(FIPS_F_DSA_DO_SIGN), "DSA_do_sign"},
7676 {ERR_FUNC(FIPS_F_DSA_DO_VERIFY), "DSA_do_verify"},
77+{ERR_FUNC(FIPS_F_EVP_CIPHERINIT_EX), "EVP_CipherInit_ex"},
78+{ERR_FUNC(FIPS_F_EVP_DIGESTINIT_EX), "EVP_DigestInit_ex"},
7779 {ERR_FUNC(FIPS_F_FIPS_CHECK_DSA), "FIPS_CHECK_DSA"},
7880 {ERR_FUNC(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT), "FIPS_CHECK_INCORE_FINGERPRINT"},
7981 {ERR_FUNC(FIPS_F_FIPS_CHECK_RSA), "FIPS_CHECK_RSA"},
--- a/fips/fips.h
+++ b/fips/fips.h
@@ -107,6 +107,8 @@ void ERR_load_FIPS_strings(void);
107107 #define FIPS_F_DSA_BUILTIN_PARAMGEN 101
108108 #define FIPS_F_DSA_DO_SIGN 102
109109 #define FIPS_F_DSA_DO_VERIFY 103
110+#define FIPS_F_EVP_CIPHERINIT_EX 124
111+#define FIPS_F_EVP_DIGESTINIT_EX 125
110112 #define FIPS_F_FIPS_CHECK_DSA 104
111113 #define FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT 105
112114 #define FIPS_F_FIPS_CHECK_RSA 106