xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/crypto/keyhash_provider/descbc.c (revision 505d05c73a6e56769f263d4803b22eddd168ee24)
1 /*
2  * Copyright 2005 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  * Copyright (C) 1998 by the FundsXpress, INC.
10  *
11  * All rights reserved.
12  *
13  * Export of this software from the United States of America may require
14  * a specific license from the United States Government.  It is the
15  * responsibility of any person or organization contemplating export to
16  * obtain such a license before exporting.
17  *
18  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
19  * distribute this software and its documentation for any purpose and
20  * without fee is hereby granted, provided that the above copyright
21  * notice appear in all copies and that both that copyright notice and
22  * this permission notice appear in supporting documentation, and that
23  * the name of FundsXpress. not be used in advertising or publicity pertaining
24  * to distribution of the software without specific, written prior
25  * permission.  FundsXpress makes no representations about the suitability of
26  * this software for any purpose.  It is provided "as is" without express
27  * or implied warranty.
28  *
29  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
30  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
31  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  */
33 
34 #include <k5-int.h>
35 #include <des_int.h>
36 #include <keyhash_provider.h>
37 #ifdef _KERNEL
38 #include <sys/kmem.h>
39 #include <sys/crypto/api.h>
40 #endif
41 
42 /*ARGSUSED*/
43 static krb5_error_code
44 k5_descbc_hash(krb5_context context,
45 	krb5_const krb5_keyblock *key,
46 	krb5_keyusage usage,
47 	krb5_const krb5_data *ivec,
48 	krb5_const krb5_data *input, krb5_data *output)
49 {
50     int ret;
51     krb5_data zero_ivec;
52 
53     if (key->length != MIT_DES_KEYSIZE)
54 	return(KRB5_BAD_KEYSIZE);
55     if ((input->length%8) != 0)
56 	return(KRB5_BAD_MSIZE);
57     if (ivec && (ivec->length != MIT_DES_BLOCK_LENGTH))
58 	return(KRB5_CRYPTO_INTERNAL);
59     if (output->length != MIT_DES_BLOCK_LENGTH)
60 	return(KRB5_CRYPTO_INTERNAL);
61 
62     zero_ivec.data = (char *)mit_des_zeroblock;
63     zero_ivec.length = sizeof(mit_des_zeroblock);
64 
65     ret = k5_ef_mac(context, (krb5_keyblock *)key,
66 	ivec ? (krb5_data *)ivec : &zero_ivec, input, output);
67 
68     return(ret);
69 }
70 
71 const struct krb5_keyhash_provider krb5_keyhash_descbc = {
72     MIT_DES_BLOCK_LENGTH,
73     k5_descbc_hash,
74     NULL
75 };
76