diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-09-17 21:47:19 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-09-17 21:47:19 +0800 |
commit | bad0d52d6549aa0ff4e1dfdfeec9046fb6174ea7 (patch) | |
tree | 77ad04e969e18ad640aeee55d3cb0cff11cb686e | |
parent | 48a73206e83cb0901deaab594340b2711a4430b5 (diff) | |
download | dexon-bls-bad0d52d6549aa0ff4e1dfdfeec9046fb6174ea7.tar dexon-bls-bad0d52d6549aa0ff4e1dfdfeec9046fb6174ea7.tar.gz dexon-bls-bad0d52d6549aa0ff4e1dfdfeec9046fb6174ea7.tar.bz2 dexon-bls-bad0d52d6549aa0ff4e1dfdfeec9046fb6174ea7.tar.lz dexon-bls-bad0d52d6549aa0ff4e1dfdfeec9046fb6174ea7.tar.xz dexon-bls-bad0d52d6549aa0ff4e1dfdfeec9046fb6174ea7.tar.zst dexon-bls-bad0d52d6549aa0ff4e1dfdfeec9046fb6174ea7.zip |
insert zero byte into low bit of h for BLS12-381
-rw-r--r-- | src/bls_c_impl.hpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/bls_c_impl.hpp b/src/bls_c_impl.hpp index ad52cf7..1540d94 100644 --- a/src/bls_c_impl.hpp +++ b/src/bls_c_impl.hpp @@ -270,7 +270,19 @@ int blsPublicKeyIsValidOrder(const blsPublicKey *pub) inline bool toG1(G1& Hm, const void *h, mclSize size) { Fp t; - t.setArrayMask((const char *)h, size); + if (BN::param.cp.curveType == MCL_BLS12_381) { + /* + the current mapToG1 for BLS12_381 uses an algorithm to search x++ while y exsits, + so almost same h values return same point unless there exists margine in low bit. + */ + char buf[48]; + buf[0] = 0; + size = (std::min)(size, sizeof(buf) - 1); + memcpy(&buf[1], h, size); + t.setArrayMask(buf, size + 1); + } else { + t.setArrayMask((const char *)h, size); + } bool b; BN::mapToG1(&b, Hm, t); return b; |