eef5e11cc5986f6949699421278f9bf055a3b3b3
[openssl.git] / crypto / rand / drbg_lib.c
1 /*
2  * Copyright 2011-2017 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include <string.h>
11 #include <openssl/crypto.h>
12 #include <openssl/err.h>
13 #include <openssl/rand.h>
14 #include "rand_lcl.h"
15 #include "internal/thread_once.h"
16 #include "internal/rand_int.h"
17
18 static RAND_DRBG rand_drbg; /* The default global DRBG. */
19 static RAND_DRBG priv_drbg; /* The global private-key DRBG. */
20
21 /* NIST SP 800-90A DRBG recommends the use of a personalization string. */
22 static const char ossl_pers_string[] = "OpenSSL NIST SP 800-90A DRBG";
23
24 /*
25  * Support framework for NIST SP 800-90A DRBG, AES-CTR mode.
26  * The RAND_DRBG is OpenSSL's pointer to an instance of the DRBG.
27  *
28  * The OpenSSL model is to have new and free functions, and that new
29  * does all initialization.  That is not the NIST model, which has
30  * instantiation and un-instantiate, and re-use within a new/free
31  * lifecycle.  (No doubt this comes from the desire to support hardware
32  * DRBG, where allocation of resources on something like an HSM is
33  * a much bigger deal than just re-setting an allocated resource.)
34  */
35
36 static CRYPTO_ONCE rand_drbg_init = CRYPTO_ONCE_STATIC_INIT;
37
38 static int drbg_setup(RAND_DRBG *drbg, const char *name);
39
40 /*
41  * Set/initialize |drbg| to be of type |nid|, with optional |flags|.
42  * Return -2 if the type is not supported, 1 on success and -1 on
43  * failure.
44  */
45 int RAND_DRBG_set(RAND_DRBG *drbg, int nid, unsigned int flags)
46 {
47     int ret = 1;
48
49     drbg->state = DRBG_UNINITIALISED;
50     drbg->flags = flags;
51     drbg->nid = nid;
52
53     switch (nid) {
54     default:
55         RANDerr(RAND_F_RAND_DRBG_SET, RAND_R_UNSUPPORTED_DRBG_TYPE);
56         return -2;
57     case 0:
58         /* Uninitialized; that's okay. */
59         return 1;
60     case NID_aes_128_ctr:
61     case NID_aes_192_ctr:
62     case NID_aes_256_ctr:
63         ret = ctr_init(drbg);
64         break;
65     }
66
67     if (ret < 0)
68         RANDerr(RAND_F_RAND_DRBG_SET, RAND_R_ERROR_INITIALISING_DRBG);
69     return ret;
70 }
71
72 /*
73  * Allocate memory and initialize a new DRBG.  The |parent|, if not
74  * NULL, will be used to auto-seed this RAND_DRBG as needed.
75  */
76 RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent)
77 {
78     RAND_DRBG *drbg = OPENSSL_zalloc(sizeof(*drbg));
79
80     if (drbg == NULL) {
81         RANDerr(RAND_F_RAND_DRBG_NEW, ERR_R_MALLOC_FAILURE);
82         goto err;
83     }
84     drbg->fork_count = rand_fork_count;
85     drbg->parent = parent;
86     if (RAND_DRBG_set(drbg, type, flags) < 0)
87         goto err;
88
89     if (parent != NULL) {
90         if (!RAND_DRBG_set_callbacks(drbg, rand_drbg_get_entropy,
91                                      rand_drbg_cleanup_entropy,
92                                      NULL, NULL))
93             goto err;
94     }
95
96     return drbg;
97
98 err:
99     OPENSSL_free(drbg);
100     return NULL;
101 }
102
103 /*
104  * Uninstantiate |drbg| and free all memory.
105  */
106 void RAND_DRBG_free(RAND_DRBG *drbg)
107 {
108     if (drbg == NULL)
109         return;
110
111     ctr_uninstantiate(drbg);
112     CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DRBG, drbg, &drbg->ex_data);
113     OPENSSL_clear_free(drbg, sizeof(*drbg));
114 }
115
116 /*
117  * Instantiate |drbg|, after it has been initialized.  Use |pers| and
118  * |perslen| as prediction-resistance input.
119  */
120 int RAND_DRBG_instantiate(RAND_DRBG *drbg,
121                           const unsigned char *pers, size_t perslen)
122 {
123     unsigned char *nonce = NULL, *entropy = NULL;
124     size_t noncelen = 0, entropylen = 0;
125
126     if (perslen > drbg->max_perslen) {
127         RANDerr(RAND_F_RAND_DRBG_INSTANTIATE,
128                 RAND_R_PERSONALISATION_STRING_TOO_LONG);
129         goto end;
130     }
131     if (drbg->state != DRBG_UNINITIALISED) {
132         RANDerr(RAND_F_RAND_DRBG_INSTANTIATE,
133                 drbg->state == DRBG_ERROR ? RAND_R_IN_ERROR_STATE
134                                           : RAND_R_ALREADY_INSTANTIATED);
135         goto end;
136     }
137
138     drbg->state = DRBG_ERROR;
139     if (drbg->get_entropy != NULL)
140         entropylen = drbg->get_entropy(drbg, &entropy, drbg->strength,
141                                    drbg->min_entropylen, drbg->max_entropylen);
142     if (entropylen < drbg->min_entropylen
143         || entropylen > drbg->max_entropylen) {
144         RANDerr(RAND_F_RAND_DRBG_INSTANTIATE, RAND_R_ERROR_RETRIEVING_ENTROPY);
145         goto end;
146     }
147
148     if (drbg->max_noncelen > 0 && drbg->get_nonce != NULL) {
149         noncelen = drbg->get_nonce(drbg, &nonce, drbg->strength / 2,
150                                    drbg->min_noncelen, drbg->max_noncelen);
151         if (noncelen < drbg->min_noncelen || noncelen > drbg->max_noncelen) {
152             RANDerr(RAND_F_RAND_DRBG_INSTANTIATE,
153                     RAND_R_ERROR_RETRIEVING_NONCE);
154             goto end;
155         }
156     }
157
158     if (!ctr_instantiate(drbg, entropy, entropylen,
159                          nonce, noncelen, pers, perslen)) {
160         RANDerr(RAND_F_RAND_DRBG_INSTANTIATE, RAND_R_ERROR_INSTANTIATING_DRBG);
161         goto end;
162     }
163
164     drbg->state = DRBG_READY;
165     drbg->reseed_counter = 1;
166
167 end:
168     if (entropy != NULL && drbg->cleanup_entropy != NULL)
169         drbg->cleanup_entropy(drbg, entropy, entropylen);
170     if (nonce != NULL && drbg->cleanup_nonce!= NULL )
171         drbg->cleanup_nonce(drbg, nonce, noncelen);
172     if (drbg->pool != NULL) {
173         if (drbg->state == DRBG_READY) {
174             RANDerr(RAND_F_RAND_DRBG_INSTANTIATE,
175                     RAND_R_ERROR_ENTROPY_POOL_WAS_IGNORED);
176             drbg->state = DRBG_ERROR;
177         }
178         RAND_POOL_free(drbg->pool);
179         drbg->pool = NULL;
180     }
181     if (drbg->state == DRBG_READY)
182         return 1;
183     return 0;
184 }
185
186 /*
187  * Uninstantiate |drbg|. Must be instantiated before it can be used.
188  */
189 int RAND_DRBG_uninstantiate(RAND_DRBG *drbg)
190 {
191     int ret = ctr_uninstantiate(drbg);
192
193     OPENSSL_cleanse(&drbg->ctr, sizeof(drbg->ctr));
194     drbg->state = DRBG_UNINITIALISED;
195     return ret;
196 }
197
198 /*
199  * Reseed |drbg|, mixing in the specified data
200  */
201 int RAND_DRBG_reseed(RAND_DRBG *drbg,
202                      const unsigned char *adin, size_t adinlen)
203 {
204     unsigned char *entropy = NULL;
205     size_t entropylen = 0;
206
207     if (drbg->state == DRBG_ERROR) {
208         RANDerr(RAND_F_RAND_DRBG_RESEED, RAND_R_IN_ERROR_STATE);
209         return 0;
210     }
211     if (drbg->state == DRBG_UNINITIALISED) {
212         RANDerr(RAND_F_RAND_DRBG_RESEED, RAND_R_NOT_INSTANTIATED);
213         return 0;
214     }
215
216     if (adin == NULL)
217         adinlen = 0;
218     else if (adinlen > drbg->max_adinlen) {
219         RANDerr(RAND_F_RAND_DRBG_RESEED, RAND_R_ADDITIONAL_INPUT_TOO_LONG);
220         return 0;
221     }
222
223     drbg->state = DRBG_ERROR;
224     if (drbg->get_entropy != NULL)
225         entropylen = drbg->get_entropy(drbg, &entropy, drbg->strength,
226                                    drbg->min_entropylen, drbg->max_entropylen);
227     if (entropylen < drbg->min_entropylen
228         || entropylen > drbg->max_entropylen) {
229         RANDerr(RAND_F_RAND_DRBG_RESEED, RAND_R_ERROR_RETRIEVING_ENTROPY);
230         goto end;
231     }
232
233     if (!ctr_reseed(drbg, entropy, entropylen, adin, adinlen))
234         goto end;
235     drbg->state = DRBG_READY;
236     drbg->reseed_counter = 1;
237
238 end:
239     if (entropy != NULL && drbg->cleanup_entropy != NULL)
240         drbg->cleanup_entropy(drbg, entropy, entropylen);
241     if (drbg->state == DRBG_READY)
242         return 1;
243     return 0;
244 }
245
246 /*
247  * Restart |drbg|, using the specified entropy or additional input
248  *
249  * Tries its best to get the drbg instantiated by all means,
250  * regardless of its current state.
251  *
252  * Optionally, a |buffer| of |len| random bytes can be passed,
253  * which is assumed to contain at least |entropy| bits of entropy.
254  *
255  * If |entropy| > 0, the buffer content is used as entropy input.
256  *
257  * If |entropy| == 0, the buffer content is used as additional input
258  *
259  * Returns 1 on success, 0 on failure.
260  *
261  * This function is used internally only.
262  */
263 int rand_drbg_restart(RAND_DRBG *drbg,
264                       const unsigned char *buffer, size_t len, size_t entropy)
265 {
266     int reseeded = 0;
267     const unsigned char *adin = NULL;
268     size_t adinlen = 0;
269
270     if (drbg->pool != NULL) {
271         RANDerr(RAND_F_RAND_DRBG_RESTART, ERR_R_INTERNAL_ERROR);
272         RAND_POOL_free(drbg->pool);
273         drbg->pool = NULL;
274     }
275
276     if (buffer != NULL) {
277         if (entropy > 0) {
278             if (drbg->max_entropylen < len) {
279                 RANDerr(RAND_F_RAND_DRBG_RESTART,
280                     RAND_R_ENTROPY_INPUT_TOO_LONG);
281                 return 0;
282             }
283
284             if (entropy > 8 * len) {
285                 RANDerr(RAND_F_RAND_DRBG_RESTART, RAND_R_ENTROPY_OUT_OF_RANGE);
286                 return 0;
287             }
288
289             /* will be picked up by the rand_drbg_get_entropy() callback */
290             drbg->pool = RAND_POOL_new(entropy, len, len);
291             if (drbg->pool == NULL)
292                 return 0;
293
294             RAND_POOL_add(drbg->pool, buffer, len, entropy);
295         } else {
296             if (drbg->max_adinlen < len) {
297                 RANDerr(RAND_F_RAND_DRBG_RESTART,
298                         RAND_R_ADDITIONAL_INPUT_TOO_LONG);
299                 return 0;
300             }
301             adin = buffer;
302             adinlen = len;
303         }
304     }
305
306     /* repair error state */
307     if (drbg->state == DRBG_ERROR)
308         RAND_DRBG_uninstantiate(drbg);
309
310     /* repair uninitialized state */
311     if (drbg->state == DRBG_UNINITIALISED) {
312         drbg_setup(drbg, NULL);
313         /* already reseeded. prevent second reseeding below */
314         reseeded = (drbg->state == DRBG_READY);
315     }
316
317     /* refresh current state if entropy or additional input has been provided */
318     if (drbg->state == DRBG_READY) {
319         if (adin != NULL) {
320             /*
321              * mix in additional input without reseeding
322              *
323              * Similar to RAND_DRBG_reseed(), but the provided additional
324              * data |adin| is mixed into the current state without pulling
325              * entropy from the trusted entropy source using get_entropy().
326              * This is not a reseeding in the strict sense of NIST SP 800-90A.
327              */
328             ctr_reseed(drbg, adin, adinlen, NULL, 0);
329         } else if (reseeded == 0) {
330             /* do a full reseeding if it has not been done yet above */
331             RAND_DRBG_reseed(drbg, NULL, 0);
332         }
333     }
334
335     /* check whether a given entropy pool was cleared properly during reseed */
336     if (drbg->pool != NULL) {
337         drbg->state = DRBG_ERROR;
338         RANDerr(RAND_F_RAND_DRBG_RESTART, ERR_R_INTERNAL_ERROR);
339         RAND_POOL_free(drbg->pool);
340         drbg->pool = NULL;
341         return 0;
342     }
343
344     return drbg->state == DRBG_READY;
345 }
346
347 /*
348  * Generate |outlen| bytes into the buffer at |out|.  Reseed if we need
349  * to or if |prediction_resistance| is set.  Additional input can be
350  * sent in |adin| and |adinlen|.
351  *
352  * Returns 1 on success, 0 on failure.
353  *
354  */
355 int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,
356                        int prediction_resistance,
357                        const unsigned char *adin, size_t adinlen)
358 {
359     if (drbg->state != DRBG_READY) {
360         /* try to recover from previous errors */
361         rand_drbg_restart(drbg, NULL, 0, 0);
362
363         if (drbg->state == DRBG_ERROR) {
364             RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_IN_ERROR_STATE);
365             return 0;
366         }
367         if (drbg->state == DRBG_UNINITIALISED) {
368             RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_NOT_INSTANTIATED);
369             return 0;
370         }
371     }
372
373     if (outlen > drbg->max_request) {
374         RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_REQUEST_TOO_LARGE_FOR_DRBG);
375         return 0;
376     }
377     if (adinlen > drbg->max_adinlen) {
378         RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_ADDITIONAL_INPUT_TOO_LONG);
379         return 0;
380     }
381
382     if (drbg->fork_count != rand_fork_count) {
383         drbg->fork_count = rand_fork_count;
384         drbg->state = DRBG_RESEED;
385     }
386
387     if (drbg->reseed_counter >= drbg->reseed_interval)
388         drbg->state = DRBG_RESEED;
389
390     if (drbg->state == DRBG_RESEED || prediction_resistance) {
391         if (!RAND_DRBG_reseed(drbg, adin, adinlen)) {
392             RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_RESEED_ERROR);
393             return 0;
394         }
395         adin = NULL;
396         adinlen = 0;
397     }
398
399     if (!ctr_generate(drbg, out, outlen, adin, adinlen)) {
400         drbg->state = DRBG_ERROR;
401         RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_GENERATE_ERROR);
402         return 0;
403     }
404
405     if (drbg->reseed_counter >= drbg->reseed_interval)
406         drbg->state = DRBG_RESEED;
407     else
408         drbg->reseed_counter++;
409     return 1;
410 }
411
412 /*
413  * Set the RAND_DRBG callbacks for obtaining entropy and nonce.
414  *
415  * In the following, the signature and the semantics of the
416  * get_entropy() and cleanup_entropy() callbacks are explained.
417  *
418  * GET_ENTROPY
419  *
420  *     size_t get_entropy(RAND_DRBG *ctx,
421  *                        unsigned char **pout,
422  *                        int entropy,
423  *                        size_t min_len, size_t max_len);
424  *
425  * This is a request to allocate and fill a buffer of size
426  * |min_len| <= size <= |max_len| (in bytes) which contains
427  * at least |entropy| bits of randomness. The buffer's address is
428  * to be returned in |*pout| and the number of collected
429  * randomness bytes (which may be less than the allocated size
430  * of the buffer) as return value.
431  *
432  * If the callback fails to acquire at least |entropy| bits of
433  * randomness, it shall return a buffer length of 0.
434  *
435  * CLEANUP_ENTROPY
436  *
437  *     void cleanup_entropy(RAND_DRBG *ctx,
438  *                          unsigned char *out, size_t outlen);
439  *
440  * A request to clear and free the buffer allocated by get_entropy().
441  * The values |out| and |outlen| are expected to be the random buffer's
442  * address and length, as returned by the get_entropy() callback.
443  *
444  * GET_NONCE, CLEANUP_NONCE
445  *
446  * Signature and semantics of the get_nonce() and cleanup_nonce()
447  * callbacks are analogous to get_entropy() and cleanup_entropy().
448  * Currently, the nonce is used only for the known answer tests.
449  */
450 int RAND_DRBG_set_callbacks(RAND_DRBG *drbg,
451                             RAND_DRBG_get_entropy_fn get_entropy,
452                             RAND_DRBG_cleanup_entropy_fn cleanup_entropy,
453                             RAND_DRBG_get_nonce_fn get_nonce,
454                             RAND_DRBG_cleanup_nonce_fn cleanup_nonce)
455 {
456     if (drbg->state != DRBG_UNINITIALISED)
457         return 0;
458     drbg->get_entropy = get_entropy;
459     drbg->cleanup_entropy = cleanup_entropy;
460     drbg->get_nonce = get_nonce;
461     drbg->cleanup_nonce = cleanup_nonce;
462     return 1;
463 }
464
465 /*
466  * Set the reseed interval.
467  */
468 int RAND_DRBG_set_reseed_interval(RAND_DRBG *drbg, int interval)
469 {
470     if (interval < 0 || interval > MAX_RESEED)
471         return 0;
472     drbg->reseed_interval = interval;
473     return 1;
474 }
475
476 /*
477  * Get and set the EXDATA
478  */
479 int RAND_DRBG_set_ex_data(RAND_DRBG *drbg, int idx, void *arg)
480 {
481     return CRYPTO_set_ex_data(&drbg->ex_data, idx, arg);
482 }
483
484 void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx)
485 {
486     return CRYPTO_get_ex_data(&drbg->ex_data, idx);
487 }
488
489
490 /*
491  * The following functions provide a RAND_METHOD that works on the
492  * global DRBG.  They lock.
493  */
494
495 /*
496  * Initializes the DRBG with default settings.
497  * For global DRBGs a global lock is created with the given name
498  * Returns 1 on success, 0 on failure
499  */
500 static int drbg_setup(RAND_DRBG *drbg, const char *name)
501 {
502     int ret = 1;
503
504     if (name != NULL) {
505         if (drbg->lock != NULL) {
506             RANDerr(RAND_F_DRBG_SETUP, ERR_R_INTERNAL_ERROR);
507             return 0;
508         }
509
510         drbg->lock = CRYPTO_THREAD_glock_new(name);
511         if (drbg->lock == NULL) {
512             RANDerr(RAND_F_DRBG_SETUP, RAND_R_FAILED_TO_CREATE_LOCK);
513             return 0;
514         }
515     }
516
517     ret &= RAND_DRBG_set(drbg,
518                          RAND_DRBG_NID, RAND_DRBG_FLAG_CTR_USE_DF) == 1;
519     ret &= RAND_DRBG_set_callbacks(drbg, rand_drbg_get_entropy,
520                                    rand_drbg_cleanup_entropy, NULL, NULL) == 1;
521     /*
522      * Ignore instantiation error so support just-in-time instantiation.
523      *
524      * The state of the drbg will be checked in RAND_DRBG_generate() and
525      * an automatic recovery is attempted.
526      */
527     RAND_DRBG_instantiate(drbg,
528                           (const unsigned char *) ossl_pers_string,
529                           sizeof(ossl_pers_string) - 1);
530     return ret;
531 }
532
533 /*
534  * Initialize the global DRBGs on first use.
535  * Returns 1 on success, 0 on failure.
536  */
537 DEFINE_RUN_ONCE_STATIC(do_rand_drbg_init)
538 {
539     int ret = 1;
540
541     ret &= drbg_setup(&rand_drbg, "rand_drbg");
542     ret &= drbg_setup(&priv_drbg, "priv_drbg");
543
544     return ret;
545 }
546
547 /* Cleans up the given global DRBG  */
548 static void drbg_cleanup(RAND_DRBG *drbg)
549 {
550     CRYPTO_THREAD_lock_free(drbg->lock);
551     RAND_DRBG_uninstantiate(drbg);
552 }
553
554 /* Clean up the global DRBGs before exit */
555 void rand_drbg_cleanup_int(void)
556 {
557     drbg_cleanup(&rand_drbg);
558     drbg_cleanup(&priv_drbg);
559 }
560
561 /* Implements the default OpenSSL RAND_bytes() method */
562 static int drbg_bytes(unsigned char *out, int count)
563 {
564     int ret = 0;
565     size_t chunk;
566     RAND_DRBG *drbg = RAND_DRBG_get0_global();
567
568     if (drbg == NULL)
569         return 0;
570
571     CRYPTO_THREAD_write_lock(drbg->lock);
572     if (drbg->state == DRBG_UNINITIALISED)
573         goto err;
574
575     for ( ; count > 0; count -= chunk, out += chunk) {
576         chunk = count;
577         if (chunk > drbg->max_request)
578             chunk = drbg->max_request;
579         ret = RAND_DRBG_generate(drbg, out, chunk, 0, NULL, 0);
580         if (!ret)
581             goto err;
582     }
583     ret = 1;
584
585 err:
586     CRYPTO_THREAD_unlock(drbg->lock);
587     return ret;
588 }
589
590 /* Implements the default OpenSSL RAND_add() method */
591 static int drbg_add(const void *buf, int num, double randomness)
592 {
593     int ret = 0;
594     RAND_DRBG *drbg = RAND_DRBG_get0_global();
595
596     if (drbg == NULL)
597         return 0;
598
599     if (num < 0 || randomness < 0.0)
600         return 0;
601
602     if (randomness > (double)drbg->max_entropylen) {
603         /*
604          * The purpose of this check is to bound |randomness| by a
605          * relatively small value in order to prevent an integer
606          * overflow when multiplying by 8 in the rand_drbg_restart()
607          * call below.
608          */
609         return 0;
610     }
611
612     CRYPTO_THREAD_write_lock(drbg->lock);
613     ret = rand_drbg_restart(drbg, buf,
614                             (size_t)(unsigned int)num,
615                             (size_t)(8*randomness));
616     CRYPTO_THREAD_unlock(drbg->lock);
617
618     return ret;
619 }
620
621 /* Implements the default OpenSSL RAND_seed() method */
622 static int drbg_seed(const void *buf, int num)
623 {
624     return drbg_add(buf, num, num);
625 }
626
627 /* Implements the default OpenSSL RAND_status() method */
628 static int drbg_status(void)
629 {
630     int ret;
631     RAND_DRBG *drbg = RAND_DRBG_get0_global();
632
633     if (drbg == NULL)
634         return 0;
635
636     CRYPTO_THREAD_write_lock(drbg->lock);
637     ret = drbg->state == DRBG_READY ? 1 : 0;
638     CRYPTO_THREAD_unlock(drbg->lock);
639     return ret;
640 }
641
642 /*
643  * Get the global public DRBG.
644  * Returns pointer to the DRBG on success, NULL on failure.
645  */
646 RAND_DRBG *RAND_DRBG_get0_global(void)
647 {
648     if (!RUN_ONCE(&rand_drbg_init, do_rand_drbg_init))
649         return NULL;
650
651     return &rand_drbg;
652 }
653
654 /*
655  * Get the global private DRBG.
656  * Returns pointer to the DRBG on success, NULL on failure.
657  */
658 RAND_DRBG *RAND_DRBG_get0_priv_global(void)
659 {
660     if (!RUN_ONCE(&rand_drbg_init, do_rand_drbg_init))
661         return NULL;
662
663     return &priv_drbg;
664 }
665
666 RAND_METHOD rand_meth = {
667     drbg_seed,
668     drbg_bytes,
669     NULL,
670     drbg_add,
671     drbg_bytes,
672     drbg_status
673 };
674
675 RAND_METHOD *RAND_OpenSSL(void)
676 {
677     return &rand_meth;
678 }