Closed mike1729 closed 5 years ago
Note that decodebytes
expects bytes. hashPair
returns a hex string that is encoded as a byte object. Therefore, there is no issue. You mean to call bytes.fromhex(hashPair(el)
instead of base64.decodebytes
.
Try this:
from charm.toolbox.pairinggroup import PairingGroup, ZR from charm.core.math.pairing import hashPair
group = PairingGroup('BN254') el = group.random(ZR)
res = hashPair(el) res = res.decode('utf8') print([bytes.fromhex(res)[i] % 2 for i in range(0,32,2)])
Hi all!
Here is a snippet for reproducing the problem:
from charm.toolbox.pairinggroup import PairingGroup, ZR from charm.core.math.pairing import hashPair from base64 import decodebytes
group = PairingGroup('MNT224') el = group.random(ZR)
[decodebytes(hashPair(el))[i] % 2 for i in range(0,48,3)]
The last line yields only ones. As I understand, hashPair is a sha2 of the element (btw in the code a comment says that it is sha1), so it should be random, while first bit is always 1, second is 1 with probability around 0.6, and the third seems to be random, and for next bits the story repeats.
Could you provide some info if this is a feature and I don't understand sth or there is some problem with hashPair.