home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xdmcp / GenKey.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-23  |  1.9 KB  |  60 lines

  1. /*
  2.  * $XConsortium: GenKey.c,v 1.3 91/01/23 22:13:42 gildea Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided
  8.  * that the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising
  11.  * or publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Keith Packard, MIT X Consortium
  24.  */
  25.  
  26. #include <X11/Xos.h>
  27. #include <X11/X.h>
  28. #include <X11/Xmd.h>
  29. #include <X11/Xdmcp.h>
  30.  
  31. static getbits (data, dst)
  32.     long        data;
  33.     unsigned char   *dst;
  34. {
  35.     dst[0] = (data      ) & 0xff;
  36.     dst[1] = (data >>  8) & 0xff;
  37.     dst[2] = (data >> 16) & 0xff;
  38.     dst[3] = (data >> 24) & 0xff;
  39. }
  40.  
  41. #if defined(SYSV) || defined(SVR4)
  42. #define srandom srand48
  43. #define random lrand48
  44. #endif
  45.  
  46. long random();
  47.  
  48. void
  49. XdmcpGenerateKey (key)
  50.     XdmAuthKeyPtr   key;
  51. {
  52.     long    lowbits, highbits;
  53.  
  54.     srandom (getpid() ^ time (0));
  55.     lowbits = random ();
  56.     highbits = random ();
  57.     getbits (lowbits, key->data);
  58.     getbits (highbits, key->data + 4);
  59. }
  60.