Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
secrng.h File Reference
#include "blapi.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define SYSTEM_RNG_SEED_COUNT   1024

Functions

SEC_BEGIN_PROTOS size_t RNG_GetNoise (void *buf, size_t maxbytes)
void RNG_SystemInfoForRNG (void)
void RNG_FileForRNG (const char *filename)
size_t RNG_SystemRNG (void *buf, size_t maxbytes)

Define Documentation

Definition at line 55 of file secrng.h.


Function Documentation

void RNG_FileForRNG ( const char *  filename)

Definition at line 301 of file os2_rand.c.

{
    struct stat stat_buf;
    unsigned char buffer[1024];
    FILE *file = 0;
    int nBytes = 0;
    static int totalFileBytes = 0;
    
    if (stat((char *)filename, &stat_buf) < 0)
       return;

    RNG_RandomUpdate((unsigned char*)&stat_buf, sizeof(stat_buf));
    
    file = fopen((char *)filename, "r");
    if (file != NULL)
    {
       for (;;)
       {
           size_t bytes = fread(buffer, 1, sizeof(buffer), file);

           if (bytes == 0)
              break;

           RNG_RandomUpdate(buffer, bytes);
           totalFileBytes += bytes;
           if (totalFileBytes > 250000)
              break;
       }
       fclose(file);
    }

    nBytes = RNG_GetNoise(buffer, 20); 
    RNG_RandomUpdate(buffer, nBytes);
}

Here is the call graph for this function:

Here is the caller graph for this function:

SEC_BEGIN_PROTOS size_t RNG_GetNoise ( void buf,
size_t  maxbytes 
)

Definition at line 62 of file os2_rand.c.

{
    unsigned long high = 0;
    unsigned long low  = 0;
    clock_t val = 0;
    int n = 0;
    int nBytes = 0;
    time_t sTime;

    if (maxbuf <= 0)
       return 0;

    clockTickTime(&high, &low);

    /* get the maximally changing bits first */
    nBytes = sizeof(low) > maxbuf ? maxbuf : sizeof(low);
    memcpy(buf, &low, nBytes);
    n += nBytes;
    maxbuf -= nBytes;

    if (maxbuf <= 0)
       return n;

    nBytes = sizeof(high) > maxbuf ? maxbuf : sizeof(high);
    memcpy(((char *)buf) + n, &high, nBytes);
    n += nBytes;
    maxbuf -= nBytes;

    if (maxbuf <= 0)
       return n;

    /* get the number of milliseconds that have elapsed since application started */
    val = clock();

    nBytes = sizeof(val) > maxbuf ? maxbuf : sizeof(val);
    memcpy(((char *)buf) + n, &val, nBytes);
    n += nBytes;
    maxbuf -= nBytes;

    if (maxbuf <= 0)
       return n;

    /* get the time in seconds since midnight Jan 1, 1970 */
    time(&sTime);
    nBytes = sizeof(sTime) > maxbuf ? maxbuf : sizeof(sTime);
    memcpy(((char *)buf) + n, &sTime, nBytes);
    n += nBytes;

    return n;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1632 of file loader.c.

{
  if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
      return ;
  (vector->p_RNG_SystemInfoForRNG)();

}

Here is the call graph for this function:

size_t RNG_SystemRNG ( void buf,
size_t  maxbytes 
)

Definition at line 336 of file os2_rand.c.

Here is the call graph for this function:

Here is the caller graph for this function: