xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/crypto/des/f_cksum.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * Copyright 2001-2003 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * des_cbc_cksum.c - compute an 8 byte checksum using DES in CBC mode
10  */
11 #include <des_int.h>
12 
13 /*
14  * This routine performs DES cipher-block-chaining checksum operation,
15  * a.k.a.  Message Authentication Code.  It ALWAYS encrypts from input
16  * to a single 64 bit output MAC checksum.
17  *
18  * The key schedule is passed as an arg, as well as the cleartext or
19  * ciphertext. The cleartext and ciphertext should be in host order.
20  *
21  * NOTE-- the output is ALWAYS 8 bytes long.  If not enough space was
22  * provided, your program will get trashed.
23  *
24  * The input is null padded, at the end (highest addr), to an integral
25  * multiple of eight bytes.
26  */
27 unsigned long
28 mit_des_cbc_cksum(krb5_context context,
29 	krb5_octet *in, krb5_octet *out,
30 	long length, krb5_keyblock *key,
31 	krb5_octet FAR *ivec)
32 {
33 	krb5_error_code ret = 0;
34 /* EXPORT DELETE START */
35 	krb5_data input;
36 	krb5_data output;
37 	krb5_data ivecdata;
38 
39 	input.data = (char *)in;
40 	input.length = length;
41 	output.data = (char *)out;
42 	output.length = MIT_DES_BLOCK_LENGTH;
43 	ivecdata.data = (char *)ivec;
44 	ivecdata.length = MIT_DES_BLOCK_LENGTH;
45 
46 	ret = k5_ef_mac(context, key, &ivecdata,
47 		(const krb5_data *)&input, &output);
48 
49 /* EXPORT DELETE END */
50 	return (ret);
51 }
52