Source code for ibenc_adapt_identityhash
'''
**Identity Hashing Adapter for IBE (HashID Adapter)**
*Description:* Converts an Identity-Based Encryption scheme that requires ZR (integer)
identities into one that accepts arbitrary string identities via cryptographic hashing.
| **Notes:** Hashes string identities to ZR elements using the pairing group's hash function.
| Transforms security from selective-ID (IND-sID-CPA) to full-ID (IND-ID-CPA) under ROM.
.. rubric:: Adapter Properties
* **Type:** identity transform adapter
* **Underlying Scheme:** any IBE scheme with ZR identity space
* **Purpose:** enables use of human-readable string identities (e.g., email addresses)
.. rubric:: Implementation
:Authors: J. Ayo Akinyele
:Date: 2011
'''
from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
from charm.toolbox.IBEnc import *
debug = False
[docs]
class HashIDAdapter(IBEnc):
"""
>>> from charm.schemes.ibenc.ibenc_bb03 import IBE_BB04
>>> group = PairingGroup('SS512')
>>> ibe = IBE_BB04(group)
>>> hashID = HashIDAdapter(ibe, group)
>>> (master_public_key, master_key) = hashID.setup()
>>> ID = 'john.doe@example.com'
>>> secret_key = hashID.extract(master_key, ID)
>>> msg = group.random(GT)
>>> cipher_text = hashID.encrypt(master_public_key, ID, msg)
>>> decrypted_msg = hashID.decrypt(master_public_key, secret_key, cipher_text)
>>> msg == decrypted_msg
True
"""
def __init__(self, scheme, group):
global ibe
IBEnc.__init__(self)
self.group = group
ibe = None
# validate that we have the appropriate object
criteria = [('secDef', IND_sID_CPA), ('scheme', 'IBEnc'), ('secModel', SM), ('id',ZR)]
if IBEnc.checkProperty(self, scheme, criteria):
# change our property as well
IBEnc.updateProperty(self, scheme, secDef=IND_ID_CPA, id=str, secModel=ROM)
ibe = scheme
#IBEnc.printProperties(self)
else:
assert False, "Input scheme does not satisfy adapter properties: %s" % criteria
[docs]
def setup(self):
assert ibe != None, "IBEnc alg not set"
return ibe.setup()
[docs]
def encrypt(self, pk, ID, msg):
assert ibe != None, "IBEnc alg not set"
if type(ID) in [str, bytes]:
ID2 = self.group.hash(ID)
return ibe.encrypt(pk, ID2, msg)
else:
assert False, "invalid type on ID."
[docs]
def decrypt(self, pk, sk, ct):
assert ibe != None, "IBEnc alg not set"
return ibe.decrypt(pk, sk, ct)