|
|
@ -339,24 +339,44 @@ public: |
|
|
|
cybozu::write(pb, os, buf + sizeof(buf) - len, len); |
|
|
|
cybozu::write(pb, os, buf + sizeof(buf) - len, len); |
|
|
|
} |
|
|
|
} |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
set array x as little endian |
|
|
|
treat x as little endian |
|
|
|
|
|
|
|
if x >= p then error |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<class S> |
|
|
|
template<class S> |
|
|
|
void setArray_(bool *pb, const S *x, size_t n, mcl::fp::MaskMode mode = fp::NoMask) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
*pb = fp::copyAndMask(v_, x, sizeof(S) * n, op_, mode); |
|
|
|
|
|
|
|
toMont(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
template<class S> |
|
|
|
|
|
|
|
void setArray(bool *pb, const S *x, size_t n) |
|
|
|
void setArray(bool *pb, const S *x, size_t n) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!fp::convertArrayAsLE(v_, op_.N, x, n) || fp::isGreaterOrEqualArray(v_, op_.p, op_.N)) { |
|
|
|
if (!fp::convertArrayAsLE(v_, op_.N, x, n)) { |
|
|
|
|
|
|
|
*pb = false; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (fp::isGreaterOrEqualArray(v_, op_.p, op_.N)) { |
|
|
|
*pb = false; |
|
|
|
*pb = false; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
*pb = true; |
|
|
|
*pb = true; |
|
|
|
toMont(); |
|
|
|
toMont(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
treat x as little endian |
|
|
|
|
|
|
|
x &= (1 << bitLen) = 1 |
|
|
|
|
|
|
|
x &= (1 << (bitLen - 1)) - 1 if x >= p |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
template<class S> |
|
|
|
|
|
|
|
void setArrayMask(const S *x, size_t n) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const size_t dstByte = sizeof(fp::Unit) * op_.N; |
|
|
|
|
|
|
|
if (sizeof(S) * n > dstByte) { |
|
|
|
|
|
|
|
n = dstByte / sizeof(S); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bool b = fp::convertArrayAsLE(v_, op_.N, x, n); |
|
|
|
|
|
|
|
assert(b); |
|
|
|
|
|
|
|
(void)b; |
|
|
|
|
|
|
|
fp::maskArray(v_, op_.N, op_.bitSize); |
|
|
|
|
|
|
|
if (fp::isGreaterOrEqualArray(v_, op_.p, op_.N)) { |
|
|
|
|
|
|
|
fp::maskArray(v_, op_.N, op_.bitSize - 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
toMont(); |
|
|
|
|
|
|
|
} |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
set (x as little endian) % p |
|
|
|
set (x as little endian) % p |
|
|
|
error if size of x >= sizeof(Fp) * 2 |
|
|
|
error if size of x >= sizeof(Fp) * 2 |
|
|
@ -380,16 +400,6 @@ public: |
|
|
|
if (!*pb) return; |
|
|
|
if (!*pb) return; |
|
|
|
toMont(); |
|
|
|
toMont(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
mask x with (1 << (bitLen - 1)) - 1 if x >= p |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
template<class S> |
|
|
|
|
|
|
|
void setArrayMask(const S *x, size_t n) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fp::copyAndMask(v_, x, sizeof(S) * n, op_, fp::SmallMask); |
|
|
|
|
|
|
|
toMont(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void getBlock(fp::Block& b) const |
|
|
|
void getBlock(fp::Block& b) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
b.n = op_.N; |
|
|
|
b.n = op_.N; |
|
|
@ -488,7 +498,7 @@ public: |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void setHashOf(const void *msg, size_t msgSize) |
|
|
|
void setHashOf(const void *msg, size_t msgSize) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char buf[MCL_MAX_HASH_BIT_SIZE / 8]; |
|
|
|
uint8_t buf[MCL_MAX_HASH_BIT_SIZE / 8]; |
|
|
|
uint32_t size = op_.hash(buf, static_cast<uint32_t>(sizeof(buf)), msg, static_cast<uint32_t>(msgSize)); |
|
|
|
uint32_t size = op_.hash(buf, static_cast<uint32_t>(sizeof(buf)), msg, static_cast<uint32_t>(msgSize)); |
|
|
|
setArrayMask(buf, size); |
|
|
|
setArrayMask(buf, size); |
|
|
|
} |
|
|
|
} |
|
|
|