Back to index

lightning-sunbird  0.9+nobinonly
Functions
w32rng.c File Reference
#include <windows.h>
#include <time.h>
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <primpl.h>

Go to the source code of this file.

Functions

static BOOL CurrentClockTickTime (LPDWORD lpdwHigh, LPDWORD lpdwLow)
PRSize _PR_MD_GetRandomNoise (void *buf, PRSize size)

Function Documentation

PRSize _PR_MD_GetRandomNoise ( void buf,
PRSize  size 
)

Definition at line 59 of file w32rng.c.

{
    DWORD   dwHigh, dwLow, dwVal;
    int     n = 0;
    int     nBytes;
    time_t  sTime;

    if (size <= 0)
        return 0;

    CurrentClockTickTime(&dwHigh, &dwLow);

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

    if (size <= 0)
        return n;

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

    if (size <= 0)
        return n;

    // get the number of milliseconds that have elapsed since Windows started
    dwVal = GetTickCount();

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

    if (size <= 0)
        return n;

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

    return n;
}

Here is the call graph for this function:

static BOOL CurrentClockTickTime ( LPDWORD  lpdwHigh,
LPDWORD  lpdwLow 
) [static]

Definition at line 47 of file w32rng.c.

{
    LARGE_INTEGER   liCount;

    if (!QueryPerformanceCounter(&liCount))
        return FALSE;

    *lpdwHigh = liCount.u.HighPart;
    *lpdwLow = liCount.u.LowPart;
    return TRUE;
}

Here is the caller graph for this function: