diff options
| author | djm <> | 2008-09-06 12:15:56 +0000 |
|---|---|---|
| committer | djm <> | 2008-09-06 12:15:56 +0000 |
| commit | 5a3c0a05c7f2c5d3c584b7c8d6aec836dd724c80 (patch) | |
| tree | aba68249883aa9d2361d92eef69a81d0c4961732 /src/lib/libcrypto/rand | |
| parent | f6198d4d0ab97685dc56be2d48715ed39fcc74b9 (diff) | |
| download | openbsd-5a3c0a05c7f2c5d3c584b7c8d6aec836dd724c80.tar.gz openbsd-5a3c0a05c7f2c5d3c584b7c8d6aec836dd724c80.tar.bz2 openbsd-5a3c0a05c7f2c5d3c584b7c8d6aec836dd724c80.zip | |
import of OpenSSL 0.9.8h
Diffstat (limited to 'src/lib/libcrypto/rand')
| -rw-r--r-- | src/lib/libcrypto/rand/rand.h | 15 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/rand_err.c | 15 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/rand_lib.c | 18 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/randfile.c | 12 |
4 files changed, 17 insertions, 43 deletions
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h index 604df9be6c..ac6c021763 100644 --- a/src/lib/libcrypto/rand/rand.h +++ b/src/lib/libcrypto/rand/rand.h | |||
| @@ -72,10 +72,13 @@ extern "C" { | |||
| 72 | #endif | 72 | #endif |
| 73 | 73 | ||
| 74 | #if defined(OPENSSL_FIPS) | 74 | #if defined(OPENSSL_FIPS) |
| 75 | #define FIPS_RAND_SIZE_T int | 75 | #define FIPS_RAND_SIZE_T size_t |
| 76 | #endif | 76 | #endif |
| 77 | 77 | ||
| 78 | typedef struct rand_meth_st | 78 | /* Already defined in ossl_typ.h */ |
| 79 | /* typedef struct rand_meth_st RAND_METHOD; */ | ||
| 80 | |||
| 81 | struct rand_meth_st | ||
| 79 | { | 82 | { |
| 80 | void (*seed)(const void *buf, int num); | 83 | void (*seed)(const void *buf, int num); |
| 81 | int (*bytes)(unsigned char *buf, int num); | 84 | int (*bytes)(unsigned char *buf, int num); |
| @@ -83,7 +86,7 @@ typedef struct rand_meth_st | |||
| 83 | void (*add)(const void *buf, int num, double entropy); | 86 | void (*add)(const void *buf, int num, double entropy); |
| 84 | int (*pseudorand)(unsigned char *buf, int num); | 87 | int (*pseudorand)(unsigned char *buf, int num); |
| 85 | int (*status)(void); | 88 | int (*status)(void); |
| 86 | } RAND_METHOD; | 89 | }; |
| 87 | 90 | ||
| 88 | #ifdef BN_DEBUG | 91 | #ifdef BN_DEBUG |
| 89 | extern int rand_predictable; | 92 | extern int rand_predictable; |
| @@ -125,17 +128,11 @@ void ERR_load_RAND_strings(void); | |||
| 125 | /* Error codes for the RAND functions. */ | 128 | /* Error codes for the RAND functions. */ |
| 126 | 129 | ||
| 127 | /* Function codes. */ | 130 | /* Function codes. */ |
| 128 | #define RAND_F_FIPS_RAND_BYTES 102 | ||
| 129 | #define RAND_F_RAND_GET_RAND_METHOD 101 | 131 | #define RAND_F_RAND_GET_RAND_METHOD 101 |
| 130 | #define RAND_F_SSLEAY_RAND_BYTES 100 | 132 | #define RAND_F_SSLEAY_RAND_BYTES 100 |
| 131 | 133 | ||
| 132 | /* Reason codes. */ | 134 | /* Reason codes. */ |
| 133 | #define RAND_R_NON_FIPS_METHOD 101 | ||
| 134 | #define RAND_R_PRNG_ASKING_FOR_TOO_MUCH 105 | ||
| 135 | #define RAND_R_PRNG_NOT_REKEYED 103 | ||
| 136 | #define RAND_R_PRNG_NOT_RESEEDED 104 | ||
| 137 | #define RAND_R_PRNG_NOT_SEEDED 100 | 135 | #define RAND_R_PRNG_NOT_SEEDED 100 |
| 138 | #define RAND_R_PRNG_STUCK 102 | ||
| 139 | 136 | ||
| 140 | #ifdef __cplusplus | 137 | #ifdef __cplusplus |
| 141 | } | 138 | } |
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c index 97f96e1aee..386934dcd1 100644 --- a/src/lib/libcrypto/rand/rand_err.c +++ b/src/lib/libcrypto/rand/rand_err.c | |||
| @@ -70,7 +70,6 @@ | |||
| 70 | 70 | ||
| 71 | static ERR_STRING_DATA RAND_str_functs[]= | 71 | static ERR_STRING_DATA RAND_str_functs[]= |
| 72 | { | 72 | { |
| 73 | {ERR_FUNC(RAND_F_FIPS_RAND_BYTES), "FIPS_RAND_BYTES"}, | ||
| 74 | {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, | 73 | {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, |
| 75 | {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, | 74 | {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, |
| 76 | {0,NULL} | 75 | {0,NULL} |
| @@ -78,12 +77,7 @@ static ERR_STRING_DATA RAND_str_functs[]= | |||
| 78 | 77 | ||
| 79 | static ERR_STRING_DATA RAND_str_reasons[]= | 78 | static ERR_STRING_DATA RAND_str_reasons[]= |
| 80 | { | 79 | { |
| 81 | {ERR_REASON(RAND_R_NON_FIPS_METHOD) ,"non fips method"}, | ||
| 82 | {ERR_REASON(RAND_R_PRNG_ASKING_FOR_TOO_MUCH),"prng asking for too much"}, | ||
| 83 | {ERR_REASON(RAND_R_PRNG_NOT_REKEYED) ,"prng not rekeyed"}, | ||
| 84 | {ERR_REASON(RAND_R_PRNG_NOT_RESEEDED) ,"prng not reseeded"}, | ||
| 85 | {ERR_REASON(RAND_R_PRNG_NOT_SEEDED) ,"PRNG not seeded"}, | 80 | {ERR_REASON(RAND_R_PRNG_NOT_SEEDED) ,"PRNG not seeded"}, |
| 86 | {ERR_REASON(RAND_R_PRNG_STUCK) ,"prng stuck"}, | ||
| 87 | {0,NULL} | 81 | {0,NULL} |
| 88 | }; | 82 | }; |
| 89 | 83 | ||
| @@ -91,15 +85,12 @@ static ERR_STRING_DATA RAND_str_reasons[]= | |||
| 91 | 85 | ||
| 92 | void ERR_load_RAND_strings(void) | 86 | void ERR_load_RAND_strings(void) |
| 93 | { | 87 | { |
| 94 | static int init=1; | 88 | #ifndef OPENSSL_NO_ERR |
| 95 | 89 | ||
| 96 | if (init) | 90 | if (ERR_func_error_string(RAND_str_functs[0].error) == NULL) |
| 97 | { | 91 | { |
| 98 | init=0; | ||
| 99 | #ifndef OPENSSL_NO_ERR | ||
| 100 | ERR_load_strings(0,RAND_str_functs); | 92 | ERR_load_strings(0,RAND_str_functs); |
| 101 | ERR_load_strings(0,RAND_str_reasons); | 93 | ERR_load_strings(0,RAND_str_reasons); |
| 102 | #endif | ||
| 103 | |||
| 104 | } | 94 | } |
| 95 | #endif | ||
| 105 | } | 96 | } |
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c index a21bde79de..513e338985 100644 --- a/src/lib/libcrypto/rand/rand_lib.c +++ b/src/lib/libcrypto/rand/rand_lib.c | |||
| @@ -63,8 +63,6 @@ | |||
| 63 | #ifndef OPENSSL_NO_ENGINE | 63 | #ifndef OPENSSL_NO_ENGINE |
| 64 | #include <openssl/engine.h> | 64 | #include <openssl/engine.h> |
| 65 | #endif | 65 | #endif |
| 66 | #include <openssl/fips.h> | ||
| 67 | #include <openssl/fips_rand.h> | ||
| 68 | 66 | ||
| 69 | #ifndef OPENSSL_NO_ENGINE | 67 | #ifndef OPENSSL_NO_ENGINE |
| 70 | /* non-NULL if default_RAND_meth is ENGINE-provided */ | 68 | /* non-NULL if default_RAND_meth is ENGINE-provided */ |
| @@ -104,22 +102,8 @@ const RAND_METHOD *RAND_get_rand_method(void) | |||
| 104 | funct_ref = e; | 102 | funct_ref = e; |
| 105 | else | 103 | else |
| 106 | #endif | 104 | #endif |
| 107 | #ifdef OPENSSL_FIPS | 105 | default_RAND_meth = RAND_SSLeay(); |
| 108 | if(FIPS_mode()) | ||
| 109 | default_RAND_meth=FIPS_rand_method(); | ||
| 110 | else | ||
| 111 | #endif | ||
| 112 | default_RAND_meth = RAND_SSLeay(); | ||
| 113 | } | 106 | } |
| 114 | |||
| 115 | #ifdef OPENSSL_FIPS | ||
| 116 | if(FIPS_mode() | ||
| 117 | && default_RAND_meth != FIPS_rand_check()) | ||
| 118 | { | ||
| 119 | RANDerr(RAND_F_RAND_GET_RAND_METHOD,RAND_R_NON_FIPS_METHOD); | ||
| 120 | return 0; | ||
| 121 | } | ||
| 122 | #endif | ||
| 123 | return default_RAND_meth; | 107 | return default_RAND_meth; |
| 124 | } | 108 | } |
| 125 | 109 | ||
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index 7183fa32e4..6c0ec9a41c 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c | |||
| @@ -102,10 +102,8 @@ int RAND_load_file(const char *file, long bytes) | |||
| 102 | 102 | ||
| 103 | if (file == NULL) return(0); | 103 | if (file == NULL) return(0); |
| 104 | 104 | ||
| 105 | i=stat(file,&sb); | 105 | if (stat(file,&sb) < 0) return(0); |
| 106 | /* If the state fails, put some crap in anyway */ | 106 | RAND_add(&sb,sizeof(sb),0.0); |
| 107 | RAND_add(&sb,sizeof(sb),0); | ||
| 108 | if (i < 0) return(0); | ||
| 109 | if (bytes == 0) return(ret); | 107 | if (bytes == 0) return(ret); |
| 110 | 108 | ||
| 111 | in=fopen(file,"rb"); | 109 | in=fopen(file,"rb"); |
| @@ -128,8 +126,12 @@ int RAND_load_file(const char *file, long bytes) | |||
| 128 | n = BUFSIZE; | 126 | n = BUFSIZE; |
| 129 | i=fread(buf,1,n,in); | 127 | i=fread(buf,1,n,in); |
| 130 | if (i <= 0) break; | 128 | if (i <= 0) break; |
| 129 | #ifdef PURIFY | ||
| 130 | RAND_add(buf,i,(double)i); | ||
| 131 | #else | ||
| 131 | /* even if n != i, use the full array */ | 132 | /* even if n != i, use the full array */ |
| 132 | RAND_add(buf,n,i); | 133 | RAND_add(buf,n,(double)i); |
| 134 | #endif | ||
| 133 | ret+=i; | 135 | ret+=i; |
| 134 | if (bytes > 0) | 136 | if (bytes > 0) |
| 135 | { | 137 | { |
