JHUISI / charm

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

AC17 YCT14 not portable #227

Open schanzen opened 5 years ago

schanzen commented 5 years ago

The objectToBytes function cannot serialize the "policy" member of a ciphertext for ABE scheme AC17. This results in a CT which is not portable, effectively preventing any practical use.

This is also true for YCT14 because it holds an internal state (!) which cannot be replicated in a portable fashion (!!), e.g. if encryption and decryption is done using two scripts.

Solution: AC17: Include a serializer for the policy member of the CT YCT14: Put the state into the keys (or allow it to be exported)

dillivanilli commented 4 years ago

I can help out for AC17. Wrote also some stuff for Json. I can create a PR. Are there any gudielines for it ?

    def serialize_ctxt(self, ctxt):
        ctxt['policy'] = ctxt['policy'].__str__()
        ctxt['Cp'] = self.group.serialize(ctxt['Cp'])
        ctxt['C_0'] = list(map(self.group.serialize, ctxt['C_0']))
        for dict_key, value in ctxt['C'].items():
            for tuple_index, value in enumerate(ctxt['C'][dict_key]):
                ctxt['C'][dict_key][tuple_index] = self.group.serialize(
                    value)
        return ctxt

    def deserialize_ctxt(self, ctxt):
        ctxt['policy'] = self.util.createPolicy(ctxt['policy'])
        ctxt['Cp'] = self.group.deserialize(ctxt['Cp'])
        ctxt['C_0'] = list(map(self.group.deserialize, ctxt['C_0']))
        for dict_key, value in ctxt['C'].items():
            for tuple_index, value in enumerate(ctxt['C'][dict_key]):
                ctxt['C'][dict_key][tuple_index] = self.group.deserialize(
                    value)
        return ctxt

    def jsonify_ctxt(self, ctxt):
        ctxt = self.serialize_ctxt(ctxt)
        ctxt['Cp'] = ctxt['Cp'].decode('utf-8')
        ctxt['C_0'] = list(map(lambda x: x.decode('utf-8'), ctxt['C_0']))
        for dict_key, value in ctxt['C'].items():
            for tuple_index, value in enumerate(ctxt['C'][dict_key]):
                ctxt['C'][dict_key][tuple_index] = value.decode('utf-8')
        return json.dumps(ctxt)

    def unjsonify_ctxt(self, ctxt):
        ctxt = json.loads(ctxt)
        ctxt['Cp'] = ctxt['Cp'].encode('utf-8')
        ctxt['C_0'] = list(map(lambda x: x.encode('utf-8'), ctxt['C_0']))
        for dict_key, value in ctxt['C'].items():
            for tuple_index, value in enumerate(ctxt['C'][dict_key]):
                ctxt['C'][dict_key][tuple_index] = value.encode('utf-8')
        return self.deserialize_ctxt(ctxt)
jakinyele commented 4 years ago

Thanks, @dillivanilli! Guidelines here: https://jhuisi.github.io/charm/tutorial.html#using-serialization-api