aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2019-04-17 14:20:48 +0800
committerSonic <sonic@dexon.org>2019-04-17 15:05:49 +0800
commitb43de7c695c2f7eb79359233e5d75b94fa4ba471 (patch)
treead087d0afcd6513f4dd537f081f1436317829860
parent65b1afd18c0bcb88db1b056e8b16120c9de827d4 (diff)
downloaddexon-mcl-b43de7c695c2f7eb79359233e5d75b94fa4ba471.tar.gz
dexon-mcl-b43de7c695c2f7eb79359233e5d75b94fa4ba471.tar.zst
dexon-mcl-b43de7c695c2f7eb79359233e5d75b94fa4ba471.zip
change hash function into Fp
-rw-r--r--include/mcl/bn.hpp2
-rw-r--r--include/mcl/fp.hpp13
2 files changed, 14 insertions, 1 deletions
diff --git a/include/mcl/bn.hpp b/include/mcl/bn.hpp
index 63ce484..d4ceec9 100644
--- a/include/mcl/bn.hpp
+++ b/include/mcl/bn.hpp
@@ -528,7 +528,7 @@ struct MapTo {
// hash the concatenated msg into Fp
Fp t;
- t.setHashOf(m, bufSize+postfixSize);
+ t.setHashOfMod(m, bufSize+postfixSize);
// TODO handle error
bool b = calcBN<G1, Fp>(P, t);
diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp
index 2e69729..cca0af9 100644
--- a/include/mcl/fp.hpp
+++ b/include/mcl/fp.hpp
@@ -368,6 +368,19 @@ public:
uint32_t size = op_.hash(buf, static_cast<uint32_t>(sizeof(buf)), msg, static_cast<uint32_t>(msgSize));
setArrayMask(buf, size);
}
+ void setHashOfMod(const void *msg, size_t msgSize)
+ {
+ char 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));
+ // big endian
+ for(uint32_t i = 0; i < size / 2; ++i) {
+ char c = buf[i];
+ buf[i] = buf[size-i-1];
+ buf[size-i-1] = c;
+ }
+ bool b;
+ setArray(&b, buf, size, fp::Mod);
+ }
void getMpz(bool *pb, mpz_class& x) const
{
fp::Block b;