49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * CDDL HEADER START
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * The contents of this file are subject to the terms of the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Common Development and Distribution License (the "License").
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * You may not use this file except in compliance with the License.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * or http://www.opensolaris.org/os/licensing.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * See the License for the specific language governing permissions
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * and limitations under the License.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * When distributing Covered Code, include this CDDL HEADER in each
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * If applicable, add the following below this CDDL HEADER, with the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * fields enclosed by brackets "[]" replaced with your own identifying
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * information: Portions Copyright [yyyy] [name of copyright owner]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * CDDL HEADER END
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Use is subject to license terms.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore/* Little-endian architectures need byte-swapping. */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#define sws(x) (((x >> 8) & 0x00ff) | ((x << 8) & 0xff00))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#define swl(x) (sws(x >> 16) | (sws(x) << 16))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#else /* if !_LITTLE_ENDIAN */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore/* Big-endian anchictectures don't need byte-swapping. */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#endif /* _LITTLE_ENDIAN */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amorecompute_crc8(unsigned char *bytes, int length)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore p_crc->cm_poly = 0x107; /* = X^8 + x^2 + x + 1 */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore for (i = 0; i < length; i++) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amorecompute_crc32(unsigned char *bytes, int length)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore for (i = 0; i < length; i++) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * This is the max value an uint32_t value can hold...
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Define this for Windows compilers which don't have "limits.h" or equivalant
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amorecompute_checksum32(unsigned char *bytes, int length)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore unsigned char tailbytes[4] = { 0x00, 0x00, 0x00, 0x00 };
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Grab bytes in 4-byte chunks */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Grab chunk as an int */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Add intval to regval */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Grab any remaining bytes at the end */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore for (j = length-1, k = 3; j >= i; j--, k--) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Treat any remaining bytes put into tailbytes as if they were
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * a left-zero-padded unsigned int (uint32_t == 4 bytes!)