michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /* michael@0: ** prrng.h -- NSPR Random Number Generator michael@0: ** michael@0: ** michael@0: ** lth. 29-Oct-1999. michael@0: */ michael@0: michael@0: #ifndef prrng_h___ michael@0: #define prrng_h___ michael@0: michael@0: #include "prtypes.h" michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: /* michael@0: ** PR_GetRandomNoise() -- Get random noise from the host platform michael@0: ** michael@0: ** Description: michael@0: ** PR_GetRandomNoise() provides, depending on platform, a random value. michael@0: ** The length of the random value is dependent on platform and the michael@0: ** platform's ability to provide a random value at that moment. michael@0: ** michael@0: ** The intent of PR_GetRandomNoise() is to provide a "seed" value for a michael@0: ** another random number generator that may be suitable for michael@0: ** cryptographic operations. This implies that the random value michael@0: ** provided may not be, by itself, cryptographically secure. The value michael@0: ** generated by PR_GetRandomNoise() is at best, extremely difficult to michael@0: ** predict and is as non-deterministic as the underlying platfrom can michael@0: ** provide. michael@0: ** michael@0: ** Inputs: michael@0: ** buf -- pointer to a caller supplied buffer to contain the michael@0: ** generated random number. buf must be at least as large as michael@0: ** is specified in the 'size' argument. michael@0: ** michael@0: ** size -- the requested size of the generated random number michael@0: ** michael@0: ** Outputs: michael@0: ** a random number provided in 'buf'. michael@0: ** michael@0: ** Returns: michael@0: ** PRSize value equal to the size of the random number actually michael@0: ** generated, or zero. The generated size may be less than the size michael@0: ** requested. A return value of zero means that PR_GetRandomNoise() is michael@0: ** not implemented on this platform, or there is no available noise michael@0: ** available to be returned at the time of the call. michael@0: ** michael@0: ** Restrictions: michael@0: ** Calls to PR_GetRandomNoise() may use a lot of CPU on some platforms. michael@0: ** Some platforms may block for up to a few seconds while they michael@0: ** accumulate some noise. Busy machines generate lots of noise, but michael@0: ** care is advised when using PR_GetRandomNoise() frequently in your michael@0: ** application. michael@0: ** michael@0: ** History: michael@0: ** Parts of the model dependent implementation for PR_GetRandomNoise() michael@0: ** were taken in whole or part from code previously in Netscape's NSS michael@0: ** component. michael@0: ** michael@0: */ michael@0: NSPR_API(PRSize) PR_GetRandomNoise( michael@0: void *buf, michael@0: PRSize size michael@0: ); michael@0: michael@0: PR_END_EXTERN_C michael@0: michael@0: #endif /* prrng_h___ */ michael@0: /* end prrng.h */