Enable export_to functions to have access to the libctx
[openssl.git] / include / openssl / rand.h
1 /*
2  * Copyright 1995-2018 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
24 #ifdef  __cplusplus
25 extern "C" {
26 #endif
27
28 struct rand_meth_st {
29     int (*seed) (const void *buf, int num);
30     int (*bytes) (unsigned char *buf, int num);
31     void (*cleanup) (void);
32     int (*add) (const void *buf, int num, double randomness);
33     int (*pseudorand) (unsigned char *buf, int num);
34     int (*status) (void);
35 };
36
37 int RAND_set_rand_method(const RAND_METHOD *meth);
38 const RAND_METHOD *RAND_get_rand_method(void);
39 # ifndef OPENSSL_NO_ENGINE
40 int RAND_set_rand_engine(ENGINE *engine);
41 # endif
42
43 RAND_METHOD *RAND_OpenSSL(void);
44
45 # ifndef OPENSSL_NO_DEPRECATED_1_1_0
46 #   define RAND_cleanup() while(0) continue
47 # endif
48 int RAND_bytes(unsigned char *buf, int num);
49 int RAND_priv_bytes(unsigned char *buf, int num);
50
51 /* Equivalent of RAND_priv_bytes() but additionally taking an OPENSSL_CTX */
52 int RAND_priv_bytes_ex(OPENSSL_CTX *ctx, unsigned char *buf, int num);
53
54 /* Equivalent of RAND_bytes() but additionally taking an OPENSSL_CTX */
55 int RAND_bytes_ex(OPENSSL_CTX *ctx, unsigned char *buf, int num);
56
57 DEPRECATEDIN_1_1_0(int RAND_pseudo_bytes(unsigned char *buf, int num))
58
59 void RAND_seed(const void *buf, int num);
60 void RAND_keep_random_devices_open(int keep);
61
62 # if defined(__ANDROID__) && defined(__NDK_FPABI__)
63 __NDK_FPABI__   /* __attribute__((pcs("aapcs"))) on ARM */
64 # endif
65 void RAND_add(const void *buf, int num, double randomness);
66 int RAND_load_file(const char *file, long max_bytes);
67 int RAND_write_file(const char *file);
68 const char *RAND_file_name(char *file, size_t num);
69 int RAND_status(void);
70
71 # ifndef OPENSSL_NO_EGD
72 int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);
73 int RAND_egd(const char *path);
74 int RAND_egd_bytes(const char *path, int bytes);
75 # endif
76
77 int RAND_poll(void);
78
79 # if defined(_WIN32) && (defined(BASETYPES) || defined(_WINDEF_H))
80 /* application has to include <windows.h> in order to use these */
81 DEPRECATEDIN_1_1_0(void RAND_screen(void))
82 DEPRECATEDIN_1_1_0(int RAND_event(UINT, WPARAM, LPARAM))
83 # endif
84
85
86 #ifdef  __cplusplus
87 }
88 #endif
89
90 #endif