Unwrap.c revision ff559fab
1/*
2 * $Xorg: Unwrap.c,v 1.4 2001/02/09 02:03:48 xorgcvs Exp $
3 *
4 *
5Copyright 1989, 1998  The Open Group
6
7Permission to use, copy, modify, distribute, and sell this software and its
8documentation for any purpose is hereby granted without fee, provided that
9the above copyright notice appear in all copies and that both that
10copyright notice and this permission notice appear in supporting
11documentation.
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of The Open Group shall not be
24used in advertising or otherwise to promote the sale, use or other dealings
25in this Software without prior written authorization from The Open Group.
26 * *
27 * Author:  Keith Packard, MIT X Consortium
28 */
29
30/* $XFree86: xc/lib/Xdmcp/Unwrap.c,v 1.3 2001/01/17 19:42:44 dawes Exp $ */
31
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35#include <X11/Xos.h>
36#include <X11/X.h>
37#include <X11/Xmd.h>
38#include <X11/Xdmcp.h>
39
40#ifdef HASXDMAUTH
41
42/*
43 * The following function exists only to demonstrate the
44 * desired functional interface for this routine.  You will
45 * need to add the appropriate algorithm if you wish to
46 * use XDM-AUTHENTICATION-1/XDM-AUTHORIZATION-1.
47 *
48 * The interface for this routine is quite simple.  All three
49 * arguments are arrays of 8 unsigned characters, the first two
50 * are 64 bits of useful data, the last is 56 bits of useful
51 * data packed into 8 bytes, using the low 7 bits of each
52 * byte, filling the high bit with odd parity.
53 *
54 * Examine the XDMCP specification for the correct algorithm
55 */
56
57#include "Wrap.h"
58
59void
60XdmcpUnwrap (
61    unsigned char	*input,
62    unsigned char	*wrapper,
63    unsigned char	*output,
64    int			bytes)
65{
66    int			i, j, k;
67    unsigned char	tmp[8];
68    unsigned char	blocks[2][8];
69    unsigned char	expand_wrapper[8];
70    auth_wrapper_schedule	schedule;
71
72    _XdmcpWrapperToOddParity (wrapper, expand_wrapper);
73    _XdmcpAuthSetup (expand_wrapper, schedule);
74
75    k = 0;
76    for (j = 0; j < bytes; j += 8)
77    {
78	if (bytes - j < 8)
79	    return; /* bad input length */
80	for (i = 0; i < 8; i++)
81	    blocks[k][i] = input[j + i];
82	_XdmcpAuthDoIt ((unsigned char *) (input + j), (unsigned char *) tmp, schedule, 0);
83	/* block chaining */
84	k = (k == 0) ? 1 : 0;
85	for (i = 0; i < 8; i++)
86	{
87	    if (j == 0)
88		output[j + i] = tmp[i];
89	    else
90		output[j + i] = tmp[i] ^ blocks[k][i];
91	}
92    }
93}
94
95#endif /* HASXDMAUTH */
96