- /* The following creates a seed for the session key generator
- based on a collection of volatile and environment-specific
- information unlikely to be vulnerable (as a whole) to an
- exhaustive search attack. If one of these items isn't
- available on your machine, replace it with something
- equivalent or, if you like, just delete it. */
-
- sprintf(s + strlen(s), "%lu", (unsigned long) getpid());
- sprintf(s + strlen(s), "%lu", (unsigned long) getppid());
- getcwd(s + strlen(s), 256);
- sprintf(s + strlen(s), "%lu", (unsigned long) clock());
- sprintf(s + strlen(s), "%lu", (unsigned long) time(NULL));
-#ifdef Solaris
- sysinfo(SI_HW_SERIAL,s + strlen(s), 12);
+ s[0] = 0;
+ if (seed != NULL) {
+ bstrncat(s, seed, sizeof(s));
+ }
+
+ /* The following creates a seed for the session key generator
+ based on a collection of volatile and environment-specific
+ information unlikely to be vulnerable (as a whole) to an
+ exhaustive search attack. If one of these items isn't
+ available on your machine, replace it with something
+ equivalent or, if you like, just delete it. */
+
+#if defined(HAVE_WIN32)
+ {
+ LARGE_INTEGER li;
+ DWORD length;
+ FILETIME ft;
+ char *p;
+
+ p = s;
+ bsnprintf(s + strlen(s), ss, "%lu", (uint32_t)GetCurrentProcessId());
+ (void)getcwd(s + strlen(s), 256);
+ bsnprintf(s + strlen(s), ss, "%lu", (uint32_t)GetTickCount());
+ QueryPerformanceCounter(&li);
+ bsnprintf(s + strlen(s), ss, "%lu", (uint32_t)li.LowPart);
+ GetSystemTimeAsFileTime(&ft);
+ bsnprintf(s + strlen(s), ss, "%lu", (uint32_t)ft.dwLowDateTime);
+ bsnprintf(s + strlen(s), ss, "%lu", (uint32_t)ft.dwHighDateTime);
+ length = 256;
+ GetComputerName(s + strlen(s), &length);
+ length = 256;
+ GetUserName(s + strlen(s), &length);
+ }
+#else
+ bsnprintf(s + strlen(s), ss, "%lu", (uint32_t)getpid());
+ bsnprintf(s + strlen(s), ss, "%lu", (uint32_t)getppid());
+ (void)getcwd(s + strlen(s), 256);
+ bsnprintf(s + strlen(s), ss, "%lu", (uint32_t)clock());
+ bsnprintf(s + strlen(s), ss, "%lu", (uint32_t)time(NULL));
+#if defined(Solaris)
+ sysinfo(SI_HW_SERIAL,s + strlen(s), 12);