JHUISI / charm

Charm: A Framework for Rapidly Prototyping Cryptosystems
http://charm-crypto.io
GNU Lesser General Public License v3.0
541 stars 166 forks source link

Not able to hash group element to binary string. Help!! #278

Closed ashishlakraa closed 2 years ago

ashishlakraa commented 2 years ago

I want to have a cryptographic hash function with the mapping as H: G2 → {0, 1}n for some n . But in charm-crypto we can only hash an element type/string to a specific field only.

I am implementing an algorithm for certificateless public encryption with keyword search and in the algorithm I need this hash function.

Can someone please help me how to facilitate this hash function H functionality in charm?

lrusso96 commented 2 years ago

@ashishlakra01 you could do something like this:

from hashlib import sha256

group = ... # some PairingGroup
g2 = ... # element of G2
digest = sha256(group.serialize(g2)).digest()
ashishlakraa commented 2 years ago

@ashishlakra01 you could do something like this:

from hashlib import sha256

group = ... # some PairingGroup
g2 = ... # element of G2
digest = sha256(group.serialize(g2)).digest()

Thank you so much @lrusso96 I will try this out.