I'm using Charm-Crypto to understand the CP-ABE scheme. I'm testing this scheme: CPabe_BSW07Test. This is the code:
from charm.schemes.abenc.abenc_bsw07 import CPabe_BSW07
from charm.toolbox.pairinggroup import PairingGroup,GT
import unittest
class CPabe_BSW07Test(unittest.TestCase):
def testCPabe_BSW07(self):
groupObj = PairingGroup('SS512')
cpabe = CPabe_BSW07(groupObj)
attrs = ['ONE', 'TWO', 'THREE']
access_policy = '((four or three) and (three or one))'
if debug:
print("Attributes =>", attrs); print("Policy =>", access_policy)
(pk, mk) = cpabe.setup()
sk = cpabe.keygen(pk, mk, attrs)
print (groupObj)
rand_msg = groupObj.random(GT)
if debug: print("msg =>", rand_msg)
ct = cpabe.encrypt(pk, rand_msg, access_policy)
if debug: print("\n\nCiphertext...\n")
groupObj.debug(ct)
rec_msg = cpabe.decrypt(pk, sk, ct)
if debug: print("\n\nDecrypt...\n")
if debug: print("Rec msg =>", rec_msg)
assert rand_msg == rec_msg, "FAILED Decryption: message is incorrect"
if debug: print("Successful Decryption!!!")
if __name__ == "__main__":
unittest.main()
I want to understand how can I calculate the bit lenght of a Private Key. I know the formula (in this paper BSW), but I want to check if it is true. For example if have a curve defined on 512 bit, and I have 10 attributes, the key bit-length is: (2*10+1)*512=10752 bit.
BSW07 uses a pairing of e: G0 x G0 → G1
, which corresponds to G1 x G1 → GT
in Charm. The secret key consists of 2*n+1
elements of G1
for n
attributes.
A single element g
can be serialized with
groupObj.serialize(g)
which results in a Base64 encoded string. Something like this for SS512:
b'1:Nri028S0SySkDoN0JH1Lu6HQo/Jkhq7DCZHI1MUrHOuIgCONonN14GzmhwopYQOxnjOysclhYNOnsvCLjVDLggE='
This string has 65
(decoded) byte in it (one of which denotes the sign of the element), which corresponds to 512 bit without sign.
If you want to deserialize the string representation, you can use
groupObj.deserialize(b64String)
The actual size might be different depending on whether you really want to store this Base64 representation or convert it yourself to binary.