Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not hash string to GT in pairinggroup #296

Open
suiahae opened this issue Jun 4, 2023 · 0 comments
Open

Can not hash string to GT in pairinggroup #296

suiahae opened this issue Jun 4, 2023 · 0 comments

Comments

@suiahae
Copy link

suiahae commented Jun 4, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant