]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/Xdmcp/Wrap.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / lib / Xdmcp / Wrap.c
1 /*
2  * $XConsortium: Wrap.c,v 1.9 94/04/17 20:16:48 keith Exp $
3  *
4  * 
5 Copyright (c) 1989  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
27  * *
28  * Author:  Keith Packard, MIT X Consortium
29  */
30
31 #include <X11/Xos.h>
32 #include <X11/X.h>
33 #include <X11/Xmd.h>
34 #include <X11/Xdmcp.h>
35
36 #ifdef HASXDMAUTH
37
38 /*
39  * The following function exists only to demonstrate the
40  * desired functional interface for this routine.  You will
41  * need to add the appropriate algorithm if you wish to
42  * use XDM-AUTHENTICATION-1/XDM-AUTHORIZATION-1.
43  *
44  * Examine the XDMCP specification for the correct algorithm
45  */
46
47 #include "Wrap.h"
48
49 void
50 XdmcpWrap (input, wrapper, output, bytes)
51     unsigned char       *input, *output;
52     unsigned char       *wrapper;
53     int                 bytes;
54 {
55     int                 i, j;
56     int                 len;
57     unsigned char       tmp[8];
58     unsigned char       expand_wrapper[8];
59     auth_wrapper_schedule       schedule;
60
61     _XdmcpWrapperToOddParity (wrapper, expand_wrapper);
62     _XdmcpAuthSetup (expand_wrapper, schedule);
63     for (j = 0; j < bytes; j += 8)
64     {
65         len = 8;
66         if (bytes - j < len)
67             len = bytes - j;
68         /* block chaining */
69         for (i = 0; i < len; i++)
70         {
71             if (j == 0)
72                 tmp[i] = input[i];
73             else
74                 tmp[i] = input[j + i] ^ output[j - 8 + i];
75         }
76         for (; i < 8; i++)
77         {
78             if (j == 0)
79                 tmp[i] = 0;
80             else
81                 tmp[i] = 0 ^ output[j - 8 + i];
82         }
83         _XdmcpAuthDoIt (tmp, (output + j), schedule, 1);
84     }
85 }
86
87 /*
88  * Given a 56 bit wrapper in XDMCP format, create a 56
89  * bit wrapper in 7-bits + odd parity format
90  */
91
92 static int
93 OddParity (c)
94     unsigned char   c;
95 {
96     c = c ^ (c >> 4);
97     c = c ^ (c >> 2);
98     c = c ^ (c >> 1);
99     return ~c & 0x1;
100 }
101
102 /*
103  * Spread the 56 bit wrapper among 8 bytes, using the upper 7 bits
104  * of each byte, and storing an odd parity bit in the low bit
105  */
106
107 void
108 _XdmcpWrapperToOddParity (in, out)
109     unsigned char   *in, *out;
110 {
111     int             ashift, bshift;
112     int             i;
113     unsigned char   c;
114
115     ashift = 7;
116     bshift = 1;
117     for (i = 0; i < 7; i++)
118     {
119         c = ((in[i] << ashift) | (in[i+1] >> bshift)) & 0x7f;
120         out[i] = (c << 1) | OddParity (c);
121         ashift--;
122         bshift++;
123     }
124     c = in[i];
125     out[i] = (c << 1) | OddParity(c);
126 }
127
128 #endif