linux-warning-reduction-20090318
[openafs.git] / src / rxkad / domestic / crypt_conn.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /* The rxkad security object.  This contains packet processing routines that
11  * are prohibited from being exported. */
12
13
14 #include <afsconfig.h>
15 #ifdef KERNEL
16 #include "afs/param.h"
17 #else
18 #include <afs/param.h>
19 #endif
20
21 RCSID
22     ("$Header$");
23
24 #ifdef KERNEL
25 #include "afs/stds.h"
26 #ifndef UKERNEL
27 #include "h/types.h"
28 #if defined(AFS_AIX_ENV) || defined(AFS_AUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_XBSD_ENV)
29 #include "h/systm.h"
30 #endif
31 #include "rx/rx.h"
32 #include "netinet/in.h"
33 #else /* !UKERNEL */
34 #include "afs/sysincludes.h"
35 #include "rx/rx.h"
36 #endif /* !UKERNEL */
37 #else /* !KERNEL */
38 #include <afs/stds.h>
39 #include <sys/types.h>
40 #include <string.h>
41 #include <rx/rx.h>
42 #ifdef AFS_NT40_ENV
43 #include <winsock2.h>
44 #else
45 #include <netinet/in.h>
46 #endif
47 #endif /* KERNEL */
48
49 #include <des/stats.h>
50 #include "private_data.h"
51 #define XPRT_RXKAD_CRYPT
52
53 afs_int32
54 rxkad_DecryptPacket(const struct rx_connection *conn,
55                     const fc_KeySchedule * schedule,
56                     const fc_InitializationVector * ivec, const int inlen,
57                     struct rx_packet *packet)
58 {
59     afs_uint32 xor[2];
60     struct rx_securityClass *obj;
61     struct rxkad_cprivate *tp;  /* s & c have type at same offset */
62     char *data;
63     int i, tlen, len;
64
65     len = inlen;
66
67     obj = rx_SecurityObjectOf(conn);
68     tp = (struct rxkad_cprivate *)obj->privateData;
69     ADD_RXKAD_STATS(bytesDecrypted[rxkad_TypeIndex(tp->type)],len);
70     memcpy((void *)xor, (void *)ivec, sizeof(xor));
71     for (i = 0; len; i++) {
72         data = rx_data(packet, i, tlen);
73         if (!data || !tlen)
74             break;
75         tlen = MIN(len, tlen);
76         fc_cbc_encrypt(data, data, tlen, *schedule, xor, DECRYPT);
77         len -= tlen;
78     }
79     /* Do this if packet checksums are ever enabled (below), but
80      * current version just passes zero
81      afs_int32 cksum;
82      cksum = ntohl(rx_GetInt32(packet, 1));
83      */
84     return 0;
85 }
86
87 afs_int32
88 rxkad_EncryptPacket(const struct rx_connection * conn,
89                     const fc_KeySchedule * schedule,
90                     const fc_InitializationVector * ivec, const int inlen,
91                     struct rx_packet * packet)
92 {
93     afs_uint32 xor[2];
94     struct rx_securityClass *obj;
95     struct rxkad_cprivate *tp;  /* s & c have type at same offset */
96     char *data;
97     int i, tlen, len;
98
99     len = inlen;
100
101     obj = rx_SecurityObjectOf(conn);
102     tp = (struct rxkad_cprivate *)obj->privateData;
103     ADD_RXKAD_STATS(bytesEncrypted[rxkad_TypeIndex(tp->type)],len);
104     /*
105      * afs_int32 cksum;
106      * cksum = htonl(0);                
107      * * Future option to add cksum here, but for now we just put 0
108      */
109     rx_PutInt32(packet, 1 * sizeof(afs_int32), 0);
110
111     memcpy((void *)xor, (void *)ivec, sizeof(xor));
112     for (i = 0; len; i++) {
113         data = rx_data(packet, i, tlen);
114         if (!data || !tlen)
115             break;
116         tlen = MIN(len, tlen);
117         fc_cbc_encrypt(data, data, tlen, *schedule, xor, ENCRYPT);
118         len -= tlen;
119     }
120     return 0;
121 }