Ejemplo n.º 1
0
/*
 * This function is called on every keypress or mouse move, and
 * will add the current time to the noise pool. It gets the scan
 * code or mouse position passed in, and adds that too.
 */
void noise_ultralight(NoiseSourceId id, unsigned long data)
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    random_add_noise(NOISE_SOURCE_TIME, &tv, sizeof(tv));
    random_add_noise(id, &data, sizeof(data));
}
Ejemplo n.º 2
0
void random_initialize(RandomState * state, uid_t uid, const char *filename)
{
    char buf[8192];
    int bytes;
    UserFile uf;

    state->add_position = 0;
    state->next_available_byte = sizeof(state->stir_key);
    state->last_dev_random_usage = 0;

    /* This isn't strictly necessary, but will keep programs like 3rd degree or
       purify silent. */
    memset(state->state, 0, sizeof(state->state));

    /* Get noise from the file. */
    random_add_noise(state, filename, strlen(filename));        /* Use the path. */
    uf = userfile_open(uid, filename, O_RDONLY, 0);
    if (uf != NULL) {
        state->state[0] += (int) uf;
        bytes = userfile_read(uf, buf, sizeof(buf));
        userfile_close(uf);
        if (bytes > 0)
            random_add_noise(state, buf, bytes);
        memset(buf, 0, sizeof(buf));
    } else {
        /* Get all possible noise since we have no seed. */
        random_acquire_environmental_noise(state, uid);
        random_save(state, uid, filename);
    }

    /* Get easily available noise from the environment. */
    random_acquire_light_environmental_noise(state);
}
Ejemplo n.º 3
0
/*
 * This function is called on every keypress or mouse move, and
 * will add the current time to the noise pool. It gets the scan
 * code or mouse position passed in, and adds that too.
 */
void noise_ultralight(unsigned long data)
{
    UnsignedWide utc;

    Microseconds(&utc);
    random_add_noise(&utc, sizeof(utc));
    random_add_noise(&data, sizeof(data));
}
Ejemplo n.º 4
0
Archivo: noise.c Proyecto: rdebath/sgt
/*
 * This function is called on every keypress or mouse move, and
 * will add the current Windows time and performance monitor
 * counter to the noise pool. It gets the scan code or mouse
 * position passed in.
 */
void noise_ultralight(DWORD data) {
    DWORD wintime;
    LARGE_INTEGER perftime;

    random_add_noise(&data, sizeof(DWORD));

    wintime = GetTickCount();
    random_add_noise(&wintime, sizeof(DWORD));

    if (QueryPerformanceCounter(&perftime))
	random_add_noise(&perftime, sizeof(perftime));
}
Ejemplo n.º 5
0
/*
 * This function is called on every keypress or mouse move, and
 * will add the current Windows time and performance monitor
 * counter to the noise pool. It gets the scan code or mouse
 * position passed in.
 */
void noise_ultralight(NoiseSourceId id, unsigned long data)
{
    DWORD wintime;
    LARGE_INTEGER perftime;

    random_add_noise(id, &data, sizeof(DWORD));

    wintime = GetTickCount();
    random_add_noise(NOISE_SOURCE_TIME, &wintime, sizeof(DWORD));

    if (QueryPerformanceCounter(&perftime))
	random_add_noise(NOISE_SOURCE_PERFCOUNT, &perftime, sizeof(perftime));
}
Ejemplo n.º 6
0
/*
 * This function is called on a timer, and it will monitor
 * frequently changing quantities such as the state of physical and
 * virtual memory, the state of the process's message queue, which
 * window is in the foreground, which owns the clipboard, etc.
 */
void noise_regular(void)
{
    HWND w;
    DWORD z;
    POINT pt;
    MEMORYSTATUS memstat;
    FILETIME times[4];

    w = GetForegroundWindow();
    random_add_noise(NOISE_SOURCE_FGWINDOW, &w, sizeof(w));
    w = GetCapture();
    random_add_noise(NOISE_SOURCE_CAPTURE, &w, sizeof(w));
    w = GetClipboardOwner();
    random_add_noise(NOISE_SOURCE_CLIPBOARD, &w, sizeof(w));
    z = GetQueueStatus(QS_ALLEVENTS);
    random_add_noise(NOISE_SOURCE_QUEUE, &z, sizeof(z));

    GetCursorPos(&pt);
    random_add_noise(NOISE_SOURCE_CURSORPOS, &pt, sizeof(pt));

    GlobalMemoryStatus(&memstat);
    random_add_noise(NOISE_SOURCE_MEMINFO, &memstat, sizeof(memstat));

    GetThreadTimes(GetCurrentThread(), times, times + 1, times + 2,
		   times + 3);
    random_add_noise(NOISE_SOURCE_THREADTIME, &times, sizeof(times));
    GetProcessTimes(GetCurrentProcess(), times, times + 1, times + 2,
		    times + 3);
    random_add_noise(NOISE_SOURCE_PROCTIME, &times, sizeof(times));
}
Ejemplo n.º 7
0
Archivo: noise.c Proyecto: rdebath/sgt
/*
 * This function is called on a timer, and it will monitor
 * frequently changing quantities such as the state of physical and
 * virtual memory, the state of the process's message queue, which
 * window is in the foreground, which owns the clipboard, etc.
 */
void noise_regular(void)
{
    HWND w;
    DWORD z;
    POINT pt;
    MEMORYSTATUS memstat;
    FILETIME times[4];

    w = GetForegroundWindow();
    random_add_noise(&w, sizeof(w));
    w = GetCapture();
    random_add_noise(&w, sizeof(w));
    w = GetClipboardOwner();
    random_add_noise(&w, sizeof(w));
    z = GetQueueStatus(QS_ALLEVENTS);
    random_add_noise(&z, sizeof(z));

    GetCursorPos(&pt);
    random_add_noise(&pt, sizeof(pt));

    GlobalMemoryStatus(&memstat);
    random_add_noise(&memstat, sizeof(memstat));

    GetThreadTimes(GetCurrentThread(), times, times + 1, times + 2,
		   times + 3);
    random_add_noise(&times, sizeof(times));
    GetProcessTimes(GetCurrentProcess(), times, times + 1, times + 2,
		    times + 3);
    random_add_noise(&times, sizeof(times));
}
Ejemplo n.º 8
0
/*
 * This function is called on every keypress or mouse move, and
 * will add the current Windows time and performance monitor
 * counter to the noise pool. It gets the scan code or mouse
 * position passed in.
 */
void noise_ultralight(unsigned long data)
{
    DWORD wintime;
    LARGE_INTEGER perftime;

    MPEXT_PUTTY_SECTION_ENTER;
    random_add_noise(&data, sizeof(DWORD));

    wintime = GetTickCount();
    random_add_noise(&wintime, sizeof(DWORD));

    if (QueryPerformanceCounter(&perftime))
	random_add_noise(&perftime, sizeof(perftime));
    MPEXT_PUTTY_SECTION_LEAVE;
}
Ejemplo n.º 9
0
/*
 * This function is called on every keypress or mouse move, and
 * will add the current Windows time and performance monitor
 * counter to the noise pool. It gets the scan code or mouse
 * position passed in.
 */
void noise_ultralight(unsigned long data)
{
    DWORD wintime;
    LARGE_INTEGER perftime;

#ifdef MPEXT
    EnterCriticalSection(&noise_section);
#endif
    random_add_noise(&data, sizeof(DWORD));

    wintime = GetTickCount();
    random_add_noise(&wintime, sizeof(DWORD));

    if (QueryPerformanceCounter(&perftime))
	random_add_noise(&perftime, sizeof(perftime));
#ifdef MPEXT
    LeaveCriticalSection(&noise_section);
#endif
}
Ejemplo n.º 10
0
/*
 * This function is called on a timer, and grabs as much changeable
 * system data as it can quickly get its hands on.
 */
void noise_regular(void)
{
    int fd;
    int ret;
    char buf[512];
    struct rusage rusage;

    if ((fd = open("/proc/meminfo", O_RDONLY)) >= 0) {
	while ( (ret = read(fd, buf, sizeof(buf))) > 0)
	    random_add_noise(NOISE_SOURCE_MEMINFO, buf, ret);
	close(fd);
    }
    if ((fd = open("/proc/stat", O_RDONLY)) >= 0) {
	while ( (ret = read(fd, buf, sizeof(buf))) > 0)
	    random_add_noise(NOISE_SOURCE_STAT, buf, ret);
	close(fd);
    }
    getrusage(RUSAGE_SELF, &rusage);
    random_add_noise(NOISE_SOURCE_RUSAGE, &rusage, sizeof(rusage));
}
Ejemplo n.º 11
0
void random_get_noise_from_command(RandomState * state, uid_t uid, const char *cmd)
{
    char line[1000];
    UserFile uf;

    uf = userfile_popen(uid, cmd, "r");
    if (uf == NULL)
        return;
    while (userfile_gets(line, sizeof(line), uf))
        random_add_noise(state, line, strlen(line));
    userfile_pclose(uf);
    memset(line, 0, sizeof(line));
}
Ejemplo n.º 12
0
void Profile::InitGeneralData()
{
	// Init m_iGuid.
	// Does the RNG need to be inited and seeded every time?
	random_init();
	random_add_noise( "ai8049ujr3odusj" );
	
	{
		m_sGuid = "";
		for( unsigned i=0; i<GUID_SIZE_BYTES; i++ )
			m_sGuid += ssprintf( "%02x", random_byte() );
	}


	m_bUsingProfileDefaultModifiers = false;
	m_sDefaultModifiers = "";
	m_SortOrder = SORT_INVALID;
	m_LastDifficulty = DIFFICULTY_INVALID;
	m_LastCourseDifficulty = DIFFICULTY_INVALID;
	m_lastSong.Unset();
	m_lastCourse.Unset();
	m_iTotalPlays = 0;
	m_iTotalPlaySeconds = 0;
	m_iTotalGameplaySeconds = 0;
	m_iCurrentCombo = 0;
	m_fTotalCaloriesBurned = 0;
	m_iTotalDancePoints = 0;
	m_iNumExtraStagesPassed = 0;
	m_iNumExtraStagesFailed = 0;
	m_iNumToasties = 0;
	m_UnlockedSongs.clear();
	m_sLastPlayedMachineGuid = "";
	m_LastPlayedDate.Init();
	m_iTotalTapsAndHolds = 0;
	m_iTotalJumps = 0;
	m_iTotalHolds = 0;
	m_iTotalMines = 0;
	m_iTotalHands = 0;

	int i;
	for( i=0; i<NUM_PLAY_MODES; i++ )
		m_iNumSongsPlayedByPlayMode[i] = 0;
	m_iNumSongsPlayedByStyle.clear();
	for( i=0; i<NUM_DIFFICULTIES; i++ )
		m_iNumSongsPlayedByDifficulty[i] = 0;
	for( i=0; i<MAX_METER+1; i++ )
		m_iNumSongsPlayedByMeter[i] = 0;
	ZERO( m_iNumStagesPassedByPlayMode );
	ZERO( m_iNumStagesPassedByGrade );
}
Ejemplo n.º 13
0
void random_acquire_light_environmental_noise(RandomState * state)
{
    int f;
    char buf[32];
    int len;

    /* Stir first to make all bits depend on all other bits (some of
       them not revealed to callers). */
    random_stir(state);

    /* About every five minutes, mix in some noise from /dev/random. */
    if (time(NULL) - state->last_dev_random_usage > 5 * 60) {
        state->last_dev_random_usage = time(NULL);

        /* If /dev/random is available, read some data from there in non-blocking
           mode and mix it into the pool. */
        f = open("/dev/random", O_RDONLY);
        if (f >= 0) {
            /* Set the descriptor into non-blocking mode. */
#if defined(O_NONBLOCK) && !defined(O_NONBLOCK_BROKEN)
            fcntl(f, F_SETFL, O_NONBLOCK);
#else                           /* O_NONBLOCK && !O_NONBLOCK_BROKEN */
            fcntl(f, F_SETFL, O_NDELAY);
#endif                          /* O_NONBLOCK && !O_NONBLOCK_BROKEN */
            len = read(f, buf, sizeof(buf));
            close(f);
            if (len > 0)
                random_add_noise(state, buf, len);
        }
    }

    /* Get miscellaneous noise from various system parameters and statistics. */
    random_xor_noise(state, (unsigned int) (state->state[0] + 256 * state->state[1]) % (RANDOM_STATE_BYTES / 4), (word32) time(NULL));

#ifdef HAVE_GETTIMEOFDAY
    {
        struct timeval tv;

#ifdef HAVE_NO_TZ_IN_GETTIMEOFDAY
        gettimeofday(&tv);
#else
        gettimeofday(&tv, NULL);
#endif
        random_xor_noise(state, 0, (word32) tv.tv_usec);
        random_xor_noise(state, 1, (word32) tv.tv_sec);
#ifdef HAVE_CLOCK
        random_xor_noise(state, 3, (word32) clock());
#endif                          /* HAVE_CLOCK */
    }
#endif                          /* HAVE_GETTIMEOFDAY */
#ifdef HAVE_TIMES
    {
        struct tms tm;

        random_xor_noise(state, 2, (word32) times(&tm));
        random_xor_noise(state, 4, (word32) (tm.tms_utime ^ (tm.tms_stime << 8) ^ (tm.tms_cutime << 16) ^ (tm.tms_cstime << 24)));
    }
#endif                          /* HAVE_TIMES */
#ifdef HAVE_GETRUSAGE
    {
        struct rusage ru, cru;

        getrusage(RUSAGE_SELF, &ru);
        getrusage(RUSAGE_CHILDREN, &cru);
        random_xor_noise(state, 0, (word32) (ru.ru_utime.tv_usec + cru.ru_utime.tv_usec));
        random_xor_noise(state, 2, (word32) (ru.ru_stime.tv_usec + cru.ru_stime.tv_usec));
        random_xor_noise(state, 5, (word32) (ru.ru_maxrss + cru.ru_maxrss));
        random_xor_noise(state, 6, (word32) (ru.ru_ixrss + cru.ru_ixrss));
        random_xor_noise(state, 7, (word32) (ru.ru_idrss + cru.ru_idrss));
        random_xor_noise(state, 8, (word32) (ru.ru_minflt + cru.ru_minflt));
        random_xor_noise(state, 9, (word32) (ru.ru_majflt + cru.ru_majflt));
        random_xor_noise(state, 10, (word32) (ru.ru_nswap + cru.ru_nswap));
        random_xor_noise(state, 11, (word32) (ru.ru_inblock + cru.ru_inblock));
        random_xor_noise(state, 12, (word32) (ru.ru_oublock + cru.ru_oublock));
        random_xor_noise(state, 13, (word32) ((ru.ru_msgsnd ^ ru.ru_msgrcv ^ ru.ru_nsignals) + (cru.ru_msgsnd ^ cru.ru_msgrcv ^ cru.ru_nsignals)));
        random_xor_noise(state, 14, (word32) (ru.ru_nvcsw + cru.ru_nvcsw));
        random_xor_noise(state, 15, (word32) (ru.ru_nivcsw + cru.ru_nivcsw));
    }
#endif                          /* HAVE_GETRUSAGE */
    random_xor_noise(state, 11, (word32) getpid());
    random_xor_noise(state, 12, (word32) getppid());
    random_xor_noise(state, 10, (word32) getuid());
    random_xor_noise(state, 10, (word32) (getgid() << 16));
#ifdef _POSIX_CHILD_MAX
    random_xor_noise(state, 13, (word32) (_POSIX_CHILD_MAX << 16));
#endif                          /* _POSIX_CHILD_MAX */
#ifdef CLK_TCK
    random_xor_noise(state, 14, (word32) (CLK_TCK << 16));
#endif                          /* CLK_TCK */

    random_stir(state);
}