kernel: Sync ACPICA with Intel's version 20140424.
[dragonfly.git] / lib / libatm / cache_key.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
8  * This Host ATM Research Platform ("HARP") file (the "Software") is
9  * made available by Network Computing Services, Inc. ("NetworkCS")
10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
11  * support of any kind.
12  *
13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17  * In no event shall NetworkCS be responsible for any damages, including
18  * but not limited to consequential damages, arising from or relating to
19  * any use of the Software or related support.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  * $FreeBSD: src/lib/libatm/cache_key.c,v 1.3.2.1 2001/09/28 16:52:10 dillon Exp $
27  * $DragonFly: src/lib/libatm/cache_key.c,v 1.3 2008/09/30 16:57:04 swildner Exp $
28  */
29
30 /*
31  * User Space Library Functions
32  * ----------------------------
33  *
34  * SCSP cache key computation
35  *
36  */
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
41 #include <net/if.h>
42 #include <netinet/in.h>
43 #include <netatm/port.h>
44 #include <netatm/atm.h>
45 #include <netatm/atm_if.h>
46 #include <netatm/atm_sap.h>
47 #include <netatm/atm_sys.h>
48 #include <netatm/atm_ioctl.h>
49
50 #include <md5.h>
51 #include <string.h>
52
53 #include "libatm.h"
54
55 /*
56  * Compute an SCSP cache key
57  *
58  * Arguments:
59  *      ap      pointer to an Atm_addr with the ATM address
60  *      ip      pointer to a struct in_addr with the IP address
61  *      ol      the required length of the cache key
62  *      op      pointer to receive cache key
63  *
64  * Returns:
65  *      none
66  *
67  */
68 void
69 scsp_cache_key(Atm_addr *ap, struct in_addr *ip, int ol, char *op)
70 {
71         int     i, len;
72         char    buff[32], digest[16];
73         MD5_CTX context;
74
75         /*
76          * Initialize
77          */
78         UM_ZERO(buff, sizeof(buff));
79
80         /*
81          * Copy the addresses into a buffer for MD5 computation
82          */
83         len = sizeof(struct in_addr) + ap->address_length;
84         if (len > sizeof(buff))
85                 len = sizeof(buff);
86         UM_COPY(ip, buff, sizeof(struct in_addr));
87         UM_COPY(ap->address, &buff[sizeof(struct in_addr)],
88                         len - sizeof(struct in_addr));
89
90         /*
91          * Compute the MD5 digest of the combined IP and ATM addresses
92          */
93         MD5Init(&context);
94         MD5Update(&context, buff, len);
95         MD5Final(digest, &context);
96
97         /*
98          * Fold the 16-byte digest to the required length
99          */
100         UM_ZERO((caddr_t)op, ol);
101         for (i = 0; i < 16; i++) {
102                 op[i % ol] = op[i % ol] ^ digest[i];
103         }
104 }