2 * Copyright (c) 2003 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
34 #include "krb5_locl.h"
36 #ifndef HEIMDAL_SMALLER
42 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
43 krb5_c_make_checksum(krb5_context context
,
44 krb5_cksumtype cksumtype
,
45 const krb5_keyblock
*key
,
47 const krb5_data
*input
,
53 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
57 ret
= krb5_create_checksum(context
, crypto
, usage
, cksumtype
,
58 input
->data
, input
->length
, cksum
);
59 krb5_crypto_destroy(context
, crypto
);
64 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
65 krb5_c_verify_checksum(krb5_context context
, const krb5_keyblock
*key
,
66 krb5_keyusage usage
, const krb5_data
*data
,
67 const krb5_checksum
*cksum
, krb5_boolean
*valid
)
70 krb5_checksum data_cksum
;
74 ret
= krb5_c_make_checksum(context
, cksum
->cksumtype
,
75 key
, usage
, data
, &data_cksum
);
79 if (data_cksum
.cksumtype
== cksum
->cksumtype
80 && krb5_data_ct_cmp(&data_cksum
.checksum
, &cksum
->checksum
) == 0)
83 krb5_free_checksum_contents(context
, &data_cksum
);
88 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
89 krb5_c_get_checksum(krb5_context context
, const krb5_checksum
*cksum
,
90 krb5_cksumtype
*type
, krb5_data
**data
)
95 *type
= cksum
->cksumtype
;
97 *data
= malloc(sizeof(**data
));
99 return krb5_enomem(context
);
101 ret
= der_copy_octet_string(&cksum
->checksum
, *data
);
111 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
112 krb5_c_set_checksum(krb5_context context
, krb5_checksum
*cksum
,
113 krb5_cksumtype type
, const krb5_data
*data
)
115 cksum
->cksumtype
= type
;
116 return der_copy_octet_string(data
, &cksum
->checksum
);
119 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
120 krb5_free_checksum (krb5_context context
, krb5_checksum
*cksum
)
122 krb5_checksum_free(context
, cksum
);
126 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
127 krb5_free_checksum_contents(krb5_context context
, krb5_checksum
*cksum
)
129 krb5_checksum_free(context
, cksum
);
130 memset(cksum
, 0, sizeof(*cksum
));
133 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
134 krb5_checksum_free(krb5_context context
, krb5_checksum
*cksum
)
136 free_Checksum(cksum
);
139 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
140 krb5_c_valid_enctype (krb5_enctype etype
)
142 return !krb5_enctype_valid(NULL
, etype
);
145 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
146 krb5_c_valid_cksumtype(krb5_cksumtype ctype
)
148 return krb5_cksumtype_valid(NULL
, ctype
);
151 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
152 krb5_c_is_coll_proof_cksum(krb5_cksumtype ctype
)
154 return krb5_checksum_is_collision_proof(NULL
, ctype
);
157 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
158 krb5_c_is_keyed_cksum(krb5_cksumtype ctype
)
160 return krb5_checksum_is_keyed(NULL
, ctype
);
163 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
164 krb5_copy_checksum (krb5_context context
,
165 const krb5_checksum
*old
,
168 *new = malloc(sizeof(**new));
170 return krb5_enomem(context
);
171 return copy_Checksum(old
, *new);
174 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
175 krb5_c_checksum_length (krb5_context context
, krb5_cksumtype cksumtype
,
178 return krb5_checksumsize(context
, cksumtype
, length
);
181 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
182 krb5_c_block_size(krb5_context context
,
183 krb5_enctype enctype
,
190 ret
= krb5_generate_random_keyblock(context
, enctype
, &key
);
194 ret
= krb5_crypto_init(context
, &key
, 0, &crypto
);
195 krb5_free_keyblock_contents(context
, &key
);
198 ret
= krb5_crypto_getblocksize(context
, crypto
, blocksize
);
199 krb5_crypto_destroy(context
, crypto
);
204 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
205 krb5_c_decrypt(krb5_context context
,
206 const krb5_keyblock key
,
208 const krb5_data
*ivec
,
209 krb5_enc_data
*input
,
215 ret
= krb5_crypto_init(context
, &key
, input
->enctype
, &crypto
);
222 ret
= krb5_crypto_getblocksize(context
, crypto
, &blocksize
);
224 krb5_crypto_destroy(context
, crypto
);
228 if (blocksize
> ivec
->length
) {
229 krb5_crypto_destroy(context
, crypto
);
230 return KRB5_BAD_MSIZE
;
234 ret
= krb5_decrypt_ivec(context
, crypto
, usage
,
235 input
->ciphertext
.data
, input
->ciphertext
.length
,
237 ivec
? ivec
->data
: NULL
);
239 krb5_crypto_destroy(context
, crypto
);
244 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
245 krb5_c_encrypt(krb5_context context
,
246 const krb5_keyblock
*key
,
248 const krb5_data
*ivec
,
249 const krb5_data
*input
,
250 krb5_enc_data
*output
)
255 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
262 ret
= krb5_crypto_getblocksize(context
, crypto
, &blocksize
);
264 krb5_crypto_destroy(context
, crypto
);
268 if (blocksize
> ivec
->length
) {
269 krb5_crypto_destroy(context
, crypto
);
270 return KRB5_BAD_MSIZE
;
274 ret
= krb5_encrypt_ivec(context
, crypto
, usage
,
275 input
->data
, input
->length
,
277 ivec
? ivec
->data
: NULL
);
279 krb5_crypto_getenctype(context
, crypto
, &output
->enctype
);
281 krb5_crypto_destroy(context
, crypto
);
286 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
287 krb5_c_encrypt_length(krb5_context context
,
288 krb5_enctype enctype
,
296 ret
= krb5_generate_random_keyblock(context
, enctype
, &key
);
300 ret
= krb5_crypto_init(context
, &key
, 0, &crypto
);
301 krb5_free_keyblock_contents(context
, &key
);
305 *length
= krb5_get_wrapped_length(context
, crypto
, inputlen
);
306 krb5_crypto_destroy(context
, crypto
);
312 * Deprecated: keytypes doesn't exists, they are really enctypes.
314 * @ingroup krb5_deprecated
317 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
318 krb5_c_enctype_compare(krb5_context context
,
321 krb5_boolean
*similar
)
322 KRB5_DEPRECATED_FUNCTION("Use X instead")
324 *similar
= (e1
== e2
);
328 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
329 krb5_c_make_random_key(krb5_context context
,
330 krb5_enctype enctype
,
331 krb5_keyblock
*random_key
)
333 return krb5_generate_random_keyblock(context
, enctype
, random_key
);
336 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
337 krb5_c_keylengths(krb5_context context
,
338 krb5_enctype enctype
,
344 ret
= krb5_enctype_keybits(context
, enctype
, ilen
);
347 *ilen
= (*ilen
+ 7) / 8;
348 return krb5_enctype_keysize(context
, enctype
, keylen
);
351 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
352 krb5_c_prf_length(krb5_context context
,
356 return krb5_crypto_prf_length(context
, type
, length
);
359 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
360 krb5_c_prf(krb5_context context
,
361 const krb5_keyblock
*key
,
362 const krb5_data
*input
,
368 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
372 ret
= krb5_crypto_prf(context
, crypto
, input
, output
);
373 krb5_crypto_destroy(context
, crypto
);
378 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
379 krb5_c_random_make_octets(krb5_context context
, krb5_data
* data
)
381 krb5_generate_random_block(data
->data
, data
->length
);
388 * @ingroup krb5_ccache
391 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
392 krb5_cc_copy_creds(krb5_context context
,
393 const krb5_ccache from
,
396 return krb5_cc_copy_cache(context
, from
, to
);
399 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
400 krb5_auth_con_getsendsubkey(krb5_context context
, krb5_auth_context auth_context
,
401 krb5_keyblock
**keyblock
)
403 return krb5_auth_con_getlocalsubkey(context
, auth_context
, keyblock
);
406 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
407 krb5_auth_con_getrecvsubkey(krb5_context context
, krb5_auth_context auth_context
,
408 krb5_keyblock
**keyblock
)
410 return krb5_auth_con_getremotesubkey(context
, auth_context
, keyblock
);
413 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
414 krb5_auth_con_setsendsubkey(krb5_context context
, krb5_auth_context auth_context
,
415 krb5_keyblock
*keyblock
)
417 return krb5_auth_con_setlocalsubkey(context
, auth_context
, keyblock
);
420 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
421 krb5_auth_con_setrecvsubkey(krb5_context context
, krb5_auth_context auth_context
,
422 krb5_keyblock
*keyblock
)
424 return krb5_auth_con_setremotesubkey(context
, auth_context
, keyblock
);
427 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
428 krb5_free_default_realm(krb5_context context
, krb5_realm realm
)
430 return krb5_xfree(realm
);
433 #endif /* HEIMDAL_SMALLER */