]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/Xdmcp/GenKey.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / lib / Xdmcp / GenKey.c
1 /*
2  * $XConsortium: GenKey.c,v 1.6 94/04/17 20:16:36 rws Exp $
3  * $XFree86: xc/lib/Xdmcp/GenKey.c,v 3.1 1996/10/23 13:08:39 dawes Exp $
4  *
5  * 
6 Copyright (c) 1989  X Consortium
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
21 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 Except as contained in this notice, the name of the X Consortium shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings
27 in this Software without prior written authorization from the X Consortium.
28  * *
29  * Author:  Keith Packard, MIT X Consortium
30  */
31
32 #include <X11/Xos.h>
33 #include <X11/X.h>
34 #include <X11/Xmd.h>
35 #include <X11/Xdmcp.h>
36
37 static getbits (data, dst)
38     long            data;
39     unsigned char   *dst;
40 {
41     dst[0] = (data      ) & 0xff;
42     dst[1] = (data >>  8) & 0xff;
43     dst[2] = (data >> 16) & 0xff;
44     dst[3] = (data >> 24) & 0xff;
45 }
46
47 /* EMX is not STDC, but sometimes it is */
48 #if defined(X_NOT_STDC_ENV) && !defined(__EMX__)
49 #define Time_t long
50 extern Time_t time ();
51 #else
52 #define Time_t time_t
53 #endif
54
55 #if defined(SYSV) || defined(SVR4)
56 #define srandom srand48
57 #define random lrand48
58 #endif
59
60 #ifdef linux
61 #include <stdlib.h>
62 #else
63 long random();
64 #endif
65
66 void
67 XdmcpGenerateKey (key)
68     XdmAuthKeyPtr   key;
69 {
70     long    lowbits, highbits;
71
72     srandom ((int)getpid() ^ time((Time_t *)0));
73     lowbits = random ();
74     highbits = random ();
75     getbits (lowbits, key->data);
76     getbits (highbits, key->data + 4);
77 }