/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* This is not very good */
si = sysconf(_AES_OS_VERSION);
RNG_RandomUpdate(&si, sizeof(si));
si = sysconf(_SC_CPU_VERSION);
RNG_RandomUpdate(&si, sizeof(si));
} #endif/* HPUX */
/* Give in system information */ if (gethostname(buf, sizeof(buf)) == 0) {
RNG_RandomUpdate(buf, strlen(buf));
}
/* grab some data from system's PRNG before any other files. */
bytes = RNG_FileUpdate("/dev/urandom", SYSTEM_RNG_SEED_COUNT); if (!bytes) {
PORT_SetError(SEC_ERROR_NEED_RANDOM);
}
/* If the user points us to a random file, pass it through the rng */
randfile = PR_GetEnvSecure("NSRANDFILE"); if ((randfile != NULL) && (randfile[0] != '\0')) { char *randCountString = PR_GetEnvSecure("NSRANDCOUNT"); int randCount = randCountString ? atoi(randCountString) : 0; if (randCount != 0) {
RNG_FileUpdate(randfile, randCount);
} else {
RNG_FileForRNG(randfile);
}
}
/* pass other files through */ for (cp = files; *cp; cp++)
RNG_FileForRNG(*cp);
#ifdef SOLARIS if (!bytes) { /* On Solaris 8, /dev/urandom isn't available, so we use libkstat. */
PRUint32 kstat_bytes = 0; if (SECSuccess != RNG_kstat(&kstat_bytes)) {
PORT_Assert(0);
}
bytes += kstat_bytes;
PORT_Assert(bytes);
} #endif
}
#define TOTAL_FILE_LIMIT 1000000/* one million */
size_t
RNG_FileUpdate(constchar *fileName, size_t limit)
{
FILE *file; int fd; int bytes;
size_t fileBytes = 0; struct stat stat_buf; unsignedchar buffer[BUFSIZ]; static size_t totalFileBytes = 0;
/* suppress valgrind warnings due to holes in struct stat */
memset(&stat_buf, 0, sizeof(stat_buf));
if (stat((char *)fileName, &stat_buf) < 0) return fileBytes;
RNG_RandomUpdate(&stat_buf, sizeof(stat_buf));
file = fopen(fileName, "r"); if (file != NULL) { /* Read from the underlying file descriptor directly to bypass stdio *bufferingandavoidreadingmorebytesthanweneedfrom */dev/urandom.NOTE:wecan'tusefreadwithunbufferedI/Obecause *freadmayreturnEOFinunbufferedI/OmodeonAndroid. * *Moreover,wereadintoabufferofsizeBUFSIZ,sobufferedI/O
* has no performance advantage. */
fd = fileno(file); /* 'file' was just opened, so this should not fail. */
PORT_Assert(fd != -1); while (limit > fileBytes && fd != -1) {
bytes = PR_MIN(sizeof buffer, limit - fileBytes);
bytes = read(fd, buffer, bytes); if (bytes <= 0) break;
RNG_RandomUpdate(buffer, bytes);
fileBytes += bytes;
totalFileBytes += bytes; /* after TOTAL_FILE_LIMIT has been reached, only read in first **bufferofdatafromeachsubsequentfile.
*/ if (totalFileBytes > TOTAL_FILE_LIMIT) break;
}
fclose(file);
} /* *Passyetanothersnapshotofourhighestresolutionclockinto *thehashfunction.
*/
bytes = RNG_GetNoise(buffer, sizeof(buffer));
RNG_RandomUpdate(buffer, bytes); return fileBytes;
}
PRBool
ReadFileOK(char *dir, char *file)
{ struct stat stat_buf; char filename[PATH_MAX]; int count = snprintf(filename, sizeof filename, "%s/%s", dir, file);
if (count <= 0) { return PR_FALSE; /* name too long, can't read it anyway */
}
if (stat(filename, &stat_buf) < 0) return PR_FALSE; /* can't stat, probably can't read it then as well */ return S_ISREG(stat_buf.st_mode) ? PR_TRUE : PR_FALSE;
}
size_t
RNG_SystemRNG(void *dest, size_t maxLen)
{
FILE *file; int fd; int bytes;
size_t fileBytes = 0; unsignedchar *buffer = dest;
file = fopen("/dev/urandom", "r"); if (file == NULL) {
PORT_SetError(SEC_ERROR_NEED_RANDOM); return0;
} /* Read from the underlying file descriptor directly to bypass stdio *bufferingandavoidreadingmorebytesthanweneedfrom/dev/urandom. *NOTE:wecan'tusefreadwithunbufferedI/Obecausefreadmayreturn *EOFinunbufferedI/OmodeonAndroid.
*/
fd = fileno(file); /* 'file' was just opened, so this should not fail. */
PORT_Assert(fd != -1); while (maxLen > fileBytes && fd != -1) {
bytes = maxLen - fileBytes;
bytes = read(fd, buffer, bytes); if (bytes <= 0) break;
fileBytes += bytes;
buffer += bytes;
}
fclose(file); if (fileBytes != maxLen) {
PORT_SetError(SEC_ERROR_NEED_RANDOM); /* system RNG failed */
fileBytes = 0;
} return fileBytes;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.