Fp::load/save support big endian

2merge^2
MITSUNARI Shigeo 4 years ago
parent 35b2682699
commit dec82f6f1d
  1. 23
      include/mcl/fp.hpp

@ -276,7 +276,12 @@ public:
if (isETHserialization_ && ioMode & (IoSerialize | IoSerializeHexStr)) { if (isETHserialization_ && ioMode & (IoSerialize | IoSerializeHexStr)) {
fp::local::byteSwap(buf, n); fp::local::byteSwap(buf, n);
} }
fp::convertArrayAsLE(v_, op_.N, buf, n); if (ioMode & IoArrayRaw) {
v_[op_.N - 1] = 0;
memcpy(v_, buf, n);
} else {
fp::convertArrayAsLE(v_, op_.N, buf, n);
}
} else { } else {
char buf[sizeof(*this) * 8 + 2]; // '0b' + max binary format length char buf[sizeof(*this) * 8 + 2]; // '0b' + max binary format length
size_t n = fp::local::loadWord(buf, sizeof(buf), is); size_t n = fp::local::loadWord(buf, sizeof(buf), is);
@ -306,18 +311,18 @@ public:
} else { } else {
fp::Block b; fp::Block b;
getBlock(b); getBlock(b);
const char *src = (const char *)b.p; uint8_t *x = (uint8_t*)CYBOZU_ALLOCA(sizeof(fp::Unit) * op_.N);
char rev[fp::maxUnitSize * sizeof(fp::Unit)]; if (!fp::convertArrayAsLE(x, sizeof(fp::Unit) * op_.N, b.p, b.n)) {
*pb = false;
return;
}
if (isETHserialization_ && ioMode & (IoSerialize | IoSerializeHexStr)) { if (isETHserialization_ && ioMode & (IoSerialize | IoSerializeHexStr)) {
for (size_t i = 0; i < n; i++) { fp::local::byteSwap(x, n);
rev[i] = src[n - 1 - i];
}
src = rev;
} }
if (ioMode & IoSerializeHexStr) { if (ioMode & IoSerializeHexStr) {
mcl::fp::writeHexStr(pb, os, src, n); mcl::fp::writeHexStr(pb, os, x, n);
} else { } else {
cybozu::write(pb, os, src, n); cybozu::write(pb, os, x, n);
} }
} }
return; return;

Loading…
Cancel
Save