summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rand/rand_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/rand/rand_lib.c')
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c57
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 64static ENGINE *rand_engine=NULL;
64static RAND_METHOD *rand_meth=NULL;
65#else
66extern RAND_METHOD rand_ssleay_meth;
67static RAND_METHOD *rand_meth= &rand_ssleay_meth;
68#endif
69 65
66#if 0
70void RAND_set_rand_method(RAND_METHOD *meth) 67void RAND_set_rand_method(RAND_METHOD *meth)
71 { 68 {
72 rand_meth=meth; 69 rand_meth=meth;
73 } 70 }
71#else
72int 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
75RAND_METHOD *RAND_get_rand_method(void) 85RAND_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
80void RAND_cleanup(void) 93void 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
86void RAND_seed(const void *buf, int num) 100void 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
92void RAND_add(const void *buf, int num, double entropy) 107void 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
98int RAND_bytes(unsigned char *buf, int num) 114int 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
105int RAND_pseudo_bytes(unsigned char *buf, int num) 122int 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
112int RAND_status(void) 130int 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 }