1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
/*
* Copyright (C) 1998 by the FundsXpress, INC.
*
* All rights reserved.
*
* Export of this software from the United States of America may require
* a specific license from the United States Government. It is the
* responsibility of any person or organization contemplating export to
* obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of FundsXpress. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. FundsXpress makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "k5-int.h"
krb5_error_code KRB5_CALLCONV
krb5_encrypt(context, inptr, outptr, size, eblock, ivec)
krb5_context context;
krb5_const_pointer inptr;
krb5_pointer outptr;
size_t size;
krb5_encrypt_block * eblock;
krb5_pointer ivec;
{
krb5_data inputd, ivecd;
krb5_enc_data outputd;
size_t blocksize, outlen;
krb5_error_code ret;
if (ivec) {
if ((ret = krb5_c_block_size(context, eblock->key->enctype, &blocksize)))
return(ret);
ivecd.length = blocksize;
ivecd.data = ivec;
}
/* size is the length of the input cleartext data */
inputd.length = size;
inputd.data = inptr;
/* The size of the output buffer isn't part of the old api. Not too
safe. So, we assume here that it's big enough. */
if ((ret = krb5_c_encrypt_length(context, eblock->key->enctype, size,
&outlen)))
return(ret);
outputd.ciphertext.length = outlen;
outputd.ciphertext.data = outptr;
return(krb5_c_encrypt(context, eblock->key, 0, ivec?&ivecd:0,
&inputd, &outputd));
}
krb5_error_code KRB5_CALLCONV
krb5_decrypt(context, inptr, outptr, size, eblock, ivec)
krb5_context context;
krb5_const_pointer inptr;
krb5_pointer outptr;
size_t size;
krb5_encrypt_block * eblock;
krb5_pointer ivec;
{
krb5_enc_data inputd;
krb5_data outputd, ivecd;
size_t blocksize;
krb5_error_code ret;
if (ivec) {
if ((ret = krb5_c_block_size(context, eblock->key->enctype, &blocksize)))
return(ret);
ivecd.length = blocksize;
ivecd.data = ivec;
}
/* size is the length of the input ciphertext data */
inputd.enctype = eblock->key->enctype;
inputd.ciphertext.length = size;
inputd.ciphertext.data = inptr;
/* we don't really know how big this is, but the code tends to assume
that the output buffer size should be the same as the input
buffer size */
outputd.length = size;
outputd.data = outptr;
return(krb5_c_decrypt(context, eblock->key, 0, ivec?&ivecd:0,
&inputd, &outputd));
}
krb5_error_code KRB5_CALLCONV
krb5_process_key(context, eblock, key)
krb5_context context;
krb5_encrypt_block * eblock;
const krb5_keyblock * key;
{
eblock->key = (krb5_keyblock *) key;
return(0);
}
krb5_error_code KRB5_CALLCONV
krb5_finish_key(context, eblock)
krb5_context context;
krb5_encrypt_block * eblock;
{
return(0);
}
krb5_error_code KRB5_CALLCONV
krb5_string_to_key(context, eblock, keyblock, data, salt)
krb5_context context;
const krb5_encrypt_block * eblock;
krb5_keyblock * keyblock;
const krb5_data * data;
const krb5_data * salt;
{
return(krb5_c_string_to_key(context, eblock->crypto_entry, data, salt,
keyblock));
}
krb5_error_code KRB5_CALLCONV
krb5_init_random_key(context, eblock, keyblock, ptr)
krb5_context context;
const krb5_encrypt_block * eblock;
const krb5_keyblock * keyblock;
krb5_pointer * ptr;
{
krb5_data data;
data.length = keyblock->length;
data.data = (char *) keyblock->contents;
return(krb5_c_random_seed(context, &data));
}
krb5_error_code KRB5_CALLCONV
krb5_finish_random_key(context, eblock, ptr)
krb5_context context;
const krb5_encrypt_block * eblock;
krb5_pointer * ptr;
{
return(0);
}
krb5_error_code KRB5_CALLCONV
krb5_random_key(context, eblock, ptr, keyblock)
krb5_context context;
const krb5_encrypt_block * eblock;
krb5_pointer ptr;
krb5_keyblock ** keyblock;
{
krb5_keyblock *key;
krb5_error_code ret;
if ((key = (krb5_keyblock *) malloc(sizeof(krb5_keyblock))) == NULL)
return(ENOMEM);
if ((ret = krb5_c_make_random_key(context, eblock->crypto_entry, key)))
free(key);
*keyblock = key;
return(ret);
}
krb5_enctype KRB5_CALLCONV
krb5_eblock_enctype(context, eblock)
krb5_context context;
const krb5_encrypt_block * eblock;
{
return(eblock->crypto_entry);
}
krb5_error_code KRB5_CALLCONV
krb5_use_enctype(context, eblock, enctype)
krb5_context context;
krb5_encrypt_block * eblock;
const krb5_enctype enctype;
{
eblock->crypto_entry = enctype;
return(0);
}
size_t KRB5_CALLCONV
krb5_encrypt_size(length, crypto)
size_t length;
krb5_enctype crypto;
{
size_t ret;
if (krb5_c_encrypt_length(/* XXX */ 0, crypto, length, &ret))
return(-1); /* XXX */
return(ret);
}
size_t KRB5_CALLCONV
krb5_checksum_size(context, ctype)
krb5_context context;
krb5_cksumtype ctype;
{
size_t ret;
if (krb5_c_checksum_length(context, ctype, &ret))
return(-1); /* XXX */
return(ret);
}
krb5_error_code KRB5_CALLCONV
krb5_calculate_checksum(context, ctype, in, in_length,
seed, seed_length, outcksum)
krb5_context context;
krb5_cksumtype ctype;
krb5_const_pointer in;
size_t in_length;
krb5_const_pointer seed;
size_t seed_length;
krb5_checksum * outcksum;
{
krb5_data input;
krb5_keyblock key;
krb5_error_code ret;
krb5_checksum cksum;
input.data = in;
input.length = in_length;
key.length = seed_length;
key.contents = seed;
if ((ret = krb5_c_make_checksum(context, ctype, &key, 0, &input, &cksum)))
return(ret);
if (outcksum->length < cksum.length) {
memset(cksum.contents, 0, cksum.length);
free(cksum.contents);
return(KRB5_BAD_MSIZE);
}
outcksum->magic = cksum.magic;
outcksum->checksum_type = cksum.checksum_type;
memcpy(outcksum->contents, cksum.contents, cksum.length);
outcksum->length = cksum.length;
free(cksum.contents);
return(0);
}
krb5_error_code KRB5_CALLCONV
krb5_verify_checksum(context, ctype, cksum, in, in_length,
seed, seed_length)
krb5_context context;
krb5_cksumtype ctype;
const krb5_checksum * cksum;
krb5_const_pointer in;
size_t in_length;
krb5_const_pointer seed;
size_t seed_length;
{
krb5_data input;
krb5_keyblock key;
krb5_error_code ret;
krb5_boolean valid;
input.data = in;
input.length = in_length;
key.length = seed_length;
key.contents = seed;
if ((ret = krb5_c_verify_checksum(context, &key, 0, &input, cksum,
&valid)))
return(ret);
if (!valid)
return(KRB5KRB_AP_ERR_BAD_INTEGRITY);
return(0);
}
krb5_error_code KRB5_CALLCONV
krb5_random_confounder(size, ptr)
size_t size;
krb5_pointer ptr;
{
krb5_data random_data;
random_data.length = size;
random_data.data = ptr;
return(krb5_c_random_make_octets(/* XXX */ 0, &random_data));
}
krb5_error_code krb5_encrypt_data(context, key, ivec, data, enc_data)
krb5_context context;
krb5_keyblock *key;
krb5_pointer ivec;
krb5_data *data;
krb5_enc_data *enc_data;
{
krb5_error_code ret;
size_t enclen, blocksize;
krb5_data ivecd;
if ((ret = krb5_c_encrypt_length(context, key->enctype, data->length,
&enclen)))
return(ret);
if (ivec) {
if ((ret = krb5_c_block_size(context, key->enctype, &blocksize)))
return(ret);
ivecd.length = blocksize;
ivecd.data = ivec;
}
enc_data->magic = KV5M_ENC_DATA;
enc_data->kvno = 0;
enc_data->enctype = key->enctype;
enc_data->ciphertext.length = enclen;
if ((enc_data->ciphertext.data = malloc(enclen)) == NULL)
return(ENOMEM);
if ((ret = krb5_c_encrypt(context, key, 0, ivec?&ivecd:0, data, enc_data)))
free(enc_data->ciphertext.data);
return(ret);
}
krb5_error_code krb5_decrypt_data(context, key, ivec, enc_data, data)
krb5_context context;
krb5_keyblock *key;
krb5_pointer ivec;
krb5_enc_data *enc_data;
krb5_data *data;
{
krb5_error_code ret;
krb5_data ivecd;
size_t blocksize;
if (ivec) {
if ((ret = krb5_c_block_size(context, key->enctype, &blocksize)))
return(ret);
ivecd.length = blocksize;
ivecd.data = ivec;
}
data->length = enc_data->ciphertext.length;
if ((data->data = (char *) malloc(data->length)) == NULL)
return(ENOMEM);
if ((ret = krb5_c_decrypt(context, key, 0, ivec?&ivecd:0, enc_data, data)))
free(data->data);
return(0);
}
|