我正在使用Charm-Crypto来了解 CP-ABE 方案。我正在测试这个方案:CPabe_BSW07Test。这是代码:
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()
我想了解如何计算私钥的位长度。我知道公式(在本文 BSW中),但我想检查它是否正确。例如,如果在 512 位上定义了一条曲线,并且我有 10 个属性,则关键位长为:(2*10+1)*512=10752 位。