MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlInitRandom

Function xmlInitRandom

ThirdParty/libxml2/vtklibxml2/dict.c:951–990  ·  view source on GitHub ↗

* xmlInitRandom: * * Initialize the PRNG. */

Source from the content-addressed store, hash-verified

949 * Initialize the PRNG.
950 */
951ATTRIBUTE_NO_SANITIZE_INTEGER
952void
953xmlInitRandom(void) {
954 xmlInitMutex(&xmlRngMutex);
955
956 {
957#ifdef _WIN32
958 NTSTATUS status;
959
960 status = BCryptGenRandom(NULL, (unsigned char *) globalRngState,
961 sizeof(globalRngState),
962 BCRYPT_USE_SYSTEM_PREFERRED_RNG);
963 if (!BCRYPT_SUCCESS(status)) {
964 fprintf(stderr, "libxml2: BCryptGenRandom failed with "
965 "error code %lu\n", GetLastError());
966 abort();
967 }
968#elif defined(HAVE_GETENTROPY)
969 while (1) {
970 if (getentropy(globalRngState, sizeof(globalRngState)) == 0)
971 break;
972
973 if (errno != EINTR) {
974 fprintf(stderr, "libxml2: getentropy failed with "
975 "error code %d\n", errno);
976 abort();
977 }
978 }
979#else
980 int var;
981
982 globalRngState[0] =
983 (unsigned) time(NULL) ^
984 HASH_ROL((unsigned) ((size_t) &xmlInitRandom & 0xFFFFFFFF), 8);
985 globalRngState[1] =
986 HASH_ROL((unsigned) ((size_t) &xmlRngMutex & 0xFFFFFFFF), 16) ^
987 HASH_ROL((unsigned) ((size_t) &var & 0xFFFFFFFF), 24);
988#endif
989 }
990}
991
992/*
993 * xmlCleanupRandom:

Callers 1

xmlInitParserFunction · 0.85

Calls 2

xmlInitMutexFunction · 0.85
fprintfFunction · 0.85

Tested by

no test coverage detected