stefano81 / dcpabe

Decentralized CP-ABE
MIT License
105 stars 45 forks source link

Encryption bug #3

Closed ihsanhaikalz closed 6 years ago

ihsanhaikalz commented 6 years ago

I discovered this bug while running the test case of your library.

Element M = pairing.getGT().newRandomElement().getImmutable();
message.m = M.toBytes();

I understand that you want to associate the message byte array with the element M that is generated randomly but surely this won't allow if we set the message by ourselves. Also the bug itself will actually passes the test but also the test should be wrong as in the test case there isn't any byte assigned to it then suddenly after encryption the byte is then filled with random element M, which is wrong.

What I suggest for fix of this bug is something like this:

Element M = pairing.getGT().newZeroElement();
M.setFromBytes(message.m)
stefano81 commented 6 years ago

Hi @ihsanhaikalz thanks for submitting the issue! I'll have a look in the next few days. And yes I agree with the bug, I sincerely don't remember why I wrote it like that.

stefano81 commented 6 years ago

After reviewing the code I remembered the reason behind that choice.

In our use case, we didn't need to set the message to a specific value, but we use the random element as key for the encryption algorithm (hence using two steps: encrypt the resource with a symmetric schema and encrypt the key with a policy based asymmetric schema).

I changed the code adding an utility function that generates random elements for my use case and changed the standard enc API to use the content of Message as you suggested.