VirtualBox

source: vbox/trunk/src/libs/openssl-3.1.7/include/crypto/rand.h@ 107278

最後變更 在這個檔案從107278是 104078,由 vboxsync 提交於 11 月 前

openssl-3.1.5: Applied and adjusted our OpenSSL changes to 3.1.4. bugref:10638

檔案大小: 4.9 KB
 
1/*
2 * Copyright 2016-2023 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/*
11 * Licensed under the Apache License 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 * https://www.openssl.org/source/license.html
15 * or in the file LICENSE in the source distribution.
16 */
17
18#ifndef OSSL_CRYPTO_RAND_H
19# define OSSL_CRYPTO_RAND_H
20# ifndef RT_WITHOUT_PRAGMA_ONCE /* VBOX */
21# pragma once
22# endif /* VBOX */
23
24# include <openssl/rand.h>
25# include "crypto/rand_pool.h"
26
27# if defined(__APPLE__) && !defined(OPENSSL_NO_APPLE_CRYPTO_RANDOM)
28# include <Availability.h>
29# if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || \
30 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000)
31# define OPENSSL_APPLE_CRYPTO_RANDOM 1
32# include <CommonCrypto/CommonCryptoError.h>
33# include <CommonCrypto/CommonRandom.h>
34# endif
35# endif
36
37/*
38 * Defines related to seed sources
39 */
40#ifndef DEVRANDOM
41/*
42 * set this to a comma-separated list of 'random' device files to try out. By
43 * default, we will try to read at least one of these files
44 */
45# define DEVRANDOM "/dev/urandom", "/dev/random", "/dev/hwrng", "/dev/srandom"
46# if defined(__linux) && !defined(__ANDROID__)
47# ifndef DEVRANDOM_WAIT
48# define DEVRANDOM_WAIT "/dev/random"
49# endif
50/*
51 * Linux kernels 4.8 and later changes how their random device works and there
52 * is no reliable way to tell that /dev/urandom has been seeded -- getentropy(2)
53 * should be used instead.
54 */
55# ifndef DEVRANDOM_SAFE_KERNEL
56# define DEVRANDOM_SAFE_KERNEL 4, 8
57# endif
58/*
59 * Some operating systems do not permit select(2) on their random devices,
60 * defining this to zero will force the use of read(2) to extract one byte
61 * from /dev/random.
62 */
63# ifndef DEVRANDM_WAIT_USE_SELECT
64# define DEVRANDM_WAIT_USE_SELECT 1
65# endif
66/*
67 * Define the shared memory identifier used to indicate if the operating
68 * system has properly seeded the DEVRANDOM source.
69 */
70# ifndef OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID
71# define OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID 114
72# endif
73
74# endif
75#endif
76
77#if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
78/*
79 * set this to a comma-separated list of 'egd' sockets to try out. These
80 * sockets will be tried in the order listed in case accessing the device
81 * files listed in DEVRANDOM did not return enough randomness.
82 */
83# define DEVRANDOM_EGD "/var/run/egd-pool", "/dev/egd-pool", "/etc/egd-pool", "/etc/entropy"
84#endif
85
86void ossl_rand_cleanup_int(void);
87
88/*
89 * Initialise the random pool reseeding sources.
90 *
91 * Returns 1 on success and 0 on failure.
92 */
93int ossl_rand_pool_init(void);
94
95/*
96 * Finalise the random pool reseeding sources.
97 */
98void ossl_rand_pool_cleanup(void);
99
100/*
101 * Control the random pool use of open file descriptors.
102 */
103void ossl_rand_pool_keep_random_devices_open(int keep);
104
105/*
106 * Configuration
107 */
108void ossl_random_add_conf_module(void);
109
110/*
111 * Get and cleanup random seed material.
112 */
113size_t ossl_rand_get_entropy(OSSL_LIB_CTX *ctx,
114 unsigned char **pout, int entropy,
115 size_t min_len, size_t max_len);
116size_t ossl_rand_get_user_entropy(OSSL_LIB_CTX *ctx,
117 unsigned char **pout, int entropy,
118 size_t min_len, size_t max_len);
119void ossl_rand_cleanup_entropy(OSSL_LIB_CTX *ctx,
120 unsigned char *buf, size_t len);
121void ossl_rand_cleanup_user_entropy(OSSL_LIB_CTX *ctx,
122 unsigned char *buf, size_t len);
123size_t ossl_rand_get_nonce(OSSL_LIB_CTX *ctx,
124 unsigned char **pout, size_t min_len, size_t max_len,
125 const void *salt, size_t salt_len);
126size_t ossl_rand_get_user_nonce(OSSL_LIB_CTX *ctx, unsigned char **pout,
127 size_t min_len, size_t max_len,
128 const void *salt, size_t salt_len);
129void ossl_rand_cleanup_nonce(OSSL_LIB_CTX *ctx,
130 unsigned char *buf, size_t len);
131void ossl_rand_cleanup_user_nonce(OSSL_LIB_CTX *ctx,
132 unsigned char *buf, size_t len);
133
134/*
135 * Get seeding material from the operating system sources.
136 */
137size_t ossl_pool_acquire_entropy(RAND_POOL *pool);
138int ossl_pool_add_nonce_data(RAND_POOL *pool);
139
140# ifdef FIPS_MODULE
141EVP_RAND_CTX *ossl_rand_get0_private_noncreating(OSSL_LIB_CTX *ctx);
142# else
143EVP_RAND_CTX *ossl_rand_get0_seed_noncreating(OSSL_LIB_CTX *ctx);
144# endif
145#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette