xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/crypto/hash_provider/hash_crc32.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 /*
3  * Copyright (C) 1998 by the FundsXpress, INC.
4  *
5  * All rights reserved.
6  *
7  * Export of this software from the United States of America may require
8  * a specific license from the United States Government.  It is the
9  * responsibility of any person or organization contemplating export to
10  * obtain such a license before exporting.
11  *
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of FundsXpress. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  FundsXpress makes no representations about the suitability of
20  * this software for any purpose.  It is provided "as is" without express
21  * or implied warranty.
22  *
23  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
25  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26  */
27 
28 #include <k5-int.h>
29 #include <gssapiP_krb5.h>
30 #include <crc-32.h>
31 #include <hash_provider.h>
32 
33 static void
34 k5_crc32_hash_size(size_t *output)
35 {
36     *output = CRC32_CKSUM_LENGTH;
37 }
38 
39 static void
40 k5_crc32_block_size(size_t *output)
41 {
42     *output = 1;
43 }
44 
45 /* ARGSUSED */
46 static krb5_error_code
47 k5_crc32_hash(krb5_context context,
48 	unsigned int icount, krb5_const krb5_data *input,
49 	krb5_data *output)
50 {
51     unsigned long c, cn;
52     int i;
53 
54     if (output->length != CRC32_CKSUM_LENGTH)
55 	return(KRB5_CRYPTO_INTERNAL);
56 
57     c = 0;
58     for (i=0; i<icount; i++) {
59 	mit_crc32(input[i].data, input[i].length, &cn);
60 	c ^= cn;
61     }
62 
63     output->data[0] = c&0xff;
64     output->data[1] = (c>>8)&0xff;
65     output->data[2] = (c>>16)&0xff;
66     output->data[3] = (c>>24)&0xff;
67 
68     return(0);
69 }
70 
71 const struct krb5_hash_provider krb5_hash_crc32 = {
72     k5_crc32_hash_size,
73     k5_crc32_block_size,
74     k5_crc32_hash
75 };
76