diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-05-04 14:10:15 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-05-04 14:11:57 +0800 |
commit | c4489ae8c223b5114272c6be34f97ef815a826c1 (patch) | |
tree | 48e45baaeeef6577e3db694fc70276774708047b /include | |
parent | 479f5cb5b48b6d7e01a0cb4a9146937ac6a8749e (diff) | |
download | tangerine-mcl-c4489ae8c223b5114272c6be34f97ef815a826c1.tar.gz tangerine-mcl-c4489ae8c223b5114272c6be34f97ef815a826c1.tar.zst tangerine-mcl-c4489ae8c223b5114272c6be34f97ef815a826c1.zip |
add Fp::setArrayMaskMod
Diffstat (limited to 'include')
-rw-r--r-- | include/mcl/fp.hpp | 24 | ||||
-rw-r--r-- | include/mcl/op.hpp | 6 |
2 files changed, 25 insertions, 5 deletions
diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index 7163d8c..0535ec9 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -41,7 +41,8 @@ namespace fp { void copyUnitToByteAsLE(uint8_t *dst, const Unit *src, size_t byteSize); // copy src to dst as little endian void copyByteToUnitAsLE(Unit *dst, const uint8_t *src, size_t byteSize); -void copyAndMask(Unit *y, const void *x, size_t xByteSize, const Op& op, bool doMask); + +void copyAndMask(Unit *y, const void *x, size_t xByteSize, const Op& op, MaskMode maskMode); uint64_t getUint64(bool *pb, const fp::Block& b); int64_t getInt64(bool *pb, fp::Block& b, const fp::Op& op); @@ -59,6 +60,9 @@ bool isEnableJIT(); // 1st call is not threadsafe void getRandVal(Unit *out, RandGen& rg, const Unit *in, size_t bitSize); +uint32_t sha256(void *out, uint32_t maxOutSize, const void *msg, uint32_t msgSize); +uint32_t sha512(void *out, uint32_t maxOutSize, const void *msg, uint32_t msgSize); + namespace local { inline bool isSpace(char c) @@ -289,16 +293,26 @@ public: template<class S> void setArray(const S *x, size_t n) { - fp::copyAndMask(v_, x, sizeof(S) * n, op_, false); + fp::copyAndMask(v_, x, sizeof(S) * n, op_, fp::NoMask); toMont(); } /* - mask inBuf with (1 << (bitLen - 1)) - 1 if x >= p + mask x with (1 << bitLen) and subtract p if x >= p + */ + template<class S> + void setArrayMaskMod(const S *x, size_t n) + { + fp::copyAndMask(v_, x, sizeof(S) * n, op_, fp::MaskAndMod); + toMont(); + } + + /* + mask x with (1 << (bitLen - 1)) - 1 if x >= p */ template<class S> - void setArrayMask(const S *inBuf, size_t n) + void setArrayMask(const S *x, size_t n) { - fp::copyAndMask(v_, inBuf, sizeof(S) * n, op_, true); + fp::copyAndMask(v_, x, sizeof(S) * n, op_, fp::SmallMask); toMont(); } void getBlock(fp::Block& b) const diff --git a/include/mcl/op.hpp b/include/mcl/op.hpp index a72944e..874b99f 100644 --- a/include/mcl/op.hpp +++ b/include/mcl/op.hpp @@ -142,6 +142,12 @@ enum PrimeMode { PM_NICT_P521 }; +enum MaskMode { + NoMask = 0, // throw if greater or equal + SmallMask = 1, // 1-bit smaller mask if greater or equal + MaskAndMod = 2 // mask and substract if greater or equal +}; + struct Op { /* don't change the layout of rp and p |