1 /* $NetBSD: mit_glue.c,v 1.1.1.2 2014/04/24 12:45:50 pettai Exp $ */
4 * Copyright (c) 2003 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "krb5_locl.h"
38 #ifndef HEIMDAL_SMALLER
44 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
45 krb5_c_make_checksum(krb5_context context
,
46 krb5_cksumtype cksumtype
,
47 const krb5_keyblock
*key
,
49 const krb5_data
*input
,
55 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
59 ret
= krb5_create_checksum(context
, crypto
, usage
, cksumtype
,
60 input
->data
, input
->length
, cksum
);
61 krb5_crypto_destroy(context
, crypto
);
66 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
67 krb5_c_verify_checksum(krb5_context context
, const krb5_keyblock
*key
,
68 krb5_keyusage usage
, const krb5_data
*data
,
69 const krb5_checksum
*cksum
, krb5_boolean
*valid
)
72 krb5_checksum data_cksum
;
76 ret
= krb5_c_make_checksum(context
, cksum
->cksumtype
,
77 key
, usage
, data
, &data_cksum
);
81 if (data_cksum
.cksumtype
== cksum
->cksumtype
82 && krb5_data_ct_cmp(&data_cksum
.checksum
, &cksum
->checksum
) == 0)
85 krb5_free_checksum_contents(context
, &data_cksum
);
90 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
91 krb5_c_get_checksum(krb5_context context
, const krb5_checksum
*cksum
,
92 krb5_cksumtype
*type
, krb5_data
**data
)
97 *type
= cksum
->cksumtype
;
99 *data
= malloc(sizeof(**data
));
103 ret
= der_copy_octet_string(&cksum
->checksum
, *data
);
113 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
114 krb5_c_set_checksum(krb5_context context
, krb5_checksum
*cksum
,
115 krb5_cksumtype type
, const krb5_data
*data
)
117 cksum
->cksumtype
= type
;
118 return der_copy_octet_string(data
, &cksum
->checksum
);
121 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
122 krb5_free_checksum (krb5_context context
, krb5_checksum
*cksum
)
124 krb5_checksum_free(context
, cksum
);
128 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
129 krb5_free_checksum_contents(krb5_context context
, krb5_checksum
*cksum
)
131 krb5_checksum_free(context
, cksum
);
132 memset(cksum
, 0, sizeof(*cksum
));
135 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
136 krb5_checksum_free(krb5_context context
, krb5_checksum
*cksum
)
138 free_Checksum(cksum
);
141 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
142 krb5_c_valid_enctype (krb5_enctype etype
)
144 return !krb5_enctype_valid(NULL
, etype
);
147 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
148 krb5_c_valid_cksumtype(krb5_cksumtype ctype
)
150 return krb5_cksumtype_valid(NULL
, ctype
);
153 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
154 krb5_c_is_coll_proof_cksum(krb5_cksumtype ctype
)
156 return krb5_checksum_is_collision_proof(NULL
, ctype
);
159 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
160 krb5_c_is_keyed_cksum(krb5_cksumtype ctype
)
162 return krb5_checksum_is_keyed(NULL
, ctype
);
165 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
166 krb5_copy_checksum (krb5_context context
,
167 const krb5_checksum
*old
,
170 *new = malloc(sizeof(**new));
173 return copy_Checksum(old
, *new);
176 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
177 krb5_c_checksum_length (krb5_context context
, krb5_cksumtype cksumtype
,
180 return krb5_checksumsize(context
, cksumtype
, length
);
183 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
184 krb5_c_block_size(krb5_context context
,
185 krb5_enctype enctype
,
192 ret
= krb5_generate_random_keyblock(context
, enctype
, &key
);
196 ret
= krb5_crypto_init(context
, &key
, 0, &crypto
);
197 krb5_free_keyblock_contents(context
, &key
);
200 ret
= krb5_crypto_getblocksize(context
, crypto
, blocksize
);
201 krb5_crypto_destroy(context
, crypto
);
206 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
207 krb5_c_decrypt(krb5_context context
,
208 const krb5_keyblock key
,
210 const krb5_data
*ivec
,
211 krb5_enc_data
*input
,
217 ret
= krb5_crypto_init(context
, &key
, input
->enctype
, &crypto
);
224 ret
= krb5_crypto_getblocksize(context
, crypto
, &blocksize
);
226 krb5_crypto_destroy(context
, crypto
);
230 if (blocksize
> ivec
->length
) {
231 krb5_crypto_destroy(context
, crypto
);
232 return KRB5_BAD_MSIZE
;
236 ret
= krb5_decrypt_ivec(context
, crypto
, usage
,
237 input
->ciphertext
.data
, input
->ciphertext
.length
,
239 ivec
? ivec
->data
: NULL
);
241 krb5_crypto_destroy(context
, crypto
);
246 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
247 krb5_c_encrypt(krb5_context context
,
248 const krb5_keyblock
*key
,
250 const krb5_data
*ivec
,
251 const krb5_data
*input
,
252 krb5_enc_data
*output
)
257 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
264 ret
= krb5_crypto_getblocksize(context
, crypto
, &blocksize
);
266 krb5_crypto_destroy(context
, crypto
);
270 if (blocksize
> ivec
->length
) {
271 krb5_crypto_destroy(context
, crypto
);
272 return KRB5_BAD_MSIZE
;
276 ret
= krb5_encrypt_ivec(context
, crypto
, usage
,
277 input
->data
, input
->length
,
279 ivec
? ivec
->data
: NULL
);
281 krb5_crypto_getenctype(context
, crypto
, &output
->enctype
);
283 krb5_crypto_destroy(context
, crypto
);
288 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
289 krb5_c_encrypt_length(krb5_context context
,
290 krb5_enctype enctype
,
298 ret
= krb5_generate_random_keyblock(context
, enctype
, &key
);
302 ret
= krb5_crypto_init(context
, &key
, 0, &crypto
);
303 krb5_free_keyblock_contents(context
, &key
);
307 *length
= krb5_get_wrapped_length(context
, crypto
, inputlen
);
308 krb5_crypto_destroy(context
, crypto
);
314 * Deprecated: keytypes doesn't exists, they are really enctypes.
316 * @ingroup krb5_deprecated
319 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
320 krb5_c_enctype_compare(krb5_context context
,
323 krb5_boolean
*similar
)
324 KRB5_DEPRECATED_FUNCTION("Use X instead")
326 *similar
= (e1
== e2
);
330 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
331 krb5_c_make_random_key(krb5_context context
,
332 krb5_enctype enctype
,
333 krb5_keyblock
*random_key
)
335 return krb5_generate_random_keyblock(context
, enctype
, random_key
);
338 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
339 krb5_c_keylengths(krb5_context context
,
340 krb5_enctype enctype
,
346 ret
= krb5_enctype_keybits(context
, enctype
, ilen
);
349 *ilen
= (*ilen
+ 7) / 8;
350 return krb5_enctype_keysize(context
, enctype
, keylen
);
353 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
354 krb5_c_prf_length(krb5_context context
,
358 return krb5_crypto_prf_length(context
, type
, length
);
361 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
362 krb5_c_prf(krb5_context context
,
363 const krb5_keyblock
*key
,
364 const krb5_data
*input
,
370 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
374 ret
= krb5_crypto_prf(context
, crypto
, input
, output
);
375 krb5_crypto_destroy(context
, crypto
);
380 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
381 krb5_c_random_make_octets(krb5_context context
, krb5_data
* data
)
383 return krb5_generate_random_keyblock(context
, data
->length
, data
->data
);
389 * @ingroup krb5_ccache
392 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
393 krb5_cc_copy_creds(krb5_context context
,
394 const krb5_ccache from
,
397 return krb5_cc_copy_cache(context
, from
, to
);
400 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
401 krb5_auth_con_getsendsubkey(krb5_context context
, krb5_auth_context auth_context
,
402 krb5_keyblock
**keyblock
)
404 return krb5_auth_con_getlocalsubkey(context
, auth_context
, keyblock
);
407 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
408 krb5_auth_con_getrecvsubkey(krb5_context context
, krb5_auth_context auth_context
,
409 krb5_keyblock
**keyblock
)
411 return krb5_auth_con_getremotesubkey(context
, auth_context
, keyblock
);
414 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
415 krb5_auth_con_setsendsubkey(krb5_context context
, krb5_auth_context auth_context
,
416 krb5_keyblock
*keyblock
)
418 return krb5_auth_con_setlocalsubkey(context
, auth_context
, keyblock
);
421 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
422 krb5_auth_con_setrecvsubkey(krb5_context context
, krb5_auth_context auth_context
,
423 krb5_keyblock
*keyblock
)
425 return krb5_auth_con_setremotesubkey(context
, auth_context
, keyblock
);
428 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
429 krb5_free_default_realm(krb5_context context
, krb5_realm realm
)
431 return krb5_xfree(realm
);
434 #endif /* HEIMDAL_SMALLER */