2014-11-10 03:05:46 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2014, Arvid Norberg
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libtorrent/crc32c.hpp"
|
2016-06-30 17:37:55 +02:00
|
|
|
#include "libtorrent/aux_/cpuid.hpp"
|
2018-03-23 23:54:17 +01:00
|
|
|
#include "libtorrent/aux_/byteswap.hpp"
|
2016-06-30 17:37:55 +02:00
|
|
|
#include "libtorrent/assert.hpp"
|
2014-11-10 03:05:46 +01:00
|
|
|
#include "test.hpp"
|
|
|
|
|
2015-05-30 06:31:23 +02:00
|
|
|
TORRENT_TEST(crc32)
|
2014-11-10 03:05:46 +01:00
|
|
|
{
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2014-11-10 03:05:46 +01:00
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
std::uint32_t out;
|
2014-11-10 03:05:46 +01:00
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
std::uint32_t in1 = 0x5aa5feef;
|
2014-11-10 03:05:46 +01:00
|
|
|
out = crc32c_32(in1);
|
|
|
|
|
2018-03-23 23:54:17 +01:00
|
|
|
TEST_EQUAL(out, aux::host_to_network(0xd5b9e35eU));
|
2014-11-10 03:05:46 +01:00
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
std::uint64_t buf[4];
|
2014-11-10 03:05:46 +01:00
|
|
|
memcpy(buf, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
|
|
|
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32);
|
|
|
|
|
|
|
|
out = crc32c(buf, 4);
|
2018-03-23 23:54:17 +01:00
|
|
|
TEST_EQUAL(out, aux::host_to_network(0xaa36918aU));
|
2014-11-10 03:05:46 +01:00
|
|
|
|
|
|
|
memcpy(buf, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
|
|
|
|
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 32);
|
|
|
|
out = crc32c(buf, 4);
|
2018-03-23 23:54:17 +01:00
|
|
|
TEST_EQUAL(out, aux::host_to_network(0x43aba862U));
|
2014-11-10 03:05:46 +01:00
|
|
|
|
|
|
|
memcpy(buf, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
|
|
|
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 32);
|
|
|
|
out = crc32c(buf, 4);
|
2018-03-23 23:54:17 +01:00
|
|
|
TEST_EQUAL(out, aux::host_to_network(0x4e79dd46U));
|
2014-11-10 03:05:46 +01:00
|
|
|
|
2016-06-30 17:37:55 +02:00
|
|
|
#if TORRENT_HAS_ARM
|
|
|
|
TORRENT_ASSERT(aux::arm_crc32c_support);
|
|
|
|
#else
|
|
|
|
TORRENT_ASSERT(!aux::arm_crc32c_support);
|
|
|
|
#endif
|
|
|
|
}
|