diff options
| author | beck <> | 2000-12-15 02:58:47 +0000 |
|---|---|---|
| committer | beck <> | 2000-12-15 02:58:47 +0000 |
| commit | 9200bb13d15da4b2a23e6bc92c20e95b74aa2113 (patch) | |
| tree | 5c52d628ec1e34be76e7ef2a4235d248b7c44d24 /src/lib/libcrypto/rand/rand_lib.c | |
| parent | e131d25072e3d4197ba4b9bcc0d1b27d34d6488d (diff) | |
| download | openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.gz openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.bz2 openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.zip | |
openssl-engine-0.9.6 merge
Diffstat (limited to 'src/lib/libcrypto/rand/rand_lib.c')
| -rw-r--r-- | src/lib/libcrypto/rand/rand_lib.c | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c index 7da74aab0e..57eff0f132 100644 --- a/src/lib/libcrypto/rand/rand_lib.c +++ b/src/lib/libcrypto/rand/rand_lib.c | |||
| @@ -59,59 +59,78 @@ | |||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include <time.h> | 60 | #include <time.h> |
| 61 | #include <openssl/rand.h> | 61 | #include <openssl/rand.h> |
| 62 | #include <openssl/engine.h> | ||
| 62 | 63 | ||
| 63 | #ifdef NO_RAND | 64 | static ENGINE *rand_engine=NULL; |
| 64 | static RAND_METHOD *rand_meth=NULL; | ||
| 65 | #else | ||
| 66 | extern RAND_METHOD rand_ssleay_meth; | ||
| 67 | static RAND_METHOD *rand_meth= &rand_ssleay_meth; | ||
| 68 | #endif | ||
| 69 | 65 | ||
| 66 | #if 0 | ||
| 70 | void RAND_set_rand_method(RAND_METHOD *meth) | 67 | void RAND_set_rand_method(RAND_METHOD *meth) |
| 71 | { | 68 | { |
| 72 | rand_meth=meth; | 69 | rand_meth=meth; |
| 73 | } | 70 | } |
| 71 | #else | ||
| 72 | int RAND_set_rand_method(ENGINE *engine) | ||
| 73 | { | ||
| 74 | ENGINE *mtmp; | ||
| 75 | mtmp = rand_engine; | ||
| 76 | if (!ENGINE_init(engine)) | ||
| 77 | return 0; | ||
| 78 | rand_engine = engine; | ||
| 79 | /* SHOULD ERROR CHECK THIS!!! */ | ||
| 80 | ENGINE_finish(mtmp); | ||
| 81 | return 1; | ||
| 82 | } | ||
| 83 | #endif | ||
| 74 | 84 | ||
| 75 | RAND_METHOD *RAND_get_rand_method(void) | 85 | RAND_METHOD *RAND_get_rand_method(void) |
| 76 | { | 86 | { |
| 77 | return(rand_meth); | 87 | if (rand_engine == NULL |
| 88 | && (rand_engine = ENGINE_get_default_RAND()) == NULL) | ||
| 89 | return NULL; | ||
| 90 | return ENGINE_get_RAND(rand_engine); | ||
| 78 | } | 91 | } |
| 79 | 92 | ||
| 80 | void RAND_cleanup(void) | 93 | void RAND_cleanup(void) |
| 81 | { | 94 | { |
| 82 | if (rand_meth != NULL) | 95 | RAND_METHOD *meth = RAND_get_rand_method(); |
| 83 | rand_meth->cleanup(); | 96 | if (meth && meth->cleanup) |
| 97 | meth->cleanup(); | ||
| 84 | } | 98 | } |
| 85 | 99 | ||
| 86 | void RAND_seed(const void *buf, int num) | 100 | void RAND_seed(const void *buf, int num) |
| 87 | { | 101 | { |
| 88 | if (rand_meth != NULL) | 102 | RAND_METHOD *meth = RAND_get_rand_method(); |
| 89 | rand_meth->seed(buf,num); | 103 | if (meth && meth->seed) |
| 104 | meth->seed(buf,num); | ||
| 90 | } | 105 | } |
| 91 | 106 | ||
| 92 | void RAND_add(const void *buf, int num, double entropy) | 107 | void RAND_add(const void *buf, int num, double entropy) |
| 93 | { | 108 | { |
| 94 | if (rand_meth != NULL) | 109 | RAND_METHOD *meth = RAND_get_rand_method(); |
| 95 | rand_meth->add(buf,num,entropy); | 110 | if (meth && meth->add) |
| 111 | meth->add(buf,num,entropy); | ||
| 96 | } | 112 | } |
| 97 | 113 | ||
| 98 | int RAND_bytes(unsigned char *buf, int num) | 114 | int RAND_bytes(unsigned char *buf, int num) |
| 99 | { | 115 | { |
| 100 | if (rand_meth != NULL) | 116 | RAND_METHOD *meth = RAND_get_rand_method(); |
| 101 | return rand_meth->bytes(buf,num); | 117 | if (meth && meth->bytes) |
| 118 | return meth->bytes(buf,num); | ||
| 102 | return(-1); | 119 | return(-1); |
| 103 | } | 120 | } |
| 104 | 121 | ||
| 105 | int RAND_pseudo_bytes(unsigned char *buf, int num) | 122 | int RAND_pseudo_bytes(unsigned char *buf, int num) |
| 106 | { | 123 | { |
| 107 | if (rand_meth != NULL) | 124 | RAND_METHOD *meth = RAND_get_rand_method(); |
| 108 | return rand_meth->pseudorand(buf,num); | 125 | if (meth && meth->pseudorand) |
| 126 | return meth->pseudorand(buf,num); | ||
| 109 | return(-1); | 127 | return(-1); |
| 110 | } | 128 | } |
| 111 | 129 | ||
| 112 | int RAND_status(void) | 130 | int RAND_status(void) |
| 113 | { | 131 | { |
| 114 | if (rand_meth != NULL) | 132 | RAND_METHOD *meth = RAND_get_rand_method(); |
| 115 | return rand_meth->status(); | 133 | if (meth && meth->status) |
| 134 | return meth->status(); | ||
| 116 | return 0; | 135 | return 0; |
| 117 | } | 136 | } |
