charm-crypto-framework 0.61.1__cp313-cp313-macosx_10_13_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. charm/__init__.py +5 -0
  2. charm/adapters/__init__.py +0 -0
  3. charm/adapters/abenc_adapt_hybrid.py +90 -0
  4. charm/adapters/dabenc_adapt_hybrid.py +145 -0
  5. charm/adapters/ibenc_adapt_hybrid.py +72 -0
  6. charm/adapters/ibenc_adapt_identityhash.py +80 -0
  7. charm/adapters/kpabenc_adapt_hybrid.py +91 -0
  8. charm/adapters/pkenc_adapt_bchk05.py +121 -0
  9. charm/adapters/pkenc_adapt_chk04.py +91 -0
  10. charm/adapters/pkenc_adapt_hybrid.py +98 -0
  11. charm/adapters/pksig_adapt_naor01.py +89 -0
  12. charm/config.py +7 -0
  13. charm/core/__init__.py +0 -0
  14. charm/core/benchmark/benchmark_util.c +353 -0
  15. charm/core/benchmark/benchmark_util.h +61 -0
  16. charm/core/benchmark/benchmarkmodule.c +476 -0
  17. charm/core/benchmark/benchmarkmodule.h +162 -0
  18. charm/core/benchmark.cpython-313-darwin.so +0 -0
  19. charm/core/crypto/AES/AES.c +1464 -0
  20. charm/core/crypto/AES.cpython-313-darwin.so +0 -0
  21. charm/core/crypto/DES/DES.c +113 -0
  22. charm/core/crypto/DES.cpython-313-darwin.so +0 -0
  23. charm/core/crypto/DES3/DES3.c +26 -0
  24. charm/core/crypto/DES3.cpython-313-darwin.so +0 -0
  25. charm/core/crypto/__init__.py +0 -0
  26. charm/core/crypto/cryptobase/XOR.c +80 -0
  27. charm/core/crypto/cryptobase/_counter.c +496 -0
  28. charm/core/crypto/cryptobase/_counter.h +54 -0
  29. charm/core/crypto/cryptobase/block_template.c +900 -0
  30. charm/core/crypto/cryptobase/block_template.h +69 -0
  31. charm/core/crypto/cryptobase/cryptobasemodule.c +220 -0
  32. charm/core/crypto/cryptobase/libtom/tomcrypt.h +90 -0
  33. charm/core/crypto/cryptobase/libtom/tomcrypt_argchk.h +44 -0
  34. charm/core/crypto/cryptobase/libtom/tomcrypt_cfg.h +186 -0
  35. charm/core/crypto/cryptobase/libtom/tomcrypt_cipher.h +941 -0
  36. charm/core/crypto/cryptobase/libtom/tomcrypt_custom.h +556 -0
  37. charm/core/crypto/cryptobase/libtom/tomcrypt_des.c +1912 -0
  38. charm/core/crypto/cryptobase/libtom/tomcrypt_hash.h +407 -0
  39. charm/core/crypto/cryptobase/libtom/tomcrypt_mac.h +496 -0
  40. charm/core/crypto/cryptobase/libtom/tomcrypt_macros.h +435 -0
  41. charm/core/crypto/cryptobase/libtom/tomcrypt_math.h +534 -0
  42. charm/core/crypto/cryptobase/libtom/tomcrypt_misc.h +103 -0
  43. charm/core/crypto/cryptobase/libtom/tomcrypt_pk.h +653 -0
  44. charm/core/crypto/cryptobase/libtom/tomcrypt_pkcs.h +90 -0
  45. charm/core/crypto/cryptobase/libtom/tomcrypt_prng.h +199 -0
  46. charm/core/crypto/cryptobase/stream_template.c +271 -0
  47. charm/core/crypto/cryptobase/strxor.c +229 -0
  48. charm/core/crypto/cryptobase.cpython-313-darwin.so +0 -0
  49. charm/core/engine/__init__.py +5 -0
  50. charm/core/engine/protocol.py +293 -0
  51. charm/core/engine/util.py +174 -0
  52. charm/core/math/__init__.py +0 -0
  53. charm/core/math/elliptic_curve/ecmodule.c +1986 -0
  54. charm/core/math/elliptic_curve/ecmodule.h +230 -0
  55. charm/core/math/elliptic_curve.cpython-313-darwin.so +0 -0
  56. charm/core/math/elliptic_curve.pyi +63 -0
  57. charm/core/math/integer/integermodule.c +2539 -0
  58. charm/core/math/integer/integermodule.h +145 -0
  59. charm/core/math/integer.cpython-313-darwin.so +0 -0
  60. charm/core/math/integer.pyi +76 -0
  61. charm/core/math/pairing/miracl/miracl_config.h +37 -0
  62. charm/core/math/pairing/miracl/miracl_interface.h +118 -0
  63. charm/core/math/pairing/miracl/miracl_interface2.h +126 -0
  64. charm/core/math/pairing/miracl/pairingmodule2.c +2094 -0
  65. charm/core/math/pairing/miracl/pairingmodule2.h +307 -0
  66. charm/core/math/pairing/pairingmodule.c +2230 -0
  67. charm/core/math/pairing/pairingmodule.h +241 -0
  68. charm/core/math/pairing/relic/pairingmodule3.c +1853 -0
  69. charm/core/math/pairing/relic/pairingmodule3.h +233 -0
  70. charm/core/math/pairing/relic/relic_interface.c +1337 -0
  71. charm/core/math/pairing/relic/relic_interface.h +217 -0
  72. charm/core/math/pairing/relic/test_relic.c +171 -0
  73. charm/core/math/pairing.cpython-313-darwin.so +0 -0
  74. charm/core/math/pairing.pyi +69 -0
  75. charm/core/utilities/base64.c +248 -0
  76. charm/core/utilities/base64.h +15 -0
  77. charm/schemes/__init__.py +0 -0
  78. charm/schemes/abenc/__init__.py +0 -0
  79. charm/schemes/abenc/abenc_accountability_jyjxgd20.py +647 -0
  80. charm/schemes/abenc/abenc_bsw07.py +146 -0
  81. charm/schemes/abenc/abenc_ca_cpabe_ar17.py +684 -0
  82. charm/schemes/abenc/abenc_dacmacs_yj14.py +298 -0
  83. charm/schemes/abenc/abenc_lsw08.py +159 -0
  84. charm/schemes/abenc/abenc_maabe_rw15.py +236 -0
  85. charm/schemes/abenc/abenc_maabe_yj14.py +297 -0
  86. charm/schemes/abenc/abenc_tbpre_lww14.py +309 -0
  87. charm/schemes/abenc/abenc_unmcpabe_yahk14.py +223 -0
  88. charm/schemes/abenc/abenc_waters09.py +144 -0
  89. charm/schemes/abenc/abenc_yct14.py +208 -0
  90. charm/schemes/abenc/abenc_yllc15.py +178 -0
  91. charm/schemes/abenc/ac17.py +248 -0
  92. charm/schemes/abenc/bsw07.py +141 -0
  93. charm/schemes/abenc/cgw15.py +277 -0
  94. charm/schemes/abenc/dabe_aw11.py +204 -0
  95. charm/schemes/abenc/dfa_fe12.py +144 -0
  96. charm/schemes/abenc/pk_hve08.py +179 -0
  97. charm/schemes/abenc/waters11.py +143 -0
  98. charm/schemes/aggrsign_MuSig.py +150 -0
  99. charm/schemes/aggrsign_bls.py +267 -0
  100. charm/schemes/blindsig_ps16.py +654 -0
  101. charm/schemes/chamhash_adm05.py +113 -0
  102. charm/schemes/chamhash_rsa_hw09.py +100 -0
  103. charm/schemes/commit/__init__.py +0 -0
  104. charm/schemes/commit/commit_gs08.py +77 -0
  105. charm/schemes/commit/commit_pedersen92.py +53 -0
  106. charm/schemes/encap_bchk05.py +62 -0
  107. charm/schemes/grpsig/__init__.py +0 -0
  108. charm/schemes/grpsig/groupsig_bgls04.py +114 -0
  109. charm/schemes/grpsig/groupsig_bgls04_var.py +115 -0
  110. charm/schemes/hibenc/__init__.py +0 -0
  111. charm/schemes/hibenc/hibenc_bb04.py +105 -0
  112. charm/schemes/hibenc/hibenc_lew11.py +193 -0
  113. charm/schemes/ibenc/__init__.py +0 -0
  114. charm/schemes/ibenc/clpkc_rp03.py +119 -0
  115. charm/schemes/ibenc/ibenc_CW13_z.py +168 -0
  116. charm/schemes/ibenc/ibenc_bb03.py +94 -0
  117. charm/schemes/ibenc/ibenc_bf01.py +121 -0
  118. charm/schemes/ibenc/ibenc_ckrs09.py +120 -0
  119. charm/schemes/ibenc/ibenc_cllww12_z.py +172 -0
  120. charm/schemes/ibenc/ibenc_lsw08.py +120 -0
  121. charm/schemes/ibenc/ibenc_sw05.py +238 -0
  122. charm/schemes/ibenc/ibenc_waters05.py +144 -0
  123. charm/schemes/ibenc/ibenc_waters05_z.py +164 -0
  124. charm/schemes/ibenc/ibenc_waters09.py +107 -0
  125. charm/schemes/ibenc/ibenc_waters09_z.py +147 -0
  126. charm/schemes/joye_scheme.py +106 -0
  127. charm/schemes/lem_scheme.py +207 -0
  128. charm/schemes/pk_fre_ccv11.py +107 -0
  129. charm/schemes/pk_vrf.py +127 -0
  130. charm/schemes/pkenc/__init__.py +0 -0
  131. charm/schemes/pkenc/pkenc_cs98.py +108 -0
  132. charm/schemes/pkenc/pkenc_elgamal85.py +122 -0
  133. charm/schemes/pkenc/pkenc_gm82.py +98 -0
  134. charm/schemes/pkenc/pkenc_paillier99.py +118 -0
  135. charm/schemes/pkenc/pkenc_rabin.py +254 -0
  136. charm/schemes/pkenc/pkenc_rsa.py +186 -0
  137. charm/schemes/pksig/__init__.py +0 -0
  138. charm/schemes/pksig/pksig_CW13_z.py +135 -0
  139. charm/schemes/pksig/pksig_bls04.py +87 -0
  140. charm/schemes/pksig/pksig_boyen.py +156 -0
  141. charm/schemes/pksig/pksig_chch.py +97 -0
  142. charm/schemes/pksig/pksig_chp.py +70 -0
  143. charm/schemes/pksig/pksig_cl03.py +150 -0
  144. charm/schemes/pksig/pksig_cl04.py +87 -0
  145. charm/schemes/pksig/pksig_cllww12_z.py +142 -0
  146. charm/schemes/pksig/pksig_cyh.py +132 -0
  147. charm/schemes/pksig/pksig_dsa.py +76 -0
  148. charm/schemes/pksig/pksig_ecdsa.py +71 -0
  149. charm/schemes/pksig/pksig_hess.py +104 -0
  150. charm/schemes/pksig/pksig_hw.py +110 -0
  151. charm/schemes/pksig/pksig_lamport.py +63 -0
  152. charm/schemes/pksig/pksig_ps01.py +135 -0
  153. charm/schemes/pksig/pksig_ps02.py +124 -0
  154. charm/schemes/pksig/pksig_ps03.py +119 -0
  155. charm/schemes/pksig/pksig_rsa_hw09.py +206 -0
  156. charm/schemes/pksig/pksig_schnorr91.py +77 -0
  157. charm/schemes/pksig/pksig_waters.py +115 -0
  158. charm/schemes/pksig/pksig_waters05.py +121 -0
  159. charm/schemes/pksig/pksig_waters09.py +121 -0
  160. charm/schemes/pre_mg07.py +150 -0
  161. charm/schemes/prenc/pre_afgh06.py +126 -0
  162. charm/schemes/prenc/pre_bbs98.py +123 -0
  163. charm/schemes/prenc/pre_nal16.py +216 -0
  164. charm/schemes/protocol_a01.py +272 -0
  165. charm/schemes/protocol_ao00.py +215 -0
  166. charm/schemes/protocol_cns07.py +274 -0
  167. charm/schemes/protocol_schnorr91.py +125 -0
  168. charm/schemes/sigma1.py +64 -0
  169. charm/schemes/sigma2.py +129 -0
  170. charm/schemes/sigma3.py +126 -0
  171. charm/schemes/threshold/__init__.py +59 -0
  172. charm/schemes/threshold/dkls23_dkg.py +556 -0
  173. charm/schemes/threshold/dkls23_presign.py +1089 -0
  174. charm/schemes/threshold/dkls23_sign.py +761 -0
  175. charm/schemes/threshold/xrpl_wallet.py +967 -0
  176. charm/test/__init__.py +0 -0
  177. charm/test/adapters/__init__.py +0 -0
  178. charm/test/adapters/abenc_adapt_hybrid_test.py +29 -0
  179. charm/test/adapters/dabenc_adapt_hybrid_test.py +56 -0
  180. charm/test/adapters/ibenc_adapt_hybrid_test.py +36 -0
  181. charm/test/adapters/ibenc_adapt_identityhash_test.py +32 -0
  182. charm/test/adapters/kpabenc_adapt_hybrid_test.py +30 -0
  183. charm/test/benchmark/abenc_yllc15_bench.py +92 -0
  184. charm/test/benchmark/benchmark_test.py +148 -0
  185. charm/test/benchmark_threshold.py +260 -0
  186. charm/test/conftest.py +38 -0
  187. charm/test/fuzz/__init__.py +1 -0
  188. charm/test/fuzz/conftest.py +5 -0
  189. charm/test/fuzz/fuzz_policy_parser.py +76 -0
  190. charm/test/fuzz/fuzz_serialization.py +83 -0
  191. charm/test/schemes/__init__.py +0 -0
  192. charm/test/schemes/abenc/__init__.py +0 -0
  193. charm/test/schemes/abenc/abenc_bsw07_test.py +39 -0
  194. charm/test/schemes/abenc/abenc_dacmacs_yj14_test.py +16 -0
  195. charm/test/schemes/abenc/abenc_lsw08_test.py +33 -0
  196. charm/test/schemes/abenc/abenc_maabe_yj14_test.py +16 -0
  197. charm/test/schemes/abenc/abenc_tbpre_lww14_test.py +16 -0
  198. charm/test/schemes/abenc/abenc_waters09_test.py +38 -0
  199. charm/test/schemes/abenc/abenc_yllc15_test.py +74 -0
  200. charm/test/schemes/chamhash_adm05_test.py +31 -0
  201. charm/test/schemes/chamhash_rsa_hw09_test.py +29 -0
  202. charm/test/schemes/commit/__init__.py +0 -0
  203. charm/test/schemes/commit/commit_gs08_test.py +24 -0
  204. charm/test/schemes/commit/commit_pedersen92_test.py +26 -0
  205. charm/test/schemes/dabe_aw11_test.py +45 -0
  206. charm/test/schemes/encap_bchk05_test.py +21 -0
  207. charm/test/schemes/grpsig/__init__.py +0 -0
  208. charm/test/schemes/grpsig/groupsig_bgls04_test.py +35 -0
  209. charm/test/schemes/grpsig/groupsig_bgls04_var_test.py +39 -0
  210. charm/test/schemes/hibenc/__init__.py +0 -0
  211. charm/test/schemes/hibenc/hibenc_bb04_test.py +28 -0
  212. charm/test/schemes/ibenc/__init__.py +0 -0
  213. charm/test/schemes/ibenc/ibenc_bb03_test.py +26 -0
  214. charm/test/schemes/ibenc/ibenc_bf01_test.py +24 -0
  215. charm/test/schemes/ibenc/ibenc_ckrs09_test.py +25 -0
  216. charm/test/schemes/ibenc/ibenc_lsw08_test.py +31 -0
  217. charm/test/schemes/ibenc/ibenc_sw05_test.py +32 -0
  218. charm/test/schemes/ibenc/ibenc_waters05_test.py +31 -0
  219. charm/test/schemes/ibenc/ibenc_waters09_test.py +27 -0
  220. charm/test/schemes/pk_vrf_test.py +29 -0
  221. charm/test/schemes/pkenc/__init__.py +0 -0
  222. charm/test/schemes/pkenc_test.py +255 -0
  223. charm/test/schemes/pksig/__init__.py +0 -0
  224. charm/test/schemes/pksig_test.py +376 -0
  225. charm/test/schemes/rsa_alg_test.py +340 -0
  226. charm/test/schemes/threshold_test.py +1792 -0
  227. charm/test/serialize/__init__.py +0 -0
  228. charm/test/serialize/serialize_test.py +40 -0
  229. charm/test/toolbox/__init__.py +0 -0
  230. charm/test/toolbox/conversion_test.py +30 -0
  231. charm/test/toolbox/ecgroup_test.py +53 -0
  232. charm/test/toolbox/integer_arithmetic_test.py +441 -0
  233. charm/test/toolbox/paddingschemes_test.py +238 -0
  234. charm/test/toolbox/policy_parser_stress_test.py +969 -0
  235. charm/test/toolbox/secretshare_test.py +28 -0
  236. charm/test/toolbox/symcrypto_test.py +108 -0
  237. charm/test/toolbox/test_policy_expression.py +16 -0
  238. charm/test/vectors/__init__.py +1 -0
  239. charm/test/vectors/test_bls_vectors.py +289 -0
  240. charm/test/vectors/test_pedersen_vectors.py +315 -0
  241. charm/test/vectors/test_schnorr_vectors.py +368 -0
  242. charm/test/zkp_compiler/__init__.py +9 -0
  243. charm/test/zkp_compiler/benchmark_zkp.py +258 -0
  244. charm/test/zkp_compiler/test_and_proof.py +240 -0
  245. charm/test/zkp_compiler/test_batch_verify.py +248 -0
  246. charm/test/zkp_compiler/test_dleq_proof.py +264 -0
  247. charm/test/zkp_compiler/test_or_proof.py +231 -0
  248. charm/test/zkp_compiler/test_proof_serialization.py +121 -0
  249. charm/test/zkp_compiler/test_range_proof.py +241 -0
  250. charm/test/zkp_compiler/test_representation_proof.py +325 -0
  251. charm/test/zkp_compiler/test_schnorr_proof.py +221 -0
  252. charm/test/zkp_compiler/test_thread_safety.py +169 -0
  253. charm/test/zkp_compiler/test_zkp_parser.py +139 -0
  254. charm/toolbox/ABEnc.py +26 -0
  255. charm/toolbox/ABEncMultiAuth.py +66 -0
  256. charm/toolbox/ABEnumeric.py +800 -0
  257. charm/toolbox/Commit.py +24 -0
  258. charm/toolbox/DFA.py +89 -0
  259. charm/toolbox/FSA.py +1254 -0
  260. charm/toolbox/Hash.py +39 -0
  261. charm/toolbox/IBEnc.py +62 -0
  262. charm/toolbox/IBSig.py +64 -0
  263. charm/toolbox/PKEnc.py +66 -0
  264. charm/toolbox/PKSig.py +56 -0
  265. charm/toolbox/PREnc.py +32 -0
  266. charm/toolbox/ZKProof.py +289 -0
  267. charm/toolbox/__init__.py +0 -0
  268. charm/toolbox/bitstring.py +49 -0
  269. charm/toolbox/broadcast.py +220 -0
  270. charm/toolbox/conversion.py +100 -0
  271. charm/toolbox/eccurve.py +149 -0
  272. charm/toolbox/ecgroup.py +143 -0
  273. charm/toolbox/enum.py +60 -0
  274. charm/toolbox/hash_module.py +91 -0
  275. charm/toolbox/integergroup.py +323 -0
  276. charm/toolbox/iterate.py +22 -0
  277. charm/toolbox/matrixops.py +76 -0
  278. charm/toolbox/mpc_utils.py +296 -0
  279. charm/toolbox/msp.py +175 -0
  280. charm/toolbox/mta.py +985 -0
  281. charm/toolbox/node.py +120 -0
  282. charm/toolbox/ot/__init__.py +22 -0
  283. charm/toolbox/ot/base_ot.py +374 -0
  284. charm/toolbox/ot/dpf.py +642 -0
  285. charm/toolbox/ot/mpfss.py +228 -0
  286. charm/toolbox/ot/ot_extension.py +589 -0
  287. charm/toolbox/ot/silent_ot.py +378 -0
  288. charm/toolbox/paddingschemes.py +423 -0
  289. charm/toolbox/paddingschemes_test.py +238 -0
  290. charm/toolbox/pairingcurves.py +85 -0
  291. charm/toolbox/pairinggroup.py +186 -0
  292. charm/toolbox/policy_expression_spec.py +70 -0
  293. charm/toolbox/policytree.py +189 -0
  294. charm/toolbox/reCompiler.py +346 -0
  295. charm/toolbox/redundancyschemes.py +65 -0
  296. charm/toolbox/schemebase.py +188 -0
  297. charm/toolbox/secretshare.py +104 -0
  298. charm/toolbox/secretutil.py +174 -0
  299. charm/toolbox/securerandom.py +73 -0
  300. charm/toolbox/sigmaprotocol.py +46 -0
  301. charm/toolbox/specialprimes.py +45 -0
  302. charm/toolbox/symcrypto.py +279 -0
  303. charm/toolbox/threshold_sharing.py +553 -0
  304. charm/toolbox/xmlserialize.py +94 -0
  305. charm/toolbox/zknode.py +105 -0
  306. charm/zkp_compiler/__init__.py +89 -0
  307. charm/zkp_compiler/and_proof.py +460 -0
  308. charm/zkp_compiler/batch_verify.py +324 -0
  309. charm/zkp_compiler/dleq_proof.py +423 -0
  310. charm/zkp_compiler/or_proof.py +305 -0
  311. charm/zkp_compiler/range_proof.py +417 -0
  312. charm/zkp_compiler/representation_proof.py +466 -0
  313. charm/zkp_compiler/schnorr_proof.py +273 -0
  314. charm/zkp_compiler/thread_safe.py +150 -0
  315. charm/zkp_compiler/zk_demo.py +489 -0
  316. charm/zkp_compiler/zkp_factory.py +330 -0
  317. charm/zkp_compiler/zkp_generator.py +370 -0
  318. charm/zkp_compiler/zkparser.py +269 -0
  319. charm_crypto_framework-0.61.1.dist-info/METADATA +337 -0
  320. charm_crypto_framework-0.61.1.dist-info/RECORD +323 -0
  321. charm_crypto_framework-0.61.1.dist-info/WHEEL +5 -0
  322. charm_crypto_framework-0.61.1.dist-info/licenses/LICENSE.txt +165 -0
  323. charm_crypto_framework-0.61.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,277 @@
1
+ '''
2
+ **Improved Dual System ABE (CGW15)**
3
+
4
+ *Authors:* Jie Chen, Romain Gay, Hoeteck Wee
5
+
6
+ | **Title:** "Improved Dual System ABE in Prime-Order Groups via Predicate Encodings"
7
+ | **Published in:** EUROCRYPT, 2015
8
+ | **Available from:** http://eprint.iacr.org/2015/409
9
+ | **Notes:** Implemented the scheme in Appendix B.2
10
+
11
+ .. rubric:: Scheme Properties
12
+
13
+ * **Type:** ciphertext-policy attribute-based encryption
14
+ * **Setting:** Pairing groups (prime order)
15
+ * **Assumption:** k-linear
16
+
17
+ .. rubric:: Implementation
18
+
19
+ :Authors: Shashank Agrawal
20
+ :Date: 05/2016
21
+ '''
22
+
23
+ from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair
24
+ from charm.toolbox.ABEnc import ABEnc
25
+ from charm.toolbox.msp import MSP
26
+
27
+ debug = False
28
+
29
+
30
+ class CGW15CPABE(ABEnc):
31
+ def __init__(self, groupObj, assump_size, uni_size, verbose=False):
32
+ ABEnc.__init__(self)
33
+ self.group = groupObj
34
+ self.assump_size = assump_size # size of the linear assumption
35
+ self.uni_size = uni_size # bound on the size of the universe of attributes
36
+ self.util = MSP(self.group, verbose)
37
+
38
+ def setup(self):
39
+ """
40
+ Generates public key and master secret key.
41
+ """
42
+
43
+ if debug:
44
+ print('Setup algorithm:\n')
45
+
46
+ # generate two instances of the k-linear assumption
47
+ A = []
48
+ B = []
49
+ for i in range(self.assump_size):
50
+ A.append(self.group.random(ZR))
51
+ B.append(self.group.random(ZR)) # note that A, B are vectors here
52
+
53
+ # pick matrices that help to randomize basis
54
+ W = {}
55
+ for i in range(self.uni_size):
56
+ x = []
57
+ for j1 in range(self.assump_size + 1):
58
+ y = []
59
+ for j2 in range(self.assump_size + 1):
60
+ y.append(self.group.random(ZR))
61
+ x.append(y)
62
+ W[i + 1] = x
63
+
64
+ V = []
65
+ for j1 in range(self.assump_size + 1):
66
+ y = []
67
+ for j2 in range(self.assump_size + 1):
68
+ y.append(self.group.random(ZR))
69
+ V.append(y)
70
+
71
+ # vector
72
+ k = []
73
+ for i in range(self.assump_size + 1):
74
+ k.append(self.group.random(ZR))
75
+
76
+ # pick a random element from the two source groups and pair them
77
+ g = self.group.random(G1)
78
+ h = self.group.random(G2)
79
+ e_gh = pair(g, h)
80
+
81
+ # now compute various parts of the public parameters
82
+
83
+ # compute the [A]_1 term
84
+ g_A = []
85
+ for i in range(self.assump_size):
86
+ g_A.append(g ** A[i])
87
+ g_A.append(g)
88
+
89
+ # compute the [W_1^T A]_1, [W_2^T A]_1, ... terms
90
+ g_WA = {}
91
+ for i in range(self.uni_size):
92
+ x = []
93
+ for j1 in range(self.assump_size + 1):
94
+ y = []
95
+ for j2 in range(self.assump_size):
96
+ prod = (A[j2] * W[i + 1][j2][j1]) + W[i + 1][self.assump_size][j1]
97
+ y.append(g ** prod)
98
+ x.append(y)
99
+ g_WA[i + 1] = x
100
+
101
+ g_VA = []
102
+ for j1 in range(self.assump_size + 1):
103
+ y = []
104
+ for j2 in range(self.assump_size):
105
+ prod = (A[j2] * V[j2][j1]) + V[self.assump_size][j1]
106
+ y.append(g ** prod)
107
+ g_VA.append(y)
108
+
109
+ # compute the e([A]_1, [k]_2) term
110
+ h_k = []
111
+ for i in range(self.assump_size + 1):
112
+ h_k.append(h ** k[i])
113
+
114
+ e_gh_kA = []
115
+ for i in range(self.assump_size):
116
+ e_gh_kA.append(e_gh ** (k[i] * A[i] + k[self.assump_size]))
117
+
118
+ # the public key
119
+ pk = {'g_A': g_A, 'g_WA': g_WA, 'g_VA': g_VA, 'e_gh_kA': e_gh_kA}
120
+
121
+ # the master secret key
122
+ msk = {'h': h, 'k': k, 'B': B, 'W': W, 'V': V}
123
+
124
+ return pk, msk
125
+
126
+ def keygen(self, pk, msk, attr_list):
127
+ """
128
+ Generate a key for a set of attributes.
129
+ """
130
+
131
+ if debug:
132
+ print('Key generation algorithm:\n')
133
+
134
+ # pick randomness
135
+ r = []
136
+ sum = 0
137
+ for i in range(self.assump_size):
138
+ rand = self.group.random(ZR)
139
+ r.append(rand)
140
+ sum += rand
141
+
142
+ # compute the [Br]_2 term
143
+ K_0 = []
144
+ Br = []
145
+ h = msk['h']
146
+ for i in range(self.assump_size):
147
+ prod = msk['B'][i] * r[i]
148
+ Br.append(prod)
149
+ K_0.append(h ** prod)
150
+ Br.append(sum)
151
+ K_0.append(h ** sum)
152
+
153
+ # compute the [W_i^T Br]_2 terms
154
+ K = {}
155
+ for attr in attr_list:
156
+ key = []
157
+ W_attr = msk['W'][int(attr)]
158
+ for j1 in range(self.assump_size + 1):
159
+ sum = 0
160
+ for j2 in range(self.assump_size + 1):
161
+ sum += W_attr[j1][j2] * Br[j2]
162
+ key.append(h ** sum)
163
+ K[attr] = key
164
+
165
+ # compute the [k + VBr]_2 term
166
+ Kp = []
167
+ V = msk['V']
168
+ k = msk['k']
169
+ for j1 in range(self.assump_size + 1):
170
+ sum = 0
171
+ for j2 in range(self.assump_size + 1):
172
+ sum += V[j1][j2] * Br[j2]
173
+ Kp.append(h ** (k[j1] + sum))
174
+
175
+ return {'attr_list': attr_list, 'K_0': K_0, 'K': K, 'Kp': Kp}
176
+
177
+ def encrypt(self, pk, msg, policy_str):
178
+ """
179
+ Encrypt a message M under a policy string.
180
+ """
181
+
182
+ if debug:
183
+ print('Encryption algorithm:\n')
184
+
185
+ policy = self.util.createPolicy(policy_str)
186
+ mono_span_prog = self.util.convert_policy_to_msp(policy)
187
+ num_cols = self.util.len_longest_row
188
+
189
+ # pick randomness
190
+ s = []
191
+ sum = 0
192
+ for i in range(self.assump_size):
193
+ rand = self.group.random(ZR)
194
+ s.append(rand)
195
+ sum += rand
196
+ s.append(sum)
197
+
198
+ # compute the [As]_1 term
199
+ g_As = []
200
+ g_A = pk['g_A']
201
+ for i in range(self.assump_size + 1):
202
+ g_As.append(g_A[i] ** s[i])
203
+
204
+ # compute U^T_2 As, U^T_3 As by picking random matrices U_2, U_3 ...
205
+ UAs = {}
206
+ for i in range(num_cols - 1):
207
+ x = []
208
+ for j1 in range(self.assump_size + 1):
209
+ prod = 1
210
+ for j2 in range(self.assump_size + 1):
211
+ prod *= g_As[j2] ** (self.group.random(ZR))
212
+ x.append(prod)
213
+ UAs[i+1] = x
214
+
215
+ # compute V^T As using VA from public key
216
+ VAs = []
217
+ g_VA = pk['g_VA']
218
+ for j1 in range(self.assump_size + 1):
219
+ prod = 1
220
+ for j2 in range(self.assump_size):
221
+ prod *= g_VA[j1][j2] ** s[j2]
222
+ VAs.append(prod)
223
+
224
+ # compute the [(V^T As||U^T_2 As||...||U^T_cols As) M^T_i + W^T_i As]_1 terms
225
+ C = {}
226
+ g_WA = pk['g_WA']
227
+ for attr, row in mono_span_prog.items():
228
+ attr_stripped = self.util.strip_index(attr) # no need, re-use not allowed
229
+ ct = []
230
+ for j1 in range(self.assump_size + 1):
231
+ cols = len(row)
232
+ prod1 = VAs[j1] ** row[0]
233
+ for j2 in range(1, cols):
234
+ prod1 *= UAs[j2][j1] ** row[j2]
235
+ prod2 = 1
236
+ for j2 in range(self.assump_size):
237
+ prod2 *= g_WA[int(attr_stripped)][j1][j2] ** s[j2]
238
+ ct.append(prod1 * prod2)
239
+ C[attr] = ct
240
+
241
+ # compute the e(g, h)^(k^T As) . m term
242
+ Cx = 1
243
+ for i in range(self.assump_size):
244
+ Cx = Cx * (pk['e_gh_kA'][i] ** s[i])
245
+ Cx = Cx * msg
246
+
247
+ return {'policy': policy, 'C_0': g_As, 'C': C, 'Cx': Cx}
248
+
249
+ def decrypt(self, pk, ctxt, key):
250
+ """
251
+ Decrypt ciphertext ctxt with key key.
252
+ """
253
+
254
+ if debug:
255
+ print('Decryption algorithm:\n')
256
+
257
+ nodes = self.util.prune(ctxt['policy'], key['attr_list'])
258
+ if not nodes:
259
+ print ("Policy not satisfied.")
260
+ return None
261
+
262
+ prod1_GT = 1
263
+ prod2_GT = 1
264
+ for i in range(self.assump_size + 1):
265
+ prod_H = 1
266
+ prod_G = 1
267
+ for node in nodes:
268
+ attr = node.getAttributeAndIndex()
269
+ attr_stripped = self.util.strip_index(attr) # no need, re-use not allowed
270
+ # prod_H *= D['K'][attr_stripped][i] ** coeff[attr]
271
+ # prod_G *= E['C'][attr][i] ** coeff[attr]
272
+ prod_H *= key['K'][attr_stripped][i]
273
+ prod_G *= ctxt['C'][attr][i]
274
+ prod1_GT *= pair(ctxt['C_0'][i], key['Kp'][i] * prod_H)
275
+ prod2_GT *= pair(prod_G, key['K_0'][i])
276
+
277
+ return ctxt['Cx'] * prod2_GT / prod1_GT
@@ -0,0 +1,204 @@
1
+ '''
2
+ **Decentralized Attribute-Based Encryption (AW11)**
3
+
4
+ *Authors:* Allison Lewko, Brent Waters
5
+
6
+ | **Title:** "Decentralizing Attribute-Based Encryption"
7
+ | **Published in:** EUROCRYPT, 2011 (Appendix D)
8
+ | **Available from:** http://eprint.iacr.org/2010/351.pdf
9
+ | **Notes:** Decentralized multi-authority ABE construction
10
+
11
+ .. rubric:: Scheme Properties
12
+
13
+ * **Type:** decentralized attribute-based encryption
14
+ * **Setting:** Bilinear groups (asymmetric)
15
+ * **Assumption:** Decisional Bilinear Diffie-Hellman
16
+
17
+ .. rubric:: Implementation
18
+
19
+ :Authors: Gary Belvin
20
+ :Date: 06/2011
21
+ '''
22
+
23
+ from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
24
+ from charm.toolbox.secretutil import SecretUtil
25
+ from charm.toolbox.ABEncMultiAuth import ABEncMultiAuth
26
+
27
+ debug = False
28
+ class Dabe(ABEncMultiAuth):
29
+ """
30
+ Decentralized Attribute-Based Encryption by Lewko and Waters
31
+
32
+ >>> group = PairingGroup('SS512')
33
+ >>> dabe = Dabe(group)
34
+ >>> public_parameters = dabe.setup()
35
+ >>> auth_attrs= ['ONE', 'TWO', 'THREE', 'FOUR'] #setup an authority
36
+ >>> (master_secret_key, master_public_key) = dabe.authsetup(public_parameters, auth_attrs)
37
+
38
+ Setup a user and give him some keys
39
+ >>> ID, secret_keys = "bob", {}
40
+ >>> usr_attrs = ['THREE', 'ONE', 'TWO']
41
+ >>> for i in usr_attrs: dabe.keygen(public_parameters, master_secret_key, i, ID, secret_keys)
42
+ >>> msg = group.random(GT)
43
+ >>> policy = '((one or three) and (TWO or FOUR))'
44
+ >>> cipher_text = dabe.encrypt(public_parameters, master_public_key, msg, policy)
45
+ >>> decrypted_msg = dabe.decrypt(public_parameters, secret_keys, cipher_text)
46
+ >>> decrypted_msg == msg
47
+ True
48
+ """
49
+ def __init__(self, groupObj):
50
+ ABEncMultiAuth.__init__(self)
51
+ global util, group
52
+ util = SecretUtil(groupObj, verbose=False) #Create Secret Sharing Scheme
53
+ group = groupObj #:Prime order group
54
+ #Another comment
55
+
56
+ def setup(self):
57
+ '''Global Setup'''
58
+ #:In global setup, a bilinear group G of prime order p is chosen
59
+ #:The global public parameters, GP and p, and a generator g of G. A random oracle H maps global identities GID to elements of G
60
+
61
+ #:group contains
62
+ #:the prime order p is contained somewhere within the group object
63
+ g = group.random(G1)
64
+ #: The oracle that maps global identities GID onto elements of G
65
+ #:H = lambda str: g** group.hash(str)
66
+ H = lambda x: group.hash(x, G1)
67
+ GP = {'g':g, 'H': H}
68
+
69
+ return GP
70
+
71
+ def authsetup(self, GP, attributes):
72
+ '''Authority Setup for a given set of attributes'''
73
+ #For each attribute i belonging to the authority, the authority chooses two random exponents,
74
+ #alpha_i, y_i and publishes PK={e(g,g)^alpha_i, g^y_i} for each attribute
75
+ #it keeps SK = {alpha_i, y_i} as its secret key
76
+ SK = {} #dictionary of {s: {alpha_i, y_i}}
77
+ PK = {} #dictionary of {s: {e(g,g)^alpha_i, g^y}}
78
+ for i in attributes:
79
+ #TODO: Is ZR an appropriate choice for a random element in Zp?
80
+ alpha_i, y_i = group.random(), group.random()
81
+ e_gg_alpha_i = pair(GP['g'],GP['g']) ** alpha_i
82
+ g_y_i = GP['g'] ** y_i
83
+ SK[i.upper()] = {'alpha_i': alpha_i, 'y_i': y_i}
84
+ PK[i.upper()] = {'e(gg)^alpha_i': e_gg_alpha_i, 'g^y_i': g_y_i}
85
+
86
+ if(debug):
87
+ print("Authority Setup for %s" % attributes)
88
+ print("SK = {alpha_i, y_i}")
89
+ print(SK)
90
+ print("PK = {e(g,g) ^ alpha_i, g ^ y_i}")
91
+ print(PK)
92
+
93
+ return (SK, PK)
94
+
95
+ def keygen(self, gp, sk, i, gid, pkey):
96
+ '''Create a key for GID on attribute i belonging to authority sk
97
+ sk is the private key for the releveant authority
98
+ i is the attribute to give bob
99
+ pkey is bob's private key dictionary, to which the appropriate private key is added
100
+ '''
101
+ #To create a key for GID for attribute i belonging to an authority, the authority computes K_{i,GID} = g^alpha_i * H(GID)^y_
102
+ h = gp['H'](gid)
103
+ K = (gp['g'] ** sk[i.upper()]['alpha_i']) * (h ** sk[i.upper()]['y_i'])
104
+
105
+ pkey[i.upper()] = {'k': K}
106
+ pkey['gid'] = gid
107
+
108
+ if(debug):
109
+ print("Key gen for %s on %s" % (gid, i))
110
+ print("H(GID): '%s'" % h)
111
+ print("K = g^alpha_i * H(GID) ^ y_i: %s" % K)
112
+ return None
113
+
114
+ def encrypt(self, gp, pk, M, policy_str):
115
+ '''Encrypt'''
116
+ #M is a group element
117
+ #pk is a dictionary with all the attributes of all authorities put together.
118
+ #This is legal because no attribute can be shared by more than one authority
119
+ #{i: {'e(gg)^alpha_i: , 'g^y_i'}
120
+ s = group.random()
121
+ w = group.init(ZR, 0)
122
+ egg_s = pair(gp['g'],gp['g']) ** s
123
+ C0 = M * egg_s
124
+ C1, C2, C3 = {}, {}, {}
125
+
126
+ #Parse the policy string into a tree
127
+ policy = util.createPolicy(policy_str)
128
+ sshares = util.calculateSharesList(s, policy) #Shares of the secret
129
+ wshares = util.calculateSharesList(w, policy) #Shares of 0
130
+
131
+
132
+ wshares = dict([(x[0].getAttributeAndIndex(), x[1]) for x in wshares])
133
+ sshares = dict([(x[0].getAttributeAndIndex(), x[1]) for x in sshares])
134
+ for attr, s_share in sshares.items():
135
+ k_attr = util.strip_index(attr)
136
+ w_share = wshares[attr]
137
+ r_x = group.random()
138
+ C1[attr] = (pair(gp['g'],gp['g']) ** s_share) * (pk[k_attr]['e(gg)^alpha_i'] ** r_x)
139
+ C2[attr] = gp['g'] ** r_x
140
+ C3[attr] = (pk[k_attr]['g^y_i'] ** r_x) * (gp['g'] ** w_share)
141
+
142
+ return { 'C0':C0, 'C1':C1, 'C2':C2, 'C3':C3, 'policy':policy_str }
143
+
144
+ def decrypt(self, gp, sk, ct):
145
+ '''Decrypt a ciphertext
146
+ SK is the user's private key dictionary {attr: { xxx , xxx }}
147
+ '''
148
+ usr_attribs = list(sk.keys())
149
+ usr_attribs.remove('gid')
150
+ policy = util.createPolicy(ct['policy'])
151
+ pruned = util.prune(policy, usr_attribs)
152
+ if pruned == False:
153
+ raise Exception("Don't have the required attributes for decryption!")
154
+ coeffs = util.getCoefficients(policy)
155
+
156
+ h_gid = gp['H'](sk['gid']) #find H(GID)
157
+ egg_s = 1
158
+ for i in pruned:
159
+ x = i.getAttributeAndIndex()
160
+ y = i.getAttribute()
161
+ num = ct['C1'][x] * pair(h_gid, ct['C3'][x])
162
+ dem = pair(sk[y]['k'], ct['C2'][x])
163
+ egg_s *= ( (num / dem) ** coeffs[x] )
164
+
165
+ if(debug): print("e(gg)^s: %s" % egg_s)
166
+
167
+ return ct['C0'] / egg_s
168
+
169
+ def main():
170
+ groupObj = PairingGroup('SS512')
171
+
172
+ dabe = Dabe(groupObj)
173
+ GP = dabe.setup()
174
+
175
+ #Setup an authority
176
+ auth_attrs= ['ONE', 'TWO', 'THREE', 'FOUR']
177
+ (SK, PK) = dabe.authsetup(GP, auth_attrs)
178
+ if debug: print("Authority SK")
179
+ if debug: print(SK)
180
+
181
+ #Setup a user and give him some keys
182
+ gid, K = "bob", {}
183
+ usr_attrs = ['THREE', 'ONE', 'TWO']
184
+ for i in usr_attrs: dabe.keygen(GP, SK, i, gid, K)
185
+ if debug: print('User credential list: %s' % usr_attrs)
186
+ if debug: print("\nSecret key:")
187
+ if debug: groupObj.debug(K)
188
+
189
+ #Encrypt a random element in GT
190
+ m = groupObj.random(GT)
191
+ policy = '((one or three) and (TWO or FOUR))'
192
+ if debug: print('Acces Policy: %s' % policy)
193
+ CT = dabe.encrypt(GP, PK, m, policy)
194
+ if debug: print("\nCiphertext...")
195
+ if debug: groupObj.debug(CT)
196
+
197
+ orig_m = dabe.decrypt(GP, K, CT)
198
+
199
+ assert m == orig_m, 'FAILED Decryption!!!'
200
+ if debug: print('Successful Decryption!')
201
+
202
+ if __name__ == '__main__':
203
+ debug = True
204
+ main()
@@ -0,0 +1,144 @@
1
+ '''
2
+ **Functional Encryption for Regular Languages (FE12)**
3
+
4
+ *Authors:* Brent Waters
5
+
6
+ | **Title:** "Functional Encryption for Regular Languages"
7
+ | **Published in:** CRYPTO, 2012
8
+ | **Available from:** http://eprint.iacr.org/2012/384
9
+ | **Notes:** DFA-based functional encryption with public index
10
+
11
+ .. rubric:: Scheme Properties
12
+
13
+ * **Type:** functional encryption (public index)
14
+ * **Setting:** Pairing groups
15
+ * **Assumption:** Decisional Linear
16
+
17
+ .. rubric:: Implementation
18
+
19
+ :Authors: J. Ayo Akinyele
20
+ :Date: 12/2012
21
+ '''
22
+ from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
23
+ from charm.toolbox.DFA import DFA
24
+
25
+ debug = False
26
+ class FE_DFA:
27
+ def __init__(self, _groupObj, _dfaObj):
28
+ global group, dfaObj
29
+ group = _groupObj
30
+ dfaObj = _dfaObj
31
+
32
+ def setup(self, alphabet):
33
+ g, z, h_start, h_end = group.random(G1, 4)
34
+ h = {'start':h_start, 'end':h_end }
35
+ for sigma in alphabet:
36
+ h[str(sigma)] = group.random(G1)
37
+ alpha = group.random(ZR)
38
+
39
+ msk = g ** -alpha
40
+ mpk = {'egg':pair(g, g) ** alpha, 'g':g, 'z':z, 'h':h }
41
+ return (mpk, msk)
42
+
43
+ def keygen(self, mpk, msk, dfaM):
44
+ Q, S, T, q0, F = dfaM
45
+ q = len(Q)
46
+ # associate D_i with each state q_i in Q
47
+ D = group.random(G1, q+1) # [0, q] including q-th index
48
+ r_start = group.random(ZR)
49
+ K = {}
50
+ K['start1'] = D[0] * (mpk['h']['start'] ** r_start)
51
+ K['start2'] = mpk['g'] ** r_start
52
+
53
+ for t in T: # for each tuple, t in transition list
54
+ r = group.random(ZR)
55
+ (x, y, sigma) = t
56
+ K[str(t)] = {}
57
+ K[str(t)][1] = (D[x] ** -1) * (mpk['z'] ** r)
58
+ K[str(t)][2] = mpk['g'] ** r
59
+ K[str(t)][3] = D[y] * ((mpk['h'][str(sigma)]) ** r)
60
+
61
+ # for each accept state in the set of all accept states
62
+ K['end'] = {}
63
+ for x in F:
64
+ rx = group.random(ZR)
65
+ K['end'][str(x)] = {}
66
+ K['end'][str(x)][1] = msk * D[x] * (mpk['h']['end'] ** rx)
67
+ K['end'][str(x)][2] = mpk['g'] ** rx
68
+
69
+ sk = {'K':K, 'dfaM':dfaM }
70
+ return sk
71
+
72
+ def encrypt(self, mpk, w, M):
73
+ l = len(w) # symbols of string
74
+ s = group.random(ZR, l+1) # l+1 b/c it includes 'l'-th index
75
+ C = {}
76
+ C['m'] = M * (mpk['egg'] ** s[l])
77
+
78
+ C[0] = {}
79
+ C[0][1] = mpk['g'] ** s[0]
80
+ C[0][2] = mpk['h']['start'] ** s[0]
81
+
82
+ for i in range(1, l+1):
83
+ C[i] = {}
84
+ C[i][1] = mpk['g'] ** s[i]
85
+ C[i][2] = (mpk['h'][ str(w[i]) ] ** s[i]) * (mpk['z'] ** s[i-1])
86
+
87
+ C['end1'] = mpk['g'] ** s[l]
88
+ C['end2'] = mpk['h']['end'] ** s[l]
89
+ ct = {'C':C, 'w':w}
90
+ return ct
91
+
92
+ def decrypt(self, sk, ct):
93
+ K, dfaM = sk['K'], sk['dfaM']
94
+ C, w = ct['C'], ct['w']
95
+ l = len(w)
96
+ B = {}
97
+ # if DFA does not accept string, return immediately
98
+ if not dfaObj.accept(dfaM, w):
99
+ print("DFA rejects: ", w)
100
+ return False
101
+
102
+ Ti = dfaObj.getTransitions(dfaM, w) # returns a tuple of transitions
103
+ B[0] = pair(C[0][1], K['start1']) * (pair(C[0][2], K['start2']) ** -1)
104
+ for i in range(1, l+1):
105
+ ti = Ti[i]
106
+ if debug: print("transition: ", ti)
107
+ B[i] = B[i-1] * pair(C[i-1][1], K[str(ti)][1]) * (pair(C[i][2], K[str(ti)][2]) ** -1) * pair(C[i][1], K[str(ti)][3])
108
+
109
+ x = dfaObj.getAcceptState(Ti) # retrieve accept state
110
+ Bend = B[l] * (pair(C['end1'], K['end'][str(x)][1]) ** -1) * pair(C['end2'], K['end'][str(x)][2])
111
+ M = C['m'] / Bend
112
+ return M
113
+
114
+ def main():
115
+ global group
116
+ group = PairingGroup("SS512")
117
+
118
+ alphabet = {'a', 'b'}
119
+ dfa = DFA("ab*a", alphabet)
120
+ dfaM = dfa.constructDFA()
121
+
122
+ fe = FE_DFA(group, dfa)
123
+
124
+ (mpk, msk) = fe.setup(alphabet)
125
+ if debug: print("mpk :=>", mpk, "\n\n")
126
+
127
+ sk = fe.keygen(mpk, msk, dfaM)
128
+ if debug: print("sk :=>", sk)
129
+
130
+ w = dfa.getSymbols("abba")
131
+ M = group.random(GT)
132
+ ct = fe.encrypt(mpk, w, M)
133
+
134
+ origM = fe.decrypt(sk, ct)
135
+ assert M == origM, "failed decryption!"
136
+ if debug: print("Successful Decryption!!!!!")
137
+
138
+ if __name__ == "__main__":
139
+ debug = True
140
+ main()
141
+
142
+
143
+
144
+