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