(nnpfs_block_open): better cleanup on failure
[arla.git] / rxkad / rxkad_locl.h
blob2658ad6b261b82d33c0f7733029442448da5e066
1 /*
2 * Copyright (c) 1995, 1996, 1997, 2003 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 /* @(#)$Id$ */
36 #ifndef __RXKAD_LOCL_H
37 #define __RXKAD_LOCL_H
39 /* $Id$ */
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
45 #include <stdlib.h>
46 #include <string.h>
47 #include <limits.h>
48 #include <time.h>
49 #include <errno.h>
51 #include <sys/types.h>
52 #include <netinet/in.h>
54 #include <roken.h> /* sometimes needed for strlcpy */
56 #ifdef NDEBUG
57 #ifndef assert
58 #define assert(e) ((void)0)
59 #endif
60 #else
61 #ifndef assert
62 #define assert(e) ((e) ? (void)0 : (void)osi_Panic("assert(%s) failed: file %s, line %d\n", #e, __FILE__, __LINE__, #e))
63 #endif
64 #endif
66 #ifdef HAVE_OPENSSL
67 #include <openssl/des.h>
68 #else
69 #include <des.h>
70 #endif
72 #undef RCSID
73 #include <rx/rx.h>
74 #undef RCSID
75 #define RCSID(msg) \
76 static /**/const char *const rcsid[] = { (char *)rcsid, "\100(#)" msg }
78 extern int rx_epoch, rx_nextCid;
80 #include "rxkad.h"
82 #define rxkad_disipline 3
84 #define rxkad_unallocated 1
85 #define rxkad_authenticated 2
86 #define rxkad_expired 4
87 #define rxkad_checksummed 8
89 #define ROUNDS 16
91 #define FC_ENCRYPT 1
92 #define FC_DECRYPT 0
94 int fc_keysched(const void *key_, int32_t sched[ROUNDS]);
96 /* In_ and out_ MUST be uint32_t aligned */
97 int fc_ecb_encrypt(const void *in_, void *out_,
98 const int32_t sched[ROUNDS], int encrypt);
100 /* In_ and out_ MUST be uint32_t aligned */
101 int fc_cbc_encrypt(const void *in_, void *out_, int32_t length,
102 const int32_t sched[ROUNDS], uint32_t iv[2],
103 int encrypt);
105 int rxkad_EncryptPacket(const void *rx_connection_not_used,
106 const int32_t sched[ROUNDS], const uint32_t iv[2],
107 int len, struct rx_packet *packet);
109 int rxkad_DecryptPacket(const void *rx_connection_not_used,
110 const int32_t sched[ROUNDS], const uint32_t iv[2],
111 int len, struct rx_packet *packet);
113 #ifdef __GNUC__
114 static inline
115 void
116 fc_cbc_enc2(const void *in, void *out, int32_t length, const int32_t sched[ROUNDS],
117 const uint32_t iv_[2], int encrypt)
119 uint32_t iv[2];
120 iv[0] = iv_[0];
121 iv[1] = iv_[1];
122 fc_cbc_encrypt(in, out, length, sched, iv, encrypt);
124 #else
125 #define fc_cbc_enc2(in, out, length, sched, iv_, encrypt) \
126 { uint32_t _iv_[2]; uint32_t *_tmp_ = (iv_); \
127 memcpy(_iv_, _tmp_, 8); \
128 fc_cbc_encrypt((in), (out), (length), (sched), (_iv_), (encrypt)); }
129 #endif
131 #define RXKAD_VERSION 2
133 /* Version 2 challenge format */
134 typedef struct rxkad_challenge {
135 int32_t version;
136 int32_t nonce;
137 int32_t min_level;
138 int32_t unused;
139 } rxkad_challenge;
141 /* To protect the client from being used as an oracle the response
142 * contains connection specific information. */
143 typedef struct rxkad_response {
144 int32_t version;
145 int32_t unused;
146 struct {
147 int32_t epoch;
148 int32_t cid;
149 uint32_t cksum; /* Cksum of this response */
150 int32_t security_index;
151 int32_t call_numbers[RX_MAXCALLS];
152 int32_t inc_nonce;
153 int32_t level;
154 } encrypted;
155 int32_t kvno;
156 int32_t ticket_len;
157 /* u_char the_ticket[ticket_len]; */
158 } rxkad_response;
160 typedef struct key_stuff {
161 int32_t keysched[ROUNDS];
162 struct ktc_encryptionKey key;
163 } key_stuff;
165 typedef struct end_stuff {
166 uint32_t header_iv[2];
167 uint32_t bytesReceived, packetsReceived, bytesSent, packetsSent;
168 } end_stuff;
170 uint32_t
171 rxkad_cksum_response(rxkad_response *r);
173 void
174 rxkad_calc_header_iv(const struct rx_connection *conn,
175 const int32_t sched[ROUNDS],
176 char *in_iv,
177 uint32_t out_iv[2]);
180 rxkad_prepare_packet(struct rx_packet *pkt, struct rx_connection *con,
181 int level, key_stuff *k, end_stuff *e);
184 rxkad_check_packet(struct rx_packet *pkt, struct rx_connection *con,
185 int level, key_stuff *k, end_stuff *e);
187 /* Per connection specific server data */
188 typedef struct serv_con_data {
189 end_stuff e;
190 key_stuff k;
191 uint32_t expires;
192 int32_t nonce;
193 char *user;
194 rxkad_level cur_level; /* Starts at min_level and can only increase */
195 char authenticated;
196 } serv_con_data;
198 #endif /* __RXKAD_LOCL_H */