nsprpub/pr/include/prrng.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     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/. */
     7 /*
     8 ** prrng.h -- NSPR Random Number Generator
     9 ** 
    10 **
    11 ** lth. 29-Oct-1999.
    12 */
    14 #ifndef prrng_h___ 
    15 #define prrng_h___
    17 #include "prtypes.h"
    19 PR_BEGIN_EXTERN_C
    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 );
    72 PR_END_EXTERN_C
    74 #endif /* prrng_h___ */
    75 /* end prrng.h */

mercurial