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