check_chain_extensions(): Add check that Basic Constraints of CA cert are marked...
[openssl.git] / include / openssl / rand.h
1 /*
2  * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (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 #ifndef OPENSSL_RAND_H
11 # define OPENSSL_RAND_H
12 # pragma once
13
14 # include <openssl/macros.h>
15 # ifndef OPENSSL_NO_DEPRECATED_3_0
16 #  define HEADER_RAND_H
17 # endif
18
19 # include <stdlib.h>
20 # include <openssl/types.h>
21 # include <openssl/e_os2.h>
22 # include <openssl/randerr.h>
23 # include <openssl/evp.h>
24
25 #ifdef  __cplusplus
26 extern "C" {
27 #endif
28
29 /*
30  * Default security strength (in the sense of [NIST SP 800-90Ar1])
31  *
32  * NIST SP 800-90Ar1 supports the strength of the DRBG being smaller than that
33  * of the cipher by collecting less entropy. The current DRBG implementation
34  * does not take RAND_DRBG_STRENGTH into account and sets the strength of the
35  * DRBG to that of the cipher.
36  */
37 # define RAND_DRBG_STRENGTH             256
38
39 struct rand_meth_st {
40     int (*seed) (const void *buf, int num);
41     int (*bytes) (unsigned char *buf, int num);
42     void (*cleanup) (void);
43     int (*add) (const void *buf, int num, double randomness);
44     int (*pseudorand) (unsigned char *buf, int num);
45     int (*status) (void);
46 };
47
48 int RAND_set_rand_method(const RAND_METHOD *meth);
49 const RAND_METHOD *RAND_get_rand_method(void);
50 # ifndef OPENSSL_NO_ENGINE
51 int RAND_set_rand_engine(ENGINE *engine);
52 # endif
53
54 RAND_METHOD *RAND_OpenSSL(void);
55
56 # ifndef OPENSSL_NO_DEPRECATED_1_1_0
57 #   define RAND_cleanup() while(0) continue
58 # endif
59 int RAND_bytes(unsigned char *buf, int num);
60 int RAND_priv_bytes(unsigned char *buf, int num);
61
62 /* Equivalent of RAND_priv_bytes() but additionally taking an OPENSSL_CTX */
63 int RAND_priv_bytes_ex(OPENSSL_CTX *ctx, unsigned char *buf, int num);
64
65 /* Equivalent of RAND_bytes() but additionally taking an OPENSSL_CTX */
66 int RAND_bytes_ex(OPENSSL_CTX *ctx, unsigned char *buf, int num);
67
68 DEPRECATEDIN_1_1_0(int RAND_pseudo_bytes(unsigned char *buf, int num))
69
70 EVP_RAND_CTX *RAND_get0_primary(OPENSSL_CTX *ctx);
71 EVP_RAND_CTX *RAND_get0_public(OPENSSL_CTX *ctx);
72 EVP_RAND_CTX *RAND_get0_private(OPENSSL_CTX *ctx);
73
74 void RAND_seed(const void *buf, int num);
75 void RAND_keep_random_devices_open(int keep);
76
77 # if defined(__ANDROID__) && defined(__NDK_FPABI__)
78 __NDK_FPABI__   /* __attribute__((pcs("aapcs"))) on ARM */
79 # endif
80 void RAND_add(const void *buf, int num, double randomness);
81 int RAND_load_file(const char *file, long max_bytes);
82 int RAND_write_file(const char *file);
83 const char *RAND_file_name(char *file, size_t num);
84 int RAND_status(void);
85
86 # ifndef OPENSSL_NO_EGD
87 int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);
88 int RAND_egd(const char *path);
89 int RAND_egd_bytes(const char *path, int bytes);
90 # endif
91
92 int RAND_poll(void);
93
94 # if defined(_WIN32) && (defined(BASETYPES) || defined(_WINDEF_H))
95 /* application has to include <windows.h> in order to use these */
96 DEPRECATEDIN_1_1_0(void RAND_screen(void))
97 DEPRECATEDIN_1_1_0(int RAND_event(UINT, WPARAM, LPARAM))
98 # endif
99
100 #ifdef  __cplusplus
101 }
102 #endif
103
104 #endif