Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/openssl/rand.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved.
0003  *
0004  * Licensed under the Apache License 2.0 (the "License").  You may not use
0005  * this file except in compliance with the License.  You can obtain a copy
0006  * in the file LICENSE in the source distribution or at
0007  * https://www.openssl.org/source/license.html
0008  */
0009 
0010 #ifndef OPENSSL_RAND_H
0011 #define OPENSSL_RAND_H
0012 #pragma once
0013 
0014 #include <openssl/macros.h>
0015 #ifndef OPENSSL_NO_DEPRECATED_3_0
0016 #define HEADER_RAND_H
0017 #endif
0018 
0019 #include <stdlib.h>
0020 #include <openssl/types.h>
0021 #include <openssl/e_os2.h>
0022 #include <openssl/randerr.h>
0023 #include <openssl/evp.h>
0024 
0025 #ifdef __cplusplus
0026 extern "C" {
0027 #endif
0028 
0029 /*
0030  * Default security strength (in the sense of [NIST SP 800-90Ar1])
0031  *
0032  * NIST SP 800-90Ar1 supports the strength of the DRBG being smaller than that
0033  * of the cipher by collecting less entropy. The current DRBG implementation
0034  * does not take RAND_DRBG_STRENGTH into account and sets the strength of the
0035  * DRBG to that of the cipher.
0036  */
0037 #define RAND_DRBG_STRENGTH 256
0038 
0039 #ifndef OPENSSL_NO_DEPRECATED_3_0
0040 struct rand_meth_st {
0041     int (*seed)(const void *buf, int num);
0042     int (*bytes)(unsigned char *buf, int num);
0043     void (*cleanup)(void);
0044     int (*add)(const void *buf, int num, double randomness);
0045     int (*pseudorand)(unsigned char *buf, int num);
0046     int (*status)(void);
0047 };
0048 
0049 OSSL_DEPRECATEDIN_3_0 int RAND_set_rand_method(const RAND_METHOD *meth);
0050 OSSL_DEPRECATEDIN_3_0 const RAND_METHOD *RAND_get_rand_method(void);
0051 #ifndef OPENSSL_NO_ENGINE
0052 OSSL_DEPRECATEDIN_3_0 int RAND_set_rand_engine(ENGINE *engine);
0053 #endif
0054 
0055 OSSL_DEPRECATEDIN_3_0 RAND_METHOD *RAND_OpenSSL(void);
0056 #endif /* OPENSSL_NO_DEPRECATED_3_0 */
0057 
0058 #ifndef OPENSSL_NO_DEPRECATED_1_1_0
0059 #define RAND_cleanup() \
0060     while (0)          \
0061     continue
0062 #endif
0063 int RAND_bytes(unsigned char *buf, int num);
0064 int RAND_priv_bytes(unsigned char *buf, int num);
0065 
0066 /*
0067  * Equivalent of RAND_priv_bytes() but additionally taking an OSSL_LIB_CTX and
0068  * a strength.
0069  */
0070 int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num,
0071     unsigned int strength);
0072 
0073 /*
0074  * Equivalent of RAND_bytes() but additionally taking an OSSL_LIB_CTX and
0075  * a strength.
0076  */
0077 int RAND_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num,
0078     unsigned int strength);
0079 
0080 #ifndef OPENSSL_NO_DEPRECATED_1_1_0
0081 OSSL_DEPRECATEDIN_1_1_0 int RAND_pseudo_bytes(unsigned char *buf, int num);
0082 #endif
0083 
0084 EVP_RAND_CTX *RAND_get0_primary(OSSL_LIB_CTX *ctx);
0085 EVP_RAND_CTX *RAND_get0_public(OSSL_LIB_CTX *ctx);
0086 EVP_RAND_CTX *RAND_get0_private(OSSL_LIB_CTX *ctx);
0087 int RAND_set0_public(OSSL_LIB_CTX *ctx, EVP_RAND_CTX *rand);
0088 int RAND_set0_private(OSSL_LIB_CTX *ctx, EVP_RAND_CTX *rand);
0089 
0090 int RAND_set_DRBG_type(OSSL_LIB_CTX *ctx, const char *drbg, const char *propq,
0091     const char *cipher, const char *digest);
0092 int RAND_set_seed_source_type(OSSL_LIB_CTX *ctx, const char *seed,
0093     const char *propq);
0094 
0095 void RAND_seed(const void *buf, int num);
0096 void RAND_keep_random_devices_open(int keep);
0097 
0098 #if defined(__ANDROID__) && defined(__NDK_FPABI__)
0099 __NDK_FPABI__ /* __attribute__((pcs("aapcs"))) on ARM */
0100 #endif
0101     void RAND_add(const void *buf, int num, double randomness);
0102 int RAND_load_file(const char *file, long max_bytes);
0103 int RAND_write_file(const char *file);
0104 const char *RAND_file_name(char *file, size_t num);
0105 int RAND_status(void);
0106 
0107 #ifndef OPENSSL_NO_EGD
0108 int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes);
0109 int RAND_egd(const char *path);
0110 int RAND_egd_bytes(const char *path, int bytes);
0111 #endif
0112 
0113 int RAND_poll(void);
0114 
0115 #if defined(_WIN32) && (defined(BASETYPES) || defined(_WINDEF_H))
0116 /* application has to include <windows.h> in order to use these */
0117 #ifndef OPENSSL_NO_DEPRECATED_1_1_0
0118 OSSL_DEPRECATEDIN_1_1_0 void RAND_screen(void);
0119 OSSL_DEPRECATEDIN_1_1_0 int RAND_event(UINT, WPARAM, LPARAM);
0120 #endif
0121 #endif
0122 
0123 int RAND_set1_random_provider(OSSL_LIB_CTX *ctx, OSSL_PROVIDER *p);
0124 
0125 /* Which parameter to provider_random call */
0126 #define OSSL_PROV_RANDOM_PUBLIC 0
0127 #define OSSL_PROV_RANDOM_PRIVATE 1
0128 
0129 #ifdef __cplusplus
0130 }
0131 #endif
0132 
0133 #endif