]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/Xdmcp/Unwrap.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / lib / Xdmcp / Unwrap.c
1 /*
2  * $XConsortium: Unwrap.c,v 1.9 94/04/17 20:16:43 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  * The interface for this routine is quite simple.  All three
45  * arguments are arrays of 8 unsigned characters, the first two
46  * are 64 bits of useful data, the last is 56 bits of useful
47  * data packed into 8 bytes, using the low 7 bits of each
48  * byte, filling the high bit with odd parity.
49  *
50  * Examine the XDMCP specification for the correct algorithm
51  */
52
53 #include "Wrap.h"
54
55 void
56 XdmcpUnwrap (input, wrapper, output, bytes)
57     unsigned char       *input, *output;
58     unsigned char       *wrapper;
59     int                 bytes;
60 {
61     int                 i, j, k;
62     unsigned char       tmp[8];
63     unsigned char       blocks[2][8];
64     unsigned char       expand_wrapper[8];
65     auth_wrapper_schedule       schedule;
66
67     _XdmcpWrapperToOddParity (wrapper, expand_wrapper);
68     _XdmcpAuthSetup (expand_wrapper, schedule);
69
70     k = 0;
71     for (j = 0; j < bytes; j += 8)
72     {
73         if (bytes - j < 8)
74             return; /* bad input length */
75         for (i = 0; i < 8; i++)
76             blocks[k][i] = input[j + i];
77         _XdmcpAuthDoIt ((unsigned char *) (input + j), (unsigned char *) tmp, schedule, 0);
78         /* block chaining */
79         k = (k == 0) ? 1 : 0;
80         for (i = 0; i < 8; i++)
81         {
82             if (j == 0)
83                 output[j + i] = tmp[i];
84             else
85                 output[j + i] = tmp[i] ^ blocks[k][i];
86         }
87     }
88 }
89
90 #endif /* HASXDMAUTH */