PuTTYgen initial version. Still to do are basic user-friendliness
[sgt/putty] / puttygen.c
CommitLineData
6e522441 1/*
2 * PuTTY key generation front end.
3 */
4
5#include <windows.h>
6#include <commctrl.h>
7#include <time.h>
8#ifndef NO_SECURITY
9#include <aclapi.h>
10#endif
11#include <stdio.h>
12
13#define PUTTY_DO_GLOBALS
14
15#include "putty.h"
16#include "ssh.h"
17#include "winstuff.h"
18
19#define WM_DONEKEY (WM_XUSER + 1)
20
21#define KEYSIZE 1024
22
23/*
24 * TODO:
25 * - have some means of verifying passphrase changes against typos
26 * - prompt before overwriting an existing file
27 * - check the return value from saversakey()
28 * - test the generated keys for actual working-RSA-key-hood
29 * - variable key size
30 */
31
32/* ----------------------------------------------------------------------
33 * Progress report code. This is really horrible :-)
34 */
35#define PHASE1TOTAL 0x10000
36#define PHASE2TOTAL 0x10000
37#define PHASE3TOTAL 0x04000
38#define PHASE1START 0
39#define PHASE2START (PHASE1TOTAL)
40#define PHASE3START (PHASE1TOTAL + PHASE2TOTAL)
41#define TOTALTOTAL (PHASE1TOTAL + PHASE2TOTAL + PHASE3TOTAL)
42#define PROGRESSBIGRANGE 65535
43#define DIVISOR ((TOTALTOTAL + PROGRESSBIGRANGE - 1) / PROGRESSBIGRANGE)
44#define PROGRESSRANGE (TOTALTOTAL / DIVISOR)
45struct progress {
46 unsigned phase1param, phase1current, phase1n;
47 unsigned phase2param, phase2current, phase2n;
48 unsigned phase3mult;
49 HWND progbar;
50};
51
52static void progress_update(void *param, int phase, int iprogress) {
53 struct progress *p = (struct progress *)param;
54 unsigned progress = iprogress;
55 int position;
56
57 switch (phase) {
58 case -1:
59 p->phase1param = 0x10000 + progress;
60 p->phase1current = 0x10000; p->phase1n = 0;
61 return;
62 case -2:
63 p->phase2param = 0x10000 + progress;
64 p->phase2current = 0x10000; p->phase2n = 0;
65 return;
66 case -3:
67 p->phase3mult = PHASE3TOTAL / progress;
68 return;
69 case 1:
70 while (p->phase1n < progress) {
71 p->phase1n++;
72 p->phase1current *= p->phase1param;
73 p->phase1current /= 0x10000;
74 }
75 position = PHASE1START + 0x10000 - p->phase1current;
76 break;
77 case 2:
78 while (p->phase2n < progress) {
79 p->phase2n++;
80 p->phase2current *= p->phase2param;
81 p->phase2current /= 0x10000;
82 }
83 position = PHASE2START + 0x10000 - p->phase2current;
84 break;
85 case 3:
86 position = PHASE3START + progress * p->phase3mult;
87 break;
88 }
89
90 SendMessage(p->progbar, PBM_SETPOS, position / DIVISOR, 0);
91}
92
93extern char ver[];
94
95#define PASSPHRASE_MAXLEN 512
96
97struct PassphraseProcStruct {
98 char *passphrase;
99 char *comment;
100};
101
102/*
103 * Dialog-box function for the passphrase box.
104 */
105static int CALLBACK PassphraseProc(HWND hwnd, UINT msg,
106 WPARAM wParam, LPARAM lParam) {
107 static char *passphrase;
108 struct PassphraseProcStruct *p;
109
110 switch (msg) {
111 case WM_INITDIALOG:
112 SetForegroundWindow(hwnd);
113 SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
114 SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
115 p = (struct PassphraseProcStruct *)lParam;
116 passphrase = p->passphrase;
117 if (p->comment)
118 SetDlgItemText(hwnd, 101, p->comment);
119 *passphrase = 0;
120 return 0;
121 case WM_COMMAND:
122 switch (LOWORD(wParam)) {
123 case IDOK:
124 if (*passphrase)
125 EndDialog (hwnd, 1);
126 else
127 MessageBeep (0);
128 return 0;
129 case IDCANCEL:
130 EndDialog (hwnd, 0);
131 return 0;
132 case 102: /* edit box */
133 if (HIWORD(wParam) == EN_CHANGE) {
134 GetDlgItemText (hwnd, 102, passphrase, PASSPHRASE_MAXLEN-1);
135 passphrase[PASSPHRASE_MAXLEN-1] = '\0';
136 }
137 return 0;
138 }
139 return 0;
140 case WM_CLOSE:
141 EndDialog (hwnd, 0);
142 return 0;
143 }
144 return 0;
145}
146
147/*
148 * Prompt for a key file. Assumes the filename buffer is of size
149 * FILENAME_MAX.
150 */
151static int prompt_keyfile(HWND hwnd, char *dlgtitle,
152 char *filename, int save) {
153 OPENFILENAME of;
154 memset(&of, 0, sizeof(of));
155#ifdef OPENFILENAME_SIZE_VERSION_400
156 of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
157#else
158 of.lStructSize = sizeof(of);
159#endif
160 of.hwndOwner = hwnd;
161 of.lpstrFilter = "All Files\0*\0\0\0";
162 of.lpstrCustomFilter = NULL;
163 of.nFilterIndex = 1;
164 of.lpstrFile = filename; *filename = '\0';
165 of.nMaxFile = FILENAME_MAX;
166 of.lpstrFileTitle = NULL;
167 of.lpstrInitialDir = NULL;
168 of.lpstrTitle = dlgtitle;
169 of.Flags = 0;
170 if (save)
171 return GetSaveFileName(&of);
172 else
173 return GetOpenFileName(&of);
174}
175
176/*
177 * This function is needed to link with the DES code. We need not
178 * have it do anything at all.
179 */
180void logevent(char *msg) {
181}
182
183/*
184 * Dialog-box function for the Licence box.
185 */
186static int CALLBACK LicenceProc (HWND hwnd, UINT msg,
187 WPARAM wParam, LPARAM lParam) {
188 switch (msg) {
189 case WM_INITDIALOG:
190 return 1;
191 case WM_COMMAND:
192 switch (LOWORD(wParam)) {
193 case IDOK:
194 EndDialog(hwnd, 1);
195 return 0;
196 }
197 return 0;
198 case WM_CLOSE:
199 EndDialog(hwnd, 1);
200 return 0;
201 }
202 return 0;
203}
204
205/*
206 * Dialog-box function for the About box.
207 */
208static int CALLBACK AboutProc (HWND hwnd, UINT msg,
209 WPARAM wParam, LPARAM lParam) {
210 switch (msg) {
211 case WM_INITDIALOG:
212 SetDlgItemText (hwnd, 100, ver);
213 return 1;
214 case WM_COMMAND:
215 switch (LOWORD(wParam)) {
216 case IDOK:
217 EndDialog(hwnd, 1);
218 return 0;
219 case 101:
220 EnableWindow(hwnd, 0);
221 DialogBox (hinst, MAKEINTRESOURCE(214), NULL, LicenceProc);
222 EnableWindow(hwnd, 1);
223 SetActiveWindow(hwnd);
224 return 0;
225 }
226 return 0;
227 case WM_CLOSE:
228 EndDialog(hwnd, 1);
229 return 0;
230 }
231 return 0;
232}
233
234/*
235 * Thread to generate a key.
236 */
237struct rsa_key_thread_params {
238 HWND progressbar; /* notify this with progress */
239 HWND dialog; /* notify this on completion */
240 struct RSAKey *key;
241 struct RSAAux *aux;
242};
243static DWORD WINAPI generate_rsa_key_thread(void *param) {
244 struct rsa_key_thread_params *params =
245 (struct rsa_key_thread_params *)param;
246 struct progress prog;
247 prog.progbar = params->progressbar;
248
249 rsa_generate(params->key, params->aux, KEYSIZE, progress_update, &prog);
250
251 PostMessage(params->dialog, WM_DONEKEY, 0, 0);
252
253 free(params);
254 return 0;
255}
256
257struct MainDlgState {
258 int collecting_entropy;
259 int generation_thread_exists;
260 int key_exists;
261 int entropy_got, entropy_required, entropy_size;
262 unsigned *entropy;
263 struct RSAKey key;
264 struct RSAAux aux;
265};
266
267static void hidemany(HWND hwnd, const int *ids, int hideit) {
268 while (*ids) {
269 ShowWindow(GetDlgItem(hwnd, *ids++), (hideit ? SW_HIDE : SW_SHOW));
270 }
271}
272
273static void setupbigedit(HWND hwnd, int id, struct RSAKey *key) {
274 char *buffer;
275 char *dec1, *dec2;
276
277 dec1 = bignum_decimal(key->exponent);
278 dec2 = bignum_decimal(key->modulus);
279 buffer = malloc(strlen(dec1)+strlen(dec2)+
280 strlen(key->comment)+30);
281 sprintf(buffer, "%d %s %s %s",
282 ssh1_bignum_bitcount(key->modulus),
283 dec1, dec2, key->comment);
284 SetDlgItemText(hwnd, id, buffer);
285 free(dec1);
286 free(dec2);
287 free(buffer);
288}
289
290/*
291 * Dialog-box function for the main PuTTYgen dialog box.
292 */
293static int CALLBACK MainDlgProc (HWND hwnd, UINT msg,
294 WPARAM wParam, LPARAM lParam) {
295 enum {
296 controlidstart = 100,
297 IDC_TITLE,
298 IDC_BOX_KEY, IDC_BOXT_KEY,
299 IDC_NOKEY,
300 IDC_GENERATING,
301 IDC_PROGRESS,
302 IDC_PKSTATIC, IDC_KEYDISPLAY,
303 IDC_FPSTATIC, IDC_FINGERPRINT,
304 IDC_COMMENTSTATIC, IDC_COMMENTEDIT,
305 IDC_PASSPHRASESTATIC, IDC_PASSPHRASEEDIT,
306 IDC_BOX_ACTIONS, IDC_BOXT_ACTIONS,
307 IDC_GENSTATIC, IDC_GENERATE,
308 IDC_LOADSTATIC, IDC_LOAD,
309 IDC_SAVESTATIC, IDC_SAVE,
310 IDC_ABOUT,
311 };
312 static const int nokey_ids[] = { IDC_NOKEY, 0 };
313 static const int generating_ids[] = { IDC_GENERATING, IDC_PROGRESS, 0 };
314 static const int gotkey_ids[] = {
315 IDC_PKSTATIC, IDC_KEYDISPLAY,
316 IDC_FPSTATIC, IDC_FINGERPRINT,
317 IDC_COMMENTSTATIC, IDC_COMMENTEDIT,
318 IDC_PASSPHRASESTATIC, IDC_PASSPHRASEEDIT, 0 };
319 static const char generating_msg[] =
320 "Please wait while a key is generated...";
321 static const char entropy_msg[] =
322 "Please move the mouse in this window to generate randomness";
323 struct MainDlgState *state;
324
325 switch (msg) {
326 case WM_INITDIALOG:
327 state = malloc(sizeof(*state));
328 state->generation_thread_exists = FALSE;
329 state->key_exists = FALSE;
330 SetWindowLong(hwnd, GWL_USERDATA, (LONG)state);
331 {
332 struct ctlpos cp, cp2;
333
334 ctlposinit(&cp, hwnd, 10, 10, 10);
335 bartitle(&cp, "Public and private key generation for PuTTY",
336 IDC_TITLE);
337 beginbox(&cp, "Key",
338 IDC_BOX_KEY, IDC_BOXT_KEY);
339 cp2 = cp;
340 statictext(&cp2, "No key.", IDC_NOKEY);
341 cp2 = cp;
342 statictext(&cp2, "",
343 IDC_GENERATING);
344 progressbar(&cp2, IDC_PROGRESS);
345 bigeditctrl(&cp,
346 "&Public key for pasting into authorized_keys file:",
347 IDC_PKSTATIC, IDC_KEYDISPLAY, 7);
348 SendDlgItemMessage(hwnd, IDC_KEYDISPLAY, EM_SETREADONLY, 1, 0);
349 staticedit(&cp, "Key fingerprint:", IDC_FPSTATIC,
350 IDC_FINGERPRINT, 70);
351 SendDlgItemMessage(hwnd, IDC_FINGERPRINT, EM_SETREADONLY, 1, 0);
352 staticedit(&cp, "Key &comment:", IDC_COMMENTSTATIC,
353 IDC_COMMENTEDIT, 70);
354 staticpassedit(&cp, "Key p&assphrase:", IDC_PASSPHRASESTATIC,
355 IDC_PASSPHRASEEDIT, 70);
356 endbox(&cp);
357 beginbox(&cp, "Actions",
358 IDC_BOX_ACTIONS, IDC_BOXT_ACTIONS);
359 staticbtn(&cp, "Generate a public/private key pair",
360 IDC_GENSTATIC, "&Generate", IDC_GENERATE);
361 staticbtn(&cp, "Load an existing private key file",
362 IDC_LOADSTATIC, "&Load", IDC_LOAD);
363 staticbtn(&cp, "Save the generated key to a new file",
364 IDC_SAVESTATIC, "&Save", IDC_SAVE);
365 endbox(&cp);
366 }
367 /*
368 * Initially, hide the progress bar and the key display,
369 * and show the no-key display. Also disable the Save
370 * button, because with no key we obviously can't save
371 * anything.
372 */
373 hidemany(hwnd, nokey_ids, FALSE);
374 hidemany(hwnd, generating_ids, TRUE);
375 hidemany(hwnd, gotkey_ids, TRUE);
376 EnableWindow(GetDlgItem(hwnd, IDC_SAVE), 0);
377
378 return 1;
379 case WM_MOUSEMOVE:
380 state = (struct MainDlgState *)GetWindowLong(hwnd, GWL_USERDATA);
381 if (state->collecting_entropy) {
382 state->entropy[state->entropy_got++] = lParam;
383 state->entropy[state->entropy_got++] = GetMessageTime();
384 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS,
385 state->entropy_got, 0);
386 if (state->entropy_got >= state->entropy_required) {
387 struct rsa_key_thread_params *params;
388 DWORD threadid;
389
390 /*
391 * Seed the entropy pool
392 */
393 random_add_heavynoise(state->entropy, state->entropy_size);
394 memset(state->entropy, 0, state->entropy_size);
395 free(state->entropy);
396
397 SetDlgItemText(hwnd, IDC_GENERATING, generating_msg);
398 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
399 MAKELPARAM(0, PROGRESSRANGE));
400 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
401
402 params = malloc(sizeof(*params));
403 params->progressbar = GetDlgItem(hwnd, IDC_PROGRESS);
404 params->dialog = hwnd;
405 params->key = &state->key;
406 params->aux = &state->aux;
407
408 if (!CreateThread(NULL, 0, generate_rsa_key_thread,
409 params, 0, &threadid)) {
410 MessageBox(hwnd, "Out of thread resources",
411 "Key generation error",
412 MB_OK | MB_ICONERROR);
413 free(params);
414 } else {
415 state->generation_thread_exists = TRUE;
416 state->collecting_entropy = FALSE;
417 }
418 }
419 }
420 break;
421 case WM_COMMAND:
422 switch (LOWORD(wParam)) {
423 case IDC_COMMENTEDIT:
424 if (HIWORD(wParam) == EN_CHANGE) {
425 state = (struct MainDlgState *)
426 GetWindowLong(hwnd, GWL_USERDATA);
427 if (state->key_exists) {
428 HWND editctl = GetDlgItem(hwnd, IDC_COMMENTEDIT);
429 int len = GetWindowTextLength(editctl);
430 if (state->key.comment)
431 free(state->key.comment);
432 state->key.comment = malloc(len+1);
433 GetWindowText(editctl, state->key.comment, len+1);
434 }
435 }
436 break;
437 case IDC_ABOUT:
438 EnableWindow(hwnd, 0);
439 DialogBox (hinst, MAKEINTRESOURCE(213), NULL, AboutProc);
440 EnableWindow(hwnd, 1);
441 SetActiveWindow(hwnd);
442 return 0;
443 case IDC_GENERATE:
444 state = (struct MainDlgState *)GetWindowLong(hwnd, GWL_USERDATA);
445 if (!state->generation_thread_exists) {
446 hidemany(hwnd, nokey_ids, TRUE);
447 hidemany(hwnd, generating_ids, FALSE);
448 hidemany(hwnd, gotkey_ids, TRUE);
449 EnableWindow(GetDlgItem(hwnd, IDC_GENERATE), 0);
450 EnableWindow(GetDlgItem(hwnd, IDC_LOAD), 0);
451 EnableWindow(GetDlgItem(hwnd, IDC_SAVE), 0);
452 state->key_exists = FALSE;
453 SetDlgItemText(hwnd, IDC_GENERATING, entropy_msg);
454 state->collecting_entropy = TRUE;
455
456 /*
457 * My brief statistical tests on mouse movements
458 * suggest that there are about 5 bits of
459 * randomness in the x position, 5 in the y
460 * position, and 1.7 in the message time, making
461 * 11.7 bits of unpredictability per mouse
462 * movement. However, other people have told me
463 * it's far less than that, so I'm going to be
464 * stupidly cautious and knock that down to a nice
465 * round 4.
466 */
467 state->entropy_required = (KEYSIZE / 4) * 2;
468 state->entropy_got = 0;
469 state->entropy_size = (state->entropy_required *
470 sizeof(*state->entropy));
471 state->entropy = malloc(state->entropy_size);
472
473 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
474 MAKELPARAM(0, state->entropy_required));
475 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
476 }
477 break;
478 case IDC_SAVE:
479 state = (struct MainDlgState *)GetWindowLong(hwnd, GWL_USERDATA);
480 if (state->key_exists) {
481 char filename[FILENAME_MAX];
482 char passphrase[PASSPHRASE_MAXLEN];
483 GetDlgItemText(hwnd, IDC_PASSPHRASEEDIT,
484 passphrase, sizeof(passphrase)-1);
485 if (!*passphrase) {
486 int ret;
487 ret = MessageBox(hwnd,
488 "Are you sure you want to save this key\n"
489 "without a passphrase to protect it?",
490 "PuTTYgen Warning",
491 MB_YESNO | MB_ICONWARNING);
492 if (ret != IDYES)
493 break;
494 }
495 if (prompt_keyfile(hwnd, "Save private key as:",
496 filename, 1)) {
497 /* FIXME: prompt before overwriting */
498 saversakey(filename, &state->key, &state->aux,
499 *passphrase ? passphrase : NULL);
500 /* FIXME: check return value */
501 }
502 }
503 break;
504 case IDC_LOAD:
505 state = (struct MainDlgState *)GetWindowLong(hwnd, GWL_USERDATA);
506 if (!state->generation_thread_exists) {
507 char filename[FILENAME_MAX];
508 if (prompt_keyfile(hwnd, "Load private key:",
509 filename, 0)) {
510 char passphrase[PASSPHRASE_MAXLEN];
511 int needs_pass;
512 int ret;
513 char *comment;
514 struct PassphraseProcStruct pps;
515 struct RSAKey newkey;
516 struct RSAAux newaux;
517
518 needs_pass = rsakey_encrypted(filename, &comment);
519 pps.passphrase = passphrase;
520 pps.comment = comment;
521 do {
522 if (needs_pass) {
523 int dlgret;
524 dlgret = DialogBoxParam(hinst,
525 MAKEINTRESOURCE(210),
526 NULL, PassphraseProc,
527 (LPARAM)&pps);
528 if (!dlgret) {
529 ret = -2;
530 break;
531 }
532 } else
533 *passphrase = '\0';
534 ret = loadrsakey(filename, &newkey, &newaux,
535 passphrase);
536 } while (ret == -1);
537 if (comment) free(comment);
538 if (ret == 0) {
539 MessageBox(NULL, "Couldn't load private key.",
540 "PuTTYgen Error", MB_OK | MB_ICONERROR);
541 } else if (ret == 1) {
542 state->key = newkey;
543 state->aux = newaux;
544
545 EnableWindow(GetDlgItem(hwnd, IDC_GENERATE), 1);
546 EnableWindow(GetDlgItem(hwnd, IDC_LOAD), 1);
547 EnableWindow(GetDlgItem(hwnd, IDC_SAVE), 1);
548 /*
549 * Now update the key controls with all the
550 * key data.
551 */
552 {
553 char buf[128];
554 SetDlgItemText(hwnd, IDC_PASSPHRASEEDIT,
555 passphrase);
556 SetDlgItemText(hwnd, IDC_COMMENTEDIT,
557 state->key.comment);
558 /*
559 * Set the key fingerprint.
560 */
561 {
562 char *savecomment = state->key.comment;
563 state->key.comment = NULL;
564 rsa_fingerprint(buf, sizeof(buf), &state->key);
565 state->key.comment = savecomment;
566 }
567 SetDlgItemText(hwnd, IDC_FINGERPRINT, buf);
568 /*
569 * Construct a decimal representation
570 * of the key, for pasting into
571 * .ssh/authorized_keys on a Unix box.
572 */
573 setupbigedit(hwnd, IDC_KEYDISPLAY, &state->key);
574 }
575 /*
576 * Finally, hide the progress bar and show
577 * the key data.
578 */
579 hidemany(hwnd, nokey_ids, TRUE);
580 hidemany(hwnd, generating_ids, TRUE);
581 hidemany(hwnd, gotkey_ids, FALSE);
582 state->key_exists = TRUE;
583 }
584 }
585 }
586 break;
587 }
588 return 0;
589 case WM_DONEKEY:
590 state = (struct MainDlgState *)GetWindowLong(hwnd, GWL_USERDATA);
591 state->generation_thread_exists = FALSE;
592 state->key_exists = TRUE;
593 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, PROGRESSRANGE, 0);
594 EnableWindow(GetDlgItem(hwnd, IDC_GENERATE), 1);
595 EnableWindow(GetDlgItem(hwnd, IDC_LOAD), 1);
596 EnableWindow(GetDlgItem(hwnd, IDC_SAVE), 1);
597 /*
598 * Invent a comment for the key. We'll do this by including
599 * the date in it. This will be so horrifyingly ugly that
600 * the user will immediately want to change it, which is
601 * what we want :-)
602 */
603 state->key.comment = malloc(30);
604 {
605 time_t t;
606 struct tm *tm;
607 time(&t);
608 tm = localtime(&t);
609 strftime(state->key.comment, 30, "rsa-key-%Y%m%d", tm);
610 }
611
612 /*
613 * Now update the key controls with all the key data.
614 */
615 {
616 char buf[128];
617 /*
618 * Blank passphrase, initially. This isn't dangerous,
619 * because we will warn (Are You Sure?) before allowing
620 * the user to save an unprotected private key.
621 */
622 SetDlgItemText(hwnd, IDC_PASSPHRASEEDIT, "");
623 /*
624 * Set the comment.
625 */
626 SetDlgItemText(hwnd, IDC_COMMENTEDIT, state->key.comment);
627 /*
628 * Set the key fingerprint.
629 */
630 {
631 char *savecomment = state->key.comment;
632 state->key.comment = NULL;
633 rsa_fingerprint(buf, sizeof(buf), &state->key);
634 state->key.comment = savecomment;
635 }
636 SetDlgItemText(hwnd, IDC_FINGERPRINT, buf);
637 /*
638 * Construct a decimal representation of the key, for
639 * pasting into .ssh/authorized_keys on a Unix box.
640 */
641 setupbigedit(hwnd, IDC_KEYDISPLAY, &state->key);
642 }
643 /*
644 * Finally, hide the progress bar and show the key data.
645 */
646 hidemany(hwnd, nokey_ids, TRUE);
647 hidemany(hwnd, generating_ids, TRUE);
648 hidemany(hwnd, gotkey_ids, FALSE);
649 break;
650 case WM_CLOSE:
651 state = (struct MainDlgState *)GetWindowLong(hwnd, GWL_USERDATA);
652 free(state);
653 EndDialog(hwnd, 1);
654 return 0;
655 }
656 return 0;
657}
658
659int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) {
660 hinst = inst;
661 random_init();
662 return DialogBox(hinst, MAKEINTRESOURCE(201), NULL, MainDlgProc) != IDOK;
663}