2 * Copyright 1998-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 * Usage: winrand [filename]
13 * Collects entropy from mouse movements and other events and writes
14 * random data to filename or .rnd
18 #include <openssl/opensslv.h>
19 #include <openssl/rand.h>
21 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
24 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
25 PSTR cmdline, int iCmdShow)
27 static char appname[] = "OpenSSL";
33 if (cmdline[0] == '\0')
34 filename = RAND_file_name(buffer, sizeof buffer);
38 RAND_load_file(filename, -1);
40 wndclass.cbSize = sizeof(wndclass);
41 wndclass.style = CS_HREDRAW | CS_VREDRAW;
42 wndclass.lpfnWndProc = WndProc;
43 wndclass.cbClsExtra = 0;
44 wndclass.cbWndExtra = 0;
45 wndclass.hInstance = hInstance;
46 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
47 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
48 wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
49 wndclass.lpszMenuName = NULL;
50 wndclass.lpszClassName = appname;
51 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
52 RegisterClassEx(&wndclass);
54 hwnd = CreateWindow(appname, OPENSSL_VERSION_TEXT,
55 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
56 CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance,
59 ShowWindow(hwnd, iCmdShow);
62 while (GetMessage(&msg, NULL, 0, 0)) {
63 TranslateMessage(&msg);
64 DispatchMessage(&msg);
70 LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
75 static int seeded = 0;
79 hdc = BeginPaint(hwnd, &ps);
80 GetClientRect(hwnd, &rect);
81 DrawText(hdc, "Seeding the PRNG. Please move the mouse!", -1,
82 &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
91 return DefWindowProc(hwnd, iMsg, wParam, lParam);