xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/crypto/hash_provider/hash_crc32.c (revision 55fea89dcaa64928bed4327112404dcb3e07b79f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (C) 1998 by the FundsXpress, INC.
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * All rights reserved.
57c478bd9Sstevel@tonic-gate  *
67c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may require
77c478bd9Sstevel@tonic-gate  * a specific license from the United States Government.  It is the
87c478bd9Sstevel@tonic-gate  * responsibility of any person or organization contemplating export to
97c478bd9Sstevel@tonic-gate  * obtain such a license before exporting.
107c478bd9Sstevel@tonic-gate  *
117c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
127c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
137c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
147c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
157c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
167c478bd9Sstevel@tonic-gate  * the name of FundsXpress. not be used in advertising or publicity pertaining
177c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
187c478bd9Sstevel@tonic-gate  * permission.  FundsXpress makes no representations about the suitability of
197c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
207c478bd9Sstevel@tonic-gate  * or implied warranty.
217c478bd9Sstevel@tonic-gate  *
227c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
237c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
247c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27*159d09a2SMark Phalan #include "k5-int.h"
28*159d09a2SMark Phalan #include "crc-32.h"
29*159d09a2SMark Phalan #include "hash_provider.h"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /* ARGSUSED */
327c478bd9Sstevel@tonic-gate static krb5_error_code
k5_crc32_hash(krb5_context context,unsigned int icount,krb5_const krb5_data * input,krb5_data * output)337c478bd9Sstevel@tonic-gate k5_crc32_hash(krb5_context context,
347c478bd9Sstevel@tonic-gate 	      unsigned int icount, krb5_const krb5_data *input,
357c478bd9Sstevel@tonic-gate 	      krb5_data *output)
367c478bd9Sstevel@tonic-gate {
377c478bd9Sstevel@tonic-gate     unsigned long c, cn;
387c478bd9Sstevel@tonic-gate     int i;
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate     if (output->length != CRC32_CKSUM_LENGTH)
417c478bd9Sstevel@tonic-gate 	return(KRB5_CRYPTO_INTERNAL);
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate     c = 0;
447c478bd9Sstevel@tonic-gate     for (i=0; i<icount; i++) {
457c478bd9Sstevel@tonic-gate 	mit_crc32(input[i].data, input[i].length, &cn);
467c478bd9Sstevel@tonic-gate 	c ^= cn;
477c478bd9Sstevel@tonic-gate     }
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate     output->data[0] = c&0xff;
507c478bd9Sstevel@tonic-gate     output->data[1] = (c>>8)&0xff;
517c478bd9Sstevel@tonic-gate     output->data[2] = (c>>16)&0xff;
527c478bd9Sstevel@tonic-gate     output->data[3] = (c>>24)&0xff;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate     return(0);
557c478bd9Sstevel@tonic-gate }
567c478bd9Sstevel@tonic-gate 
57*159d09a2SMark Phalan const struct krb5_hash_provider krb5int_hash_crc32 = {
58505d05c7Sgtb     CRC32_CKSUM_LENGTH,
59505d05c7Sgtb     1,
607c478bd9Sstevel@tonic-gate     k5_crc32_hash
617c478bd9Sstevel@tonic-gate };
62