adler32.cpp revision c7814cf6e1240a519cbec0441e033d0e2470ed00
/* $Id$ */
/** @file
* IPRT - Adler-32
*/
/*
* Copyright (C) 2009-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#define RTCRC_ADLER_32_NUMBER 65521
{
/* Don't want to do the unrolling twice. */
}
{
return 1;
}
{
{
while (cb-- > 0)
{
a += *pbSrc++;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
}
}
else
{
{
case 0:
break;
case 1:
a += *pbSrc++;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
cb--;
/* fall thru */
case 2:
a += *pbSrc++;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
cb--;
/* fall thru */
case 3:
a += *pbSrc++;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
cb--;
break;
}
while (cb >= 4)
{
pbSrc += 4;
a += u32 & 0xff;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
cb -= 4;
}
switch (cb)
{
case 0:
break;
case 3:
a += *pbSrc++;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
cb--;
/* fall thru */
case 2:
a += *pbSrc++;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
cb--;
/* fall thru */
case 1:
a += *pbSrc++;
a %= RTCRC_ADLER_32_NUMBER;
b += a;
b %= RTCRC_ADLER_32_NUMBER;
cb--;
break;
}
}
return a | (b << 16);
}
{
return u32Crc;
}