1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | |
6 | |
7 | /* |
8 | ** prrng.h -- NSPR Random Number Generator |
9 | ** |
10 | ** |
11 | ** lth. 29-Oct-1999. |
12 | */ |
13 | |
14 | #ifndef prrng_h___ |
15 | #define prrng_h___ |
16 | |
17 | #include "prtypes.h" |
18 | |
19 | PR_BEGIN_EXTERN_C |
20 | |
21 | /* |
22 | ** PR_GetRandomNoise() -- Get random noise from the host platform |
23 | ** |
24 | ** Description: |
25 | ** PR_GetRandomNoise() provides, depending on platform, a random value. |
26 | ** The length of the random value is dependent on platform and the |
27 | ** platform's ability to provide a random value at that moment. |
28 | ** |
29 | ** The intent of PR_GetRandomNoise() is to provide a "seed" value for a |
30 | ** another random number generator that may be suitable for |
31 | ** cryptographic operations. This implies that the random value |
32 | ** provided may not be, by itself, cryptographically secure. The value |
33 | ** generated by PR_GetRandomNoise() is at best, extremely difficult to |
34 | ** predict and is as non-deterministic as the underlying platfrom can |
35 | ** provide. |
36 | ** |
37 | ** Inputs: |
38 | ** buf -- pointer to a caller supplied buffer to contain the |
39 | ** generated random number. buf must be at least as large as |
40 | ** is specified in the 'size' argument. |
41 | ** |
42 | ** size -- the requested size of the generated random number |
43 | ** |
44 | ** Outputs: |
45 | ** a random number provided in 'buf'. |
46 | ** |
47 | ** Returns: |
48 | ** PRSize value equal to the size of the random number actually |
49 | ** generated, or zero. The generated size may be less than the size |
50 | ** requested. A return value of zero means that PR_GetRandomNoise() is |
51 | ** not implemented on this platform, or there is no available noise |
52 | ** available to be returned at the time of the call. |
53 | ** |
54 | ** Restrictions: |
55 | ** Calls to PR_GetRandomNoise() may use a lot of CPU on some platforms. |
56 | ** Some platforms may block for up to a few seconds while they |
57 | ** accumulate some noise. Busy machines generate lots of noise, but |
58 | ** care is advised when using PR_GetRandomNoise() frequently in your |
59 | ** application. |
60 | ** |
61 | ** History: |
62 | ** Parts of the model dependent implementation for PR_GetRandomNoise() |
63 | ** were taken in whole or part from code previously in Netscape's NSS |
64 | ** component. |
65 | ** |
66 | */ |
67 | NSPR_API(PRSize) PR_GetRandomNoise( |
68 | void *buf, |
69 | PRSize size |
70 | ); |
71 | |
72 | PR_END_EXTERN_C |
73 | |
74 | #endif /* prrng_h___ */ |
75 | /* end prrng.h */ |
76 | |