xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/crypto/keyhash_provider/descbc.c (revision 55fea89dcaa64928bed4327112404dcb3e07b79f)
17c478bd9Sstevel@tonic-gate /*
2*159d09a2SMark Phalan  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate 
77c478bd9Sstevel@tonic-gate /*
87c478bd9Sstevel@tonic-gate  * Copyright (C) 1998 by the FundsXpress, INC.
97c478bd9Sstevel@tonic-gate  *
107c478bd9Sstevel@tonic-gate  * All rights reserved.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may require
137c478bd9Sstevel@tonic-gate  * a specific license from the United States Government.  It is the
147c478bd9Sstevel@tonic-gate  * responsibility of any person or organization contemplating export to
157c478bd9Sstevel@tonic-gate  * obtain such a license before exporting.
167c478bd9Sstevel@tonic-gate  *
177c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
187c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
197c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
207c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
217c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
227c478bd9Sstevel@tonic-gate  * the name of FundsXpress. not be used in advertising or publicity pertaining
237c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
247c478bd9Sstevel@tonic-gate  * permission.  FundsXpress makes no representations about the suitability of
257c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
267c478bd9Sstevel@tonic-gate  * or implied warranty.
277c478bd9Sstevel@tonic-gate  *
287c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
297c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
307c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
33*159d09a2SMark Phalan #include "k5-int.h"
34*159d09a2SMark Phalan #include "des_int.h"
35*159d09a2SMark Phalan #include "keyhash_provider.h"
367c478bd9Sstevel@tonic-gate #ifdef _KERNEL
377c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
387c478bd9Sstevel@tonic-gate #include <sys/crypto/api.h>
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*ARGSUSED*/
427c478bd9Sstevel@tonic-gate static krb5_error_code
k5_descbc_hash(krb5_context context,krb5_const krb5_keyblock * key,krb5_keyusage usage,krb5_const krb5_data * ivec,krb5_const krb5_data * input,krb5_data * output)437c478bd9Sstevel@tonic-gate k5_descbc_hash(krb5_context context,
447c478bd9Sstevel@tonic-gate 	krb5_const krb5_keyblock *key,
457c478bd9Sstevel@tonic-gate 	krb5_keyusage usage,
467c478bd9Sstevel@tonic-gate 	krb5_const krb5_data *ivec,
477c478bd9Sstevel@tonic-gate 	krb5_const krb5_data *input, krb5_data *output)
487c478bd9Sstevel@tonic-gate {
497c478bd9Sstevel@tonic-gate     int ret;
507c478bd9Sstevel@tonic-gate     krb5_data zero_ivec;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate     if (key->length != MIT_DES_KEYSIZE)
537c478bd9Sstevel@tonic-gate 	return(KRB5_BAD_KEYSIZE);
547c478bd9Sstevel@tonic-gate     if ((input->length%8) != 0)
557c478bd9Sstevel@tonic-gate 	return(KRB5_BAD_MSIZE);
567c478bd9Sstevel@tonic-gate     if (ivec && (ivec->length != MIT_DES_BLOCK_LENGTH))
577c478bd9Sstevel@tonic-gate 	return(KRB5_CRYPTO_INTERNAL);
587c478bd9Sstevel@tonic-gate     if (output->length != MIT_DES_BLOCK_LENGTH)
597c478bd9Sstevel@tonic-gate 	return(KRB5_CRYPTO_INTERNAL);
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate     zero_ivec.data = (char *)mit_des_zeroblock;
627c478bd9Sstevel@tonic-gate     zero_ivec.length = sizeof(mit_des_zeroblock);
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate     ret = k5_ef_mac(context, (krb5_keyblock *)key,
657c478bd9Sstevel@tonic-gate 	ivec ? (krb5_data *)ivec : &zero_ivec, input, output);
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate     return(ret);
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate 
70*159d09a2SMark Phalan const struct krb5_keyhash_provider krb5int_keyhash_descbc = {
71505d05c7Sgtb     MIT_DES_BLOCK_LENGTH,
727c478bd9Sstevel@tonic-gate     k5_descbc_hash,
737c478bd9Sstevel@tonic-gate     NULL
747c478bd9Sstevel@tonic-gate };
75