23b33fc07d6c3ba79716bebbfd427ce64962ab77
[krb5.git] / src / lib / crypto / keyhash_provider / descbc.c
1 /*
2  * Copyright (C) 1998 by the FundsXpress, INC.
3  * 
4  * All rights reserved.
5  * 
6  * Export of this software from the United States of America may require
7  * a specific license from the United States Government.  It is the
8  * responsibility of any person or organization contemplating export to
9  * obtain such a license before exporting.
10  * 
11  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12  * distribute this software and its documentation for any purpose and
13  * without fee is hereby granted, provided that the above copyright
14  * notice appear in all copies and that both that copyright notice and
15  * this permission notice appear in supporting documentation, and that
16  * the name of FundsXpress. not be used in advertising or publicity pertaining
17  * to distribution of the software without specific, written prior
18  * permission.  FundsXpress makes no representations about the suitability of
19  * this software for any purpose.  It is provided "as is" without express
20  * or implied warranty.
21  * 
22  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
24  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25  */
26
27 #include "k5-int.h"
28 #include "des_int.h"
29 #include "keyhash_provider.h"
30
31 static krb5_error_code
32 k5_descbc_hash(const krb5_keyblock *key, krb5_keyusage usage, const krb5_data *ivec,
33                const krb5_data *input, krb5_data *output)
34 {
35     mit_des_key_schedule schedule;
36
37     if (key->length != 8)
38         return(KRB5_BAD_KEYSIZE);
39     if ((input->length%8) != 0)
40         return(KRB5_BAD_MSIZE);
41     if (ivec && (ivec->length != 8))
42         return(KRB5_CRYPTO_INTERNAL);
43     if (output->length != 8)
44         return(KRB5_CRYPTO_INTERNAL);
45
46     switch (mit_des_key_sched(key->contents, schedule)) {
47     case -1:
48         return(KRB5DES_BAD_KEYPAR);
49     case -2:
50         return(KRB5DES_WEAK_KEY);
51     }
52
53     /* this has a return value, but it's useless to us */
54
55     mit_des_cbc_cksum((unsigned char *) input->data, 
56                       (unsigned char *) output->data, input->length,
57                       schedule, 
58                       ivec? (const unsigned char *)ivec->data: 
59                             (const unsigned char *)mit_des_zeroblock);
60
61     memset(schedule, 0, sizeof(schedule));
62
63     return(0);
64 }
65
66 const struct krb5_keyhash_provider krb5int_keyhash_descbc = {
67     8,
68     k5_descbc_hash,
69     NULL
70 };