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

  1. /*
  2.  * $XConsortium: Wrap.c,v 1.7 91/07/23 22:28:15 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.  * Examine the XDMCP specification for the correct algorithm
  40.  */
  41.  
  42. #include "Wrap.h"
  43.  
  44. void
  45. XdmcpWrap (input, wrapper, output, bytes)
  46.     unsigned char    *input, *output;
  47.     unsigned char    *wrapper;
  48.     int            bytes;
  49. {
  50.     int            i, j;
  51.     int            len;
  52.     unsigned char    tmp[8];
  53.     unsigned char    expand_wrapper[8];
  54.     auth_wrapper_schedule    schedule;
  55.  
  56.     _XdmcpWrapperToOddParity (wrapper, expand_wrapper);
  57.     _XdmcpAuthSetup (wrapper, schedule);
  58.     for (j = 0; j < bytes; j += 8)
  59.     {
  60.     len = 8;
  61.     if (bytes - j < len)
  62.         len = bytes - j;
  63.     /* block chaining */
  64.     for (i = 0; i < len; i++)
  65.     {
  66.         if (j == 0)
  67.         tmp[i] = input[i];
  68.         else
  69.         tmp[i] = input[j + i] ^ output[j - 8 + i];
  70.     }
  71.     for (; i < 8; i++)
  72.     {
  73.         if (j == 0)
  74.         tmp[i] = 0;
  75.         else
  76.         tmp[i] = 0 ^ output[j - 8 + i];
  77.     }
  78.     _XdmcpAuthDoIt (tmp, (output + j), schedule, 1);
  79.     }
  80. }
  81.  
  82. /*
  83.  * Given a 56 bit wrapper in XDMCP format, create a 56
  84.  * bit wrapper in 7-bits + odd parity format
  85.  */
  86.  
  87. static int
  88. OddParity (c)
  89.     unsigned char   c;
  90. {
  91.     c = c ^ (c >> 4);
  92.     c = c ^ (c >> 2);
  93.     c = c ^ (c >> 1);
  94.     return ~c & 0x1;
  95. }
  96.  
  97. /*
  98.  * Spread the 56 bit wrapper among 8 bytes, using the upper 7 bits
  99.  * of each byte, and storing an odd parity bit in the low bit
  100.  */
  101.  
  102. void
  103. _XdmcpWrapperToOddParity (in, out)
  104.     unsigned char   *in, *out;
  105. {
  106.     int            ashift, bshift;
  107.     int            i;
  108.     unsigned char   c;
  109.  
  110.     ashift = 7;
  111.     bshift = 1;
  112.     for (i = 0; i < 7; i++)
  113.     {
  114.     c = ((in[i] << ashift) | (in[i+1] >> bshift)) & 0x7f;
  115.     out[i] = (c << 1) | OddParity (c);
  116.     ashift--;
  117.     bshift++;
  118.     }
  119.     c = in[i];
  120.     out[i] = (c << 1) | OddParity(c);
  121. }
  122.  
  123. #endif
  124.