Can not hash string to GT in pairinggroup
suiahae opened this issue · 0 comments
When I tried to implement "H2 : {0, 1}* --> GT" mentioned in the paper [1], I encountered an error: pairing.Error: cannot hash a string to that field. Only Zr or G1.
from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair
from hashlib import sha256
group_a = PairingGroup('SS512')
gt = group_a.hash(sha256(str('word').encode('utf-8')).hexdigest(), GT)
print(gt)
After looking at the documentation, I found that only ZR, G1 and G2 are mentioned but not GT.
However, "H2 : {0, 1}* --> GT" is available in pypbc (another python pbc library).
from pypbc import *
from hashlib import sha256
params = Parameters(qbits=512, rbits=160)
pairing = Pairing(params)
gt = Element.from_hash(pairing, GT, sha256(str('word').encode('utf-8')).hexdigest())
print(gt)
So I wonder why charm doesn't support hashing objects into GT, and how to hash strings into GT?
The only way I can think of is to hash string into G1 first and then pair, like below. Is there any other better way?
g1 = group_a.hash(sha256(str('word').encode('utf-8')).hexdigest(), G1)
pair(g1,g1)
[1] Y. Miao, J. Ma, X. Liu, X. Li, Q. Jiang, and J. Zhang, “Attribute-Based Keyword Search over Hierarchical Data in Cloud Computing,” IEEE Transactions on Services Computing, vol. 13, no. 6, pp. 985–998, Nov. 2020, doi: 10.1109/TSC.2017.2757467.