|
|
@ -609,7 +609,7 @@ void setArrayModTest() |
|
|
|
const size_t fpByteSize = unitByteSize * Fp::getOp().N; |
|
|
|
const size_t fpByteSize = unitByteSize * Fp::getOp().N; |
|
|
|
Fp y; |
|
|
|
Fp y; |
|
|
|
bool b; |
|
|
|
bool b; |
|
|
|
y.setArray(&b, px, xn, mcl::fp::Mod); |
|
|
|
y.setArrayMod(&b, px, xn); |
|
|
|
bool expected = xByteSize <= fpByteSize * 2; |
|
|
|
bool expected = xByteSize <= fpByteSize * 2; |
|
|
|
CYBOZU_TEST_EQUAL(b, expected); |
|
|
|
CYBOZU_TEST_EQUAL(b, expected); |
|
|
|
if (!b) continue; |
|
|
|
if (!b) continue; |
|
|
@ -1041,7 +1041,7 @@ CYBOZU_TEST_AUTO(main) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CYBOZU_TEST_AUTO(copyByteToUnitAsLE) |
|
|
|
CYBOZU_TEST_AUTO(convertArrayAsLE) |
|
|
|
{ |
|
|
|
{ |
|
|
|
using namespace mcl::fp; |
|
|
|
using namespace mcl::fp; |
|
|
|
#if MCL_SIZEOF_UNIT == 4 |
|
|
|
#if MCL_SIZEOF_UNIT == 4 |
|
|
@ -1050,18 +1050,19 @@ CYBOZU_TEST_AUTO(copyByteToUnitAsLE) |
|
|
|
const Unit src[] = { uint64_t(0xaabbccdd12345678ull), uint64_t(0x87654321ffeeddcc) }; |
|
|
|
const Unit src[] = { uint64_t(0xaabbccdd12345678ull), uint64_t(0x87654321ffeeddcc) }; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
const uint8_t ok[] = { 0x78, 0x56, 0x34, 0x12, 0xdd, 0xcc, 0xbb, 0xaa, 0xcc, 0xdd, 0xee, 0xff, 0x21, 0x43, 0x65, 0x87 }; |
|
|
|
const uint8_t ok[] = { 0x78, 0x56, 0x34, 0x12, 0xdd, 0xcc, 0xbb, 0xaa, 0xcc, 0xdd, 0xee, 0xff, 0x21, 0x43, 0x65, 0x87 }; |
|
|
|
mcl::fp::Unit dst[2]; |
|
|
|
const size_t dstN = 2; |
|
|
|
|
|
|
|
mcl::fp::Unit dst[dstN]; |
|
|
|
for (size_t i = 1; i <= sizeof(dst); i++) { |
|
|
|
for (size_t i = 1; i <= sizeof(dst); i++) { |
|
|
|
memset(dst, 0xff, sizeof(dst)); |
|
|
|
memset(dst, 0xff, sizeof(dst)); |
|
|
|
mcl::fp::copyByteToUnitAsLE(dst, ok, i); |
|
|
|
mcl::fp::convertArrayAsLE(dst, dstN, ok, i); |
|
|
|
if (i < sizeof(Unit)) { |
|
|
|
if (i < sizeof(Unit)) { |
|
|
|
CYBOZU_TEST_EQUAL(src[0] & ((uint64_t(1) << (i * 8)) - 1), dst[0]); |
|
|
|
CYBOZU_TEST_EQUAL(src[0] & ((uint64_t(1) << (i * 8)) - 1), dst[0]); |
|
|
|
CYBOZU_TEST_EQUAL(dst[1], Unit(-1)); |
|
|
|
CYBOZU_TEST_EQUAL(dst[1], 0); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
CYBOZU_TEST_EQUAL(dst[0], src[0]); |
|
|
|
CYBOZU_TEST_EQUAL(dst[0], src[0]); |
|
|
|
if (i == sizeof(Unit)) { |
|
|
|
if (i == sizeof(Unit)) { |
|
|
|
CYBOZU_TEST_EQUAL(dst[1], Unit(-1)); |
|
|
|
CYBOZU_TEST_EQUAL(dst[1], 0); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (i < sizeof(dst)) { |
|
|
|
if (i < sizeof(dst)) { |
|
|
@ -1071,7 +1072,7 @@ CYBOZU_TEST_AUTO(copyByteToUnitAsLE) |
|
|
|
CYBOZU_TEST_EQUAL(src[1], dst[1]); |
|
|
|
CYBOZU_TEST_EQUAL(src[1], dst[1]); |
|
|
|
} |
|
|
|
} |
|
|
|
dst[0] = 1; |
|
|
|
dst[0] = 1; |
|
|
|
copyByteToUnitAsLE(dst, ok, 0); |
|
|
|
mcl::fp::convertArrayAsLE(dst, 0, ok, 1); |
|
|
|
CYBOZU_TEST_EQUAL(dst[0], 1u); |
|
|
|
CYBOZU_TEST_EQUAL(dst[0], 1u); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|