VirtualBox

source: vbox/trunk/include/iprt/rand.h@ 41909

最後變更 在這個檔案從41909是 41909,由 vboxsync 提交於 13 年 前

re-applied r78740 (Runtime: introduced RTRandAdvCreateOpenssl())

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 10.1 KB
 
1/** @file
2 * IPRT - Random Numbers and Byte Streams.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_rand_h
27#define ___iprt_rand_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31
32RT_C_DECLS_BEGIN
33
34/** @defgroup grp_rt_rand RTRand - Random Numbers and Byte Streams
35 * @ingroup grp_rt
36 * @{
37 */
38
39/**
40 * Fills a buffer with random bytes.
41 *
42 * @param pv Where to store the random bytes.
43 * @param cb Number of bytes to generate.
44 */
45RTDECL(void) RTRandBytes(void *pv, size_t cb) RT_NO_THROW;
46
47/**
48 * Generate a 32-bit signed random number in the set [i32First..i32Last].
49 *
50 * @returns The random number.
51 * @param i32First First number in the set.
52 * @param i32Last Last number in the set.
53 */
54RTDECL(int32_t) RTRandS32Ex(int32_t i32First, int32_t i32Last) RT_NO_THROW;
55
56/**
57 * Generate a 32-bit signed random number.
58 *
59 * @returns The random number.
60 */
61RTDECL(int32_t) RTRandS32(void) RT_NO_THROW;
62
63/**
64 * Generate a 32-bit unsigned random number in the set [u32First..u32Last].
65 *
66 * @returns The random number.
67 * @param u32First First number in the set.
68 * @param u32Last Last number in the set.
69 */
70RTDECL(uint32_t) RTRandU32Ex(uint32_t u32First, uint32_t u32Last) RT_NO_THROW;
71
72/**
73 * Generate a 32-bit unsigned random number.
74 *
75 * @returns The random number.
76 */
77RTDECL(uint32_t) RTRandU32(void) RT_NO_THROW;
78
79/**
80 * Generate a 64-bit signed random number in the set [i64First..i64Last].
81 *
82 * @returns The random number.
83 * @param i64First First number in the set.
84 * @param i64Last Last number in the set.
85 */
86RTDECL(int64_t) RTRandS64Ex(int64_t i64First, int64_t i64Last) RT_NO_THROW;
87
88/**
89 * Generate a 64-bit signed random number.
90 *
91 * @returns The random number.
92 */
93RTDECL(int64_t) RTRandS64(void) RT_NO_THROW;
94
95/**
96 * Generate a 64-bit unsigned random number in the set [u64First..u64Last].
97 *
98 * @returns The random number.
99 * @param u64First First number in the set.
100 * @param u64Last Last number in the set.
101 */
102RTDECL(uint64_t) RTRandU64Ex(uint64_t u64First, uint64_t u64Last) RT_NO_THROW;
103
104/**
105 * Generate a 64-bit unsigned random number.
106 *
107 * @returns The random number.
108 */
109RTDECL(uint64_t) RTRandU64(void) RT_NO_THROW;
110
111
112/**
113 * Create an instance of the default random number generator.
114 *
115 * @returns IPRT status code.
116 * @param phRand Where to return the handle to the new random number
117 * generator.
118 */
119RTDECL(int) RTRandAdvCreate(PRTRAND phRand) RT_NO_THROW;
120
121/**
122 * Create an instance of the default pseudo random number generator.
123 *
124 * @returns IPRT status code.
125 * @param phRand Where to store the handle to the generator.
126 */
127RTDECL(int) RTRandAdvCreatePseudo(PRTRAND phRand) RT_NO_THROW;
128
129/**
130 * Create an instance of the Park-Miller pseudo random number generator.
131 *
132 * @returns IPRT status code.
133 * @param phRand Where to store the handle to the generator.
134 */
135RTDECL(int) RTRandAdvCreateParkMiller(PRTRAND phRand) RT_NO_THROW;
136
137/**
138 * Create an instance of the faster random number generator for the OS.
139 *
140 * @returns IPRT status code.
141 * @retval VERR_NOT_SUPPORTED on platforms which doesn't have this feature.
142 * @retval VERR_FILE_NOT_FOUND on system where the random generator hasn't
143 * been installed or configured correctly.
144 * @retval VERR_PATH_NOT_FOUND for the same reasons as VERR_FILE_NOT_FOUND.
145 *
146 * @param phRand Where to store the handle to the generator.
147 *
148 * @remarks Think /dev/urandom.
149 */
150RTDECL(int) RTRandAdvCreateSystemFaster(PRTRAND phRand) RT_NO_THROW;
151
152/**
153 * Create an instance of the openssl random number generator.
154 *
155 * @returns IPRT status code.
156 * @retval VERR_NOT_SUPPORTED on platforms which doesn't have this feature.
157 *
158 * @param phRand Where to store the handle to the generator.
159 *
160 */
161RTDECL(int) RTRandAdvCreateOpenssl(PRTRAND phRand) RT_NO_THROW;
162
163/**
164 * Create an instance of the truer random number generator for the OS.
165 *
166 * Don't use this unless you seriously need good random numbers because most
167 * systems will have will have problems producing sufficient entropy for this
168 * and you'll end up blocking while it accumulates.
169 *
170 * @returns IPRT status code.
171 * @retval VERR_NOT_SUPPORTED on platforms which doesn't have this feature.
172 * @retval VERR_FILE_NOT_FOUND on system where the random generator hasn't
173 * been installed or configured correctly.
174 * @retval VERR_PATH_NOT_FOUND for the same reasons as VERR_FILE_NOT_FOUND.
175 *
176 * @param phRand Where to store the handle to the generator.
177 *
178 * @remarks Think /dev/random.
179 */
180RTDECL(int) RTRandAdvCreateSystemTruer(PRTRAND phRand) RT_NO_THROW;
181
182/**
183 * Destroys a random number generator.
184 *
185 * @returns IPRT status code.
186 * @param hRand Handle to the random number generator.
187 */
188RTDECL(int) RTRandAdvDestroy(RTRAND hRand) RT_NO_THROW;
189
190/**
191 * Generic method for seeding of a random number generator.
192 *
193 * The different generators may have specialized methods for
194 * seeding, use one of those if you desire better control
195 * over the result.
196 *
197 * @returns IPRT status code.
198 * @retval VERR_NOT_SUPPORTED if it isn't a pseudo generator.
199 *
200 * @param hRand Handle to the random number generator.
201 * @param u64Seed Seed.
202 */
203RTDECL(int) RTRandAdvSeed(RTRAND hRand, uint64_t u64Seed) RT_NO_THROW;
204
205/**
206 * Save the current state of a pseudo generator.
207 *
208 * This can be use to save the state so it can later be resumed at the same
209 * position.
210 *
211 * @returns IPRT status code.
212 * @retval VINF_SUCCESS on success. *pcbState contains the length of the
213 * returned string and pszState contains the state string.
214 * @retval VERR_BUFFER_OVERFLOW if the supplied buffer is too small. *pcbState
215 * will contain the necessary buffer size.
216 * @retval VERR_NOT_SUPPORTED by non-psuedo generators.
217 *
218 * @param hRand Handle to the random number generator.
219 * @param pszState Where to store the state. The returned string will be
220 * null terminated and printable.
221 * @param pcbState The size of the buffer pszState points to on input, the
222 * size required / used on return (including the
223 * terminator, thus the 'cb' instead of 'cch').
224 */
225RTDECL(int) RTRandAdvSaveState(RTRAND hRand, char *pszState, size_t *pcbState) RT_NO_THROW;
226
227/**
228 * Restores the state of a pseudo generator.
229 *
230 * The state must have been obtained using RTRandAdvGetState.
231 *
232 * @returns IPRT status code.
233 * @retval VERR_PARSE_ERROR if the state string is malformed.
234 * @retval VERR_NOT_SUPPORTED by non-psuedo generators.
235 *
236 * @param hRand Handle to the random number generator.
237 * @param pszState The state to load.
238 */
239RTDECL(int) RTRandAdvRestoreState(RTRAND hRand, char const *pszState) RT_NO_THROW;
240
241/**
242 * Fills a buffer with random bytes.
243 *
244 * @param hRand Handle to the random number generator.
245 * @param pv Where to store the random bytes.
246 * @param cb Number of bytes to generate.
247 */
248RTDECL(void) RTRandAdvBytes(RTRAND hRand, void *pv, size_t cb) RT_NO_THROW;
249
250/**
251 * Generate a 32-bit signed random number in the set [i32First..i32Last].
252 *
253 * @returns The random number.
254 * @param hRand Handle to the random number generator.
255 * @param i32First First number in the set.
256 * @param i32Last Last number in the set.
257 */
258RTDECL(int32_t) RTRandAdvS32Ex(RTRAND hRand, int32_t i32First, int32_t i32Last) RT_NO_THROW;
259
260/**
261 * Generate a 32-bit signed random number.
262 *
263 * @returns The random number.
264 * @param hRand Handle to the random number generator.
265 */
266RTDECL(int32_t) RTRandAdvS32(RTRAND hRand) RT_NO_THROW;
267
268/**
269 * Generate a 32-bit unsigned random number in the set [u32First..u32Last].
270 *
271 * @returns The random number.
272 * @param hRand Handle to the random number generator.
273 * @param u32First First number in the set.
274 * @param u32Last Last number in the set.
275 */
276RTDECL(uint32_t) RTRandAdvU32Ex(RTRAND hRand, uint32_t u32First, uint32_t u32Last) RT_NO_THROW;
277
278/**
279 * Generate a 32-bit unsigned random number.
280 *
281 * @returns The random number.
282 * @param hRand Handle to the random number generator.
283 */
284RTDECL(uint32_t) RTRandAdvU32(RTRAND hRand) RT_NO_THROW;
285
286/**
287 * Generate a 64-bit signed random number in the set [i64First..i64Last].
288 *
289 * @returns The random number.
290 * @param hRand Handle to the random number generator.
291 * @param i64First First number in the set.
292 * @param i64Last Last number in the set.
293 */
294RTDECL(int64_t) RTRandAdvS64Ex(RTRAND hRand, int64_t i64First, int64_t i64Last) RT_NO_THROW;
295
296/**
297 * Generate a 64-bit signed random number.
298 *
299 * @returns The random number.
300 */
301RTDECL(int64_t) RTRandAdvS64(RTRAND hRand) RT_NO_THROW;
302
303/**
304 * Generate a 64-bit unsigned random number in the set [u64First..u64Last].
305 *
306 * @returns The random number.
307 * @param hRand Handle to the random number generator.
308 * @param u64First First number in the set.
309 * @param u64Last Last number in the set.
310 */
311RTDECL(uint64_t) RTRandAdvU64Ex(RTRAND hRand, uint64_t u64First, uint64_t u64Last) RT_NO_THROW;
312
313/**
314 * Generate a 64-bit unsigned random number.
315 *
316 * @returns The random number.
317 * @param hRand Handle to the random number generator.
318 */
319RTDECL(uint64_t) RTRandAdvU64(RTRAND hRand) RT_NO_THROW;
320
321
322/** @} */
323
324RT_C_DECLS_END
325
326
327#endif
328
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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