diff options
author | Ulf Möller <ulf@openssl.org> | 2000-03-19 17:14:25 +0000 |
---|---|---|
committer | Ulf Möller <ulf@openssl.org> | 2000-03-19 17:14:25 +0000 |
commit | c97b11f4b3e20b92aba6f109a3d89170974360fc (patch) | |
tree | aa83b389074e6096f326ea15356693d3f81cdb8b /crypto | |
parent | 2501b335fa1601082cfa3d6fe16c04f2ec424dd3 (diff) |
New function RAND_event() collects entropy from Windows events.
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/rand/md_rand.c | 41 | ||||
-rw-r--r-- | crypto/rand/rand.h | 2 |
2 files changed, 43 insertions, 0 deletions
diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c index b8564b1a0d..9f8da22917 100644 --- a/crypto/rand/md_rand.c +++ b/crypto/rand/md_rand.c @@ -568,6 +568,47 @@ static int ssleay_rand_status(void) #include <windows.h> #include <openssl/rand.h> +int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam) + { + double add_entropy=0; + SYSTEMTIME t; + + switch (iMsg) + { + case WM_KEYDOWN: + { + static WPARAM key; + if (key != wParam) + add_entropy = 0.05; + key = wParam; + } + break; + case WM_MOUSEMOVE: + { + static int lastx,lasty,lastdx,lastdy; + int x,y,dx,dy; + + x=LOWORD(lParam); + y=HIWORD(lParam); + dx=lastx-x; + dy=lasty-y; + if (dx != 0 && dy != 0 && dx-lastdx != 0 && dy-lastdy != 0) + entropy += .2; + lastx=x,lasty=y; + lastdx=dx, lastdy=dy; + } + break; + } + + GetSystemTime(&t); + RAND_add(&iMsg, sizeof(iMsg), add_entropy); + RAND_add(&wParam, sizeof(wParam), 0); + RAND_add(&lParam, sizeof(lParam), 0); + RAND_add(&t, sizeof(t), 0); + + return (RAND_status()); + } + /***************************************************************************** * Initialisation function for the SSL random generator. Takes the contents * of the screen as random seed. diff --git a/crypto/rand/rand.h b/crypto/rand/rand.h index 79cb9047a2..2973ee90e4 100644 --- a/crypto/rand/rand.h +++ b/crypto/rand/rand.h @@ -91,7 +91,9 @@ const char *RAND_file_name(char *file,int num); int RAND_status(void); int RAND_egd(const char *path); #if defined(WINDOWS) || defined(WIN32) +#include <windows.h> void RAND_screen(void); +int RAND_event(UINT, WPARAM, LPARAM); #endif void ERR_load_RAND_strings(void); |