/* checksum.c generated by valac 0.16.1, the Vala compiler
 * generated from checksum.vala, do not modify */

/* 
 * (c) 2010-2012 Frederik 'playya' Sdun <Frederik.Sdun@googlemail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 */

#include <glib.h>
#include <glib-object.h>




guint16 fso_framework_checksum_crc16 (guint8* data, int data_length1);
gboolean fso_framework_checksum_crc16_verify (guint8* data, int data_length1, guint16 expected);

const guint16 FSO_FRAMEWORK_CHECKSUM_crc16tab_fcs[256] = {(guint16) 0x0000, (guint16) 0x1189, (guint16) 0x2312, (guint16) 0x329b, (guint16) 0x4624, (guint16) 0x57ad, (guint16) 0x6536, (guint16) 0x74bf, (guint16) 0x8c48, (guint16) 0x9dc1, (guint16) 0xaf5a, (guint16) 0xbed3, (guint16) 0xca6c, (guint16) 0xdbe5, (guint16) 0xe97e, (guint16) 0xf8f7, (guint16) 0x1081, (guint16) 0x0108, (guint16) 0x3393, (guint16) 0x221a, (guint16) 0x56a5, (guint16) 0x472c, (guint16) 0x75b7, (guint16) 0x643e, (guint16) 0x9cc9, (guint16) 0x8d40, (guint16) 0xbfdb, (guint16) 0xae52, (guint16) 0xdaed, (guint16) 0xcb64, (guint16) 0xf9ff, (guint16) 0xe876, (guint16) 0x2102, (guint16) 0x308b, (guint16) 0x0210, (guint16) 0x1399, (guint16) 0x6726, (guint16) 0x76af, (guint16) 0x4434, (guint16) 0x55bd, (guint16) 0xad4a, (guint16) 0xbcc3, (guint16) 0x8e58, (guint16) 0x9fd1, (guint16) 0xeb6e, (guint16) 0xfae7, (guint16) 0xc87c, (guint16) 0xd9f5, (guint16) 0x3183, (guint16) 0x200a, (guint16) 0x1291, (guint16) 0x0318, (guint16) 0x77a7, (guint16) 0x662e, (guint16) 0x54b5, (guint16) 0x453c, (guint16) 0xbdcb, (guint16) 0xac42, (guint16) 0x9ed9, (guint16) 0x8f50, (guint16) 0xfbef, (guint16) 0xea66, (guint16) 0xd8fd, (guint16) 0xc974, (guint16) 0x4204, (guint16) 0x538d, (guint16) 0x6116, (guint16) 0x709f, (guint16) 0x0420, (guint16) 0x15a9, (guint16) 0x2732, (guint16) 0x36bb, (guint16) 0xce4c, (guint16) 0xdfc5, (guint16) 0xed5e, (guint16) 0xfcd7, (guint16) 0x8868, (guint16) 0x99e1, (guint16) 0xab7a, (guint16) 0xbaf3, (guint16) 0x5285, (guint16) 0x430c, (guint16) 0x7197, (guint16) 0x601e, (guint16) 0x14a1, (guint16) 0x0528, (guint16) 0x37b3, (guint16) 0x263a, (guint16) 0xdecd, (guint16) 0xcf44, (guint16) 0xfddf, (guint16) 0xec56, (guint16) 0x98e9, (guint16) 0x8960, (guint16) 0xbbfb, (guint16) 0xaa72, (guint16) 0x6306, (guint16) 0x728f, (guint16) 0x4014, (guint16) 0x519d, (guint16) 0x2522, (guint16) 0x34ab, (guint16) 0x0630, (guint16) 0x17b9, (guint16) 0xef4e, (guint16) 0xfec7, (guint16) 0xcc5c, (guint16) 0xddd5, (guint16) 0xa96a, (guint16) 0xb8e3, (guint16) 0x8a78, (guint16) 0x9bf1, (guint16) 0x7387, (guint16) 0x620e, (guint16) 0x5095, (guint16) 0x411c, (guint16) 0x35a3, (guint16) 0x242a, (guint16) 0x16b1, (guint16) 0x0738, (guint16) 0xffcf, (guint16) 0xee46, (guint16) 0xdcdd, (guint16) 0xcd54, (guint16) 0xb9eb, (guint16) 0xa862, (guint16) 0x9af9, (guint16) 0x8b70, (guint16) 0x8408, (guint16) 0x9581, (guint16) 0xa71a, (guint16) 0xb693, (guint16) 0xc22c, (guint16) 0xd3a5, (guint16) 0xe13e, (guint16) 0xf0b7, (guint16) 0x0840, (guint16) 0x19c9, (guint16) 0x2b52, (guint16) 0x3adb, (guint16) 0x4e64, (guint16) 0x5fed, (guint16) 0x6d76, (guint16) 0x7cff, (guint16) 0x9489, (guint16) 0x8500, (guint16) 0xb79b, (guint16) 0xa612, (guint16) 0xd2ad, (guint16) 0xc324, (guint16) 0xf1bf, (guint16) 0xe036, (guint16) 0x18c1, (guint16) 0x0948, (guint16) 0x3bd3, (guint16) 0x2a5a, (guint16) 0x5ee5, (guint16) 0x4f6c, (guint16) 0x7df7, (guint16) 0x6c7e, (guint16) 0xa50a, (guint16) 0xb483, (guint16) 0x8618, (guint16) 0x9791, (guint16) 0xe32e, (guint16) 0xf2a7, (guint16) 0xc03c, (guint16) 0xd1b5, (guint16) 0x2942, (guint16) 0x38cb, (guint16) 0x0a50, (guint16) 0x1bd9, (guint16) 0x6f66, (guint16) 0x7eef, (guint16) 0x4c74, (guint16) 0x5dfd, (guint16) 0xb58b, (guint16) 0xa402, (guint16) 0x9699, (guint16) 0x8710, (guint16) 0xf3af, (guint16) 0xe226, (guint16) 0xd0bd, (guint16) 0xc134, (guint16) 0x39c3, (guint16) 0x284a, (guint16) 0x1ad1, (guint16) 0x0b58, (guint16) 0x7fe7, (guint16) 0x6e6e, (guint16) 0x5cf5, (guint16) 0x4d7c, (guint16) 0xc60c, (guint16) 0xd785, (guint16) 0xe51e, (guint16) 0xf497, (guint16) 0x8028, (guint16) 0x91a1, (guint16) 0xa33a, (guint16) 0xb2b3, (guint16) 0x4a44, (guint16) 0x5bcd, (guint16) 0x6956, (guint16) 0x78df, (guint16) 0x0c60, (guint16) 0x1de9, (guint16) 0x2f72, (guint16) 0x3efb, (guint16) 0xd68d, (guint16) 0xc704, (guint16) 0xf59f, (guint16) 0xe416, (guint16) 0x90a9, (guint16) 0x8120, (guint16) 0xb3bb, (guint16) 0xa232, (guint16) 0x5ac5, (guint16) 0x4b4c, (guint16) 0x79d7, (guint16) 0x685e, (guint16) 0x1ce1, (guint16) 0x0d68, (guint16) 0x3ff3, (guint16) 0x2e7a, (guint16) 0xe70e, (guint16) 0xf687, (guint16) 0xc41c, (guint16) 0xd595, (guint16) 0xa12a, (guint16) 0xb0a3, (guint16) 0x8238, (guint16) 0x93b1, (guint16) 0x6b46, (guint16) 0x7acf, (guint16) 0x4854, (guint16) 0x59dd, (guint16) 0x2d62, (guint16) 0x3ceb, (guint16) 0x0e70, (guint16) 0x1ff9, (guint16) 0xf78f, (guint16) 0xe606, (guint16) 0xd49d, (guint16) 0xc514, (guint16) 0xb1ab, (guint16) 0xa022, (guint16) 0x92b9, (guint16) 0x8330, (guint16) 0x7bc7, (guint16) 0x6a4e, (guint16) 0x58d5, (guint16) 0x495c, (guint16) 0x3de3, (guint16) 0x2c6a, (guint16) 0x1ef1, (guint16) 0x0f78};

guint16 fso_framework_checksum_crc16 (guint8* data, int data_length1) {
	guint16 result = 0U;
	guint16 sum;
	sum = (guint16) 0xFFFF;
	{
		gint i;
		i = 0;
		{
			gboolean _tmp0_;
			_tmp0_ = TRUE;
			while (TRUE) {
				gboolean _tmp1_;
				gint _tmp3_;
				guint8* _tmp4_;
				gint _tmp4__length1;
				guint16 _tmp5_;
				guint16 _tmp6_;
				guint8* _tmp7_;
				gint _tmp7__length1;
				gint _tmp8_;
				guint8 _tmp9_;
				guint16 _tmp10_;
				_tmp1_ = _tmp0_;
				if (!_tmp1_) {
					gint _tmp2_;
					_tmp2_ = i;
					i = _tmp2_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp3_ = i;
				_tmp4_ = data;
				_tmp4__length1 = data_length1;
				if (!(_tmp3_ < _tmp4__length1)) {
					break;
				}
				_tmp5_ = sum;
				_tmp6_ = sum;
				_tmp7_ = data;
				_tmp7__length1 = data_length1;
				_tmp8_ = i;
				_tmp9_ = _tmp7_[_tmp8_];
				_tmp10_ = FSO_FRAMEWORK_CHECKSUM_crc16tab_fcs[(_tmp6_ ^ _tmp9_) & 0xFF];
				sum = (guint16) ((_tmp5_ >> 8) ^ _tmp10_);
			}
		}
	}
	result = sum;
	return result;
}


gboolean fso_framework_checksum_crc16_verify (guint8* data, int data_length1, guint16 expected) {
	gboolean result = FALSE;
	guint8* _tmp0_;
	gint _tmp0__length1;
	guint16 _tmp1_ = 0U;
	guint16 _tmp2_;
	_tmp0_ = data;
	_tmp0__length1 = data_length1;
	_tmp1_ = fso_framework_checksum_crc16 (_tmp0_, _tmp0__length1);
	_tmp2_ = expected;
	result = _tmp1_ == _tmp2_;
	return result;
}



