home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xdmcp / Unwrap.c.orig < prev    next >
Encoding:
Text File  |  1991-07-23  |  2.8 KB  |  86 lines

  1. /*
  2.  * $XConsortium: Unwrap.c,v 1.7 91/07/23 22:28:13 keith 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. #ifdef HASXDMAUTH
  32.  
  33. /*
  34.  * The following function exists only to demonstrate the
  35.  * desired functional interface for this routine.  You will
  36.  * need to add the appropriate algorithm if you wish to
  37.  * use XDM-AUTHENTICATION-1/XDM-AUTHORIZATION-1.
  38.  *
  39.  * The interface for this routine is quite simple.  All three
  40.  * arguments are arrays of 8 unsigned characters, the first two
  41.  * are 64 bits of useful data, the last is 56 bits of useful
  42.  * data packed into 8 bytes, using the low 7 bits of each
  43.  * byte, filling the high bit with odd parity.
  44.  *
  45.  * Examine the XDMCP specification for the correct algorithm
  46.  */
  47.  
  48. #include "Wrap.h"
  49.  
  50. void
  51. XdmcpUnwrap (input, wrapper, output, bytes)
  52.     unsigned char    *input, *output;
  53.     unsigned char    *wrapper;
  54.     int            bytes;
  55. {
  56.     int            i, j, k;
  57.     unsigned char    tmp[8];
  58.     unsigned char    blocks[2][8];
  59.     unsigned char    expand_wrapper[8];
  60.     auth_wrapper_schedule    schedule;
  61.  
  62.     _XdmcpWrapperToOddParity (wrapper, expand_wrapper);
  63.     _XdmcpAuthSetup ((unsigned char *) wrapper, schedule);
  64.  
  65.     k = 0;
  66.     for (j = 0; j < bytes; j += 8)
  67.     {
  68.     if (bytes - j < 8)
  69.         return; /* bad input length */
  70.     for (i = 0; i < 8; i++)
  71.         blocks[k][i] = input[j + i];
  72.     _XdmcpAuthDoIt ((unsigned char *) (input + j), (unsigned char *) tmp, schedule, 0);
  73.     /* block chaining */
  74.     k = (k == 0) ? 1 : 0;
  75.     for (i = 0; i < 8; i++)
  76.     {
  77.         if (j == 0)
  78.         output[j + i] = tmp[i];
  79.         else
  80.         output[j + i] = tmp[i] ^ blocks[k][i];
  81.     }
  82.     }
  83. }
  84.  
  85. #endif /* HASXDMAUTH */
  86.