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,178 @@
1
+ '''
2
+ **Extended Proxy-Assisted Revocable CP-ABE (YLLC15)**
3
+
4
+ *Authors:* Yanjiang Yang, Joseph K Liu, Kaitai Liang, Kim Kwang Raymond Choo, Jianying Zhou
5
+
6
+ | **Title:** "Extended Proxy-Assisted Approach: Achieving Revocable Fine-Grained Encryption of Cloud Data"
7
+ | **Published in:** 2015
8
+ | **Available from:** N/A
9
+ | **Notes:** Adapted from BSW07, provides revocable fine-grained encryption for cloud data
10
+
11
+ .. rubric:: Scheme Properties
12
+
13
+ * **Type:** ciphertext-policy attribute-based encryption
14
+ * **Setting:** Pairing groups
15
+ * **Assumption:** Decisional Bilinear Diffie-Hellman
16
+
17
+ .. rubric:: Implementation
18
+
19
+ :Authors: Douglas Hellinger
20
+ :Date: 11/2018
21
+ '''
22
+
23
+ from charm.toolbox.ABEnc import ABEnc, Output
24
+ from charm.toolbox.pairinggroup import ZR, G1, G2, GT, pair
25
+ from charm.toolbox.schemebase import Input
26
+ from charm.toolbox.secretutil import SecretUtil
27
+
28
+ # type annotations
29
+ params_t = {'g': G1, 'g2': G2, 'h': G1, 'e_gg_alpha': GT}
30
+ msk_t = {'beta': ZR, 'alpha': ZR}
31
+ pku_t = G2
32
+ sku_t = ZR
33
+ pxku_t = {'k': G2, 'k_prime': G2, 'k_attrs': dict}
34
+ ct_t = {'policy_str': str,
35
+ 'C': GT,
36
+ 'C_prime': G1,
37
+ 'C_prime_prime': G1,
38
+ 'c_attrs': dict
39
+ }
40
+ v_t = {'C': GT,
41
+ 'e_term': GT}
42
+
43
+
44
+ class YLLC15(ABEnc):
45
+ """
46
+ Possibly a subclass of BSW07?
47
+ """
48
+ def __init__(self, group):
49
+ ABEnc.__init__(self)
50
+ self.group = group
51
+ self.util = SecretUtil(self.group)
52
+
53
+ @Output(params_t, msk_t)
54
+ def setup(self):
55
+ g, gp = self.group.random(G1), self.group.random(G2)
56
+ alpha, beta = self.group.random(ZR), self.group.random(ZR)
57
+ # initialize pre-processing for generators
58
+ g.initPP()
59
+ gp.initPP()
60
+
61
+ h = g ** beta
62
+ e_gg_alpha = pair(g, gp ** alpha)
63
+
64
+ params = {'g': g, 'g2': gp, 'h': h, 'e_gg_alpha': e_gg_alpha}
65
+ msk = {'beta': beta, 'alpha': alpha}
66
+ return params, msk
67
+
68
+ @Input(params_t)
69
+ @Output(pku_t, sku_t)
70
+ def ukgen(self, params):
71
+ g2 = params['g2']
72
+ x = self.group.random(ZR)
73
+ pku = g2 ** x
74
+ sku = x
75
+ return pku, sku
76
+
77
+ @Input(params_t, msk_t, pku_t, pku_t, [str])
78
+ # @Output(pxku_t)
79
+ def proxy_keygen(self, params, msk, pkcs, pku, attribute_list):
80
+ """
81
+ attributes specified in the `attribute_list` are converted to uppercase
82
+ """
83
+ r1 = self.group.random(ZR)
84
+ r2 = self.group.random(ZR)
85
+ g = params['g']
86
+ g2 = params['g2']
87
+
88
+ k = ((pkcs ** r1) * (pku ** msk['alpha']) * (g2 ** r2)) ** ~msk['beta']
89
+ k_prime = g2 ** r1
90
+ k_attrs = {}
91
+ for attr in attribute_list:
92
+ attr_caps = attr.upper()
93
+ r_attr = self.group.random(ZR)
94
+ k_attr1 = (g2 ** r2) * (self.group.hash(str(attr_caps), G2) ** r_attr)
95
+ k_attr2 = g ** r_attr
96
+ k_attrs[attr_caps] = (k_attr1, k_attr2)
97
+
98
+ proxy_key_user = {'k': k, 'k_prime': k_prime, 'k_attrs': k_attrs}
99
+ return proxy_key_user
100
+
101
+ @Input(params_t, GT, str)
102
+ # @Output(ct_t)
103
+ def encrypt(self, params, msg, policy_str):
104
+ """
105
+ Encrypt a message M under a policy string.
106
+
107
+ attributes specified in policy_str are converted to uppercase
108
+ policy_str must use parentheses e.g. (A) and (B)
109
+ """
110
+ policy = self.util.createPolicy(policy_str)
111
+ s = self.group.random(ZR)
112
+ shares = self.util.calculateSharesDict(s, policy)
113
+
114
+ C = (params['e_gg_alpha'] ** s) * msg
115
+ c_prime = params['h'] ** s
116
+ c_prime_prime = params['g'] ** s
117
+
118
+ c_attrs = {}
119
+ for attr in shares.keys():
120
+ attr_stripped = self.util.strip_index(attr)
121
+ c_i1 = params['g'] ** shares[attr]
122
+ c_i2 = self.group.hash(attr_stripped, G1) ** shares[attr]
123
+ c_attrs[attr] = (c_i1, c_i2)
124
+
125
+ ciphertext = {'policy_str': policy_str,
126
+ 'C': C,
127
+ 'C_prime': c_prime,
128
+ 'C_prime_prime': c_prime_prime,
129
+ 'c_attrs': c_attrs}
130
+ return ciphertext
131
+
132
+ # @Input(sku_t, pxku_t, ct_t)
133
+ @Output(v_t)
134
+ def proxy_decrypt(self, skcs, proxy_key_user, ciphertext):
135
+ policy_root_node = ciphertext['policy_str']
136
+ k = proxy_key_user['k']
137
+ k_prime = proxy_key_user['k_prime']
138
+ c_prime = ciphertext['C_prime']
139
+ c_prime_prime = ciphertext['C_prime_prime']
140
+ c_attrs = ciphertext['c_attrs']
141
+ k_attrs = proxy_key_user['k_attrs']
142
+
143
+ policy = self.util.createPolicy(policy_root_node)
144
+ attributes = proxy_key_user['k_attrs'].keys()
145
+ pruned_list = self.util.prune(policy, attributes)
146
+ if not pruned_list:
147
+ return None
148
+ z = self.util.getCoefficients(policy)
149
+ # reconstitute the policy random secret (A) which was used to encrypt the message
150
+ A = 1
151
+ for i in pruned_list:
152
+ attr_idx = i.getAttributeAndIndex()
153
+ attr = i.getAttribute()
154
+ A *= (pair(c_attrs[attr_idx][0], k_attrs[attr][0]) / pair(k_attrs[attr][1], c_attrs[attr_idx][1])) ** z[attr_idx]
155
+
156
+ e_k_c_prime = pair(k, c_prime)
157
+ denominator = (pair(k_prime, c_prime_prime) ** skcs) * A
158
+ encrypted_element_for_user_pkenc_scheme = e_k_c_prime / denominator
159
+
160
+ intermediate_value = {'C': ciphertext['C'],
161
+ 'e_term': encrypted_element_for_user_pkenc_scheme}
162
+
163
+ return intermediate_value
164
+
165
+ @Input(type(None), sku_t, v_t)
166
+ @Output(GT)
167
+ def decrypt(self, params, sku, intermediate_value):
168
+ """
169
+ :param params: Not required - pass None instead. For interface compatibility only.
170
+ :param sku: the secret key of the user as generated by `ukgen()`.
171
+ :param intermediate_value: the partially decrypted ciphertext returned by `proxy_decrypt()`.
172
+ :return: the plaintext message
173
+ """
174
+ ciphertext = intermediate_value['C']
175
+ e_term = intermediate_value['e_term']
176
+ denominator = e_term ** (sku ** -1)
177
+ msg = ciphertext / denominator
178
+ return msg
@@ -0,0 +1,248 @@
1
+ '''
2
+ **FAME: Fast Attribute-based Message Encryption (AC17)**
3
+
4
+ *Authors:* Shashank Agrawal, Melissa Chase
5
+
6
+ | **Title:** "FAME: Fast Attribute-based Message Encryption"
7
+ | **Published in:** ACM CCS, 2017
8
+ | **Available from:** https://eprint.iacr.org/2017/807
9
+ | **Notes:** Implemented the scheme in Section 3; fast and practical ABE
10
+
11
+ .. rubric:: Scheme Properties
12
+
13
+ * **Type:** ciphertext-policy attribute-based encryption
14
+ * **Setting:** Pairing groups
15
+ * **Assumption:** Variant of k-linear (k >= 2)
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 AC17CPABE(ABEnc):
31
+ def __init__(self, group_obj, assump_size, verbose=False):
32
+ ABEnc.__init__(self)
33
+ self.group = group_obj
34
+ self.assump_size = assump_size # size of linear assumption, at least 2
35
+ self.util = MSP(self.group, verbose)
36
+
37
+ def setup(self):
38
+ """
39
+ Generates public key and master secret key.
40
+ """
41
+
42
+ if debug:
43
+ print('\nSetup algorithm:\n')
44
+
45
+ # generate two instances of the k-linear assumption
46
+ A = []
47
+ B = []
48
+ for i in range(self.assump_size):
49
+ A.append(self.group.random(ZR))
50
+ B.append(self.group.random(ZR)) # note that A, B are vectors here
51
+
52
+ # vector
53
+ k = []
54
+ for i in range(self.assump_size + 1):
55
+ k.append(self.group.random(ZR))
56
+
57
+ # pick a random element from the two source groups and pair them
58
+ g = self.group.random(G1)
59
+ h = self.group.random(G2)
60
+ e_gh = pair(g, h)
61
+
62
+ # now compute various parts of the public parameters
63
+
64
+ # compute the [A]_2 term
65
+ h_A = []
66
+ for i in range(self.assump_size):
67
+ h_A.append(h ** A[i])
68
+ h_A.append(h)
69
+
70
+ # compute the e([k]_1, [A]_2) term
71
+ g_k = []
72
+ for i in range(self.assump_size + 1):
73
+ g_k.append(g ** k[i])
74
+
75
+ e_gh_kA = []
76
+ for i in range(self.assump_size):
77
+ e_gh_kA.append(e_gh ** (k[i] * A[i] + k[self.assump_size]))
78
+
79
+ # the public key
80
+ pk = {'h_A': h_A, 'e_gh_kA': e_gh_kA}
81
+
82
+ # the master secret key
83
+ msk = {'g': g, 'h': h, 'g_k': g_k, 'A': A, 'B': B}
84
+
85
+ return pk, msk
86
+
87
+ def keygen(self, pk, msk, attr_list):
88
+ """
89
+ Generate a key for a list of attributes.
90
+ """
91
+
92
+ if debug:
93
+ print('\nKey generation algorithm:\n')
94
+
95
+ # pick randomness
96
+ r = []
97
+ sum = 0
98
+ for i in range(self.assump_size):
99
+ rand = self.group.random(ZR)
100
+ r.append(rand)
101
+ sum += rand
102
+
103
+ # compute the [Br]_2 term
104
+
105
+ # first compute just Br as it will be used later too
106
+ Br = []
107
+ for i in range(self.assump_size):
108
+ Br.append(msk['B'][i] * r[i])
109
+ Br.append(sum)
110
+
111
+ # now compute [Br]_2
112
+ K_0 = []
113
+ for i in range(self.assump_size + 1):
114
+ K_0.append(msk['h'] ** Br[i])
115
+
116
+ # compute [W_1 Br]_1, ...
117
+ K = {}
118
+ A = msk['A']
119
+ g = msk['g']
120
+ for attr in attr_list:
121
+ key = []
122
+ sigma_attr = self.group.random(ZR)
123
+ for t in range(self.assump_size):
124
+ prod = 1
125
+ a_t = A[t]
126
+ for l in range(self.assump_size + 1):
127
+ input_for_hash = attr + str(l) + str(t)
128
+ prod *= (self.group.hash(input_for_hash, G1) ** (Br[l]/a_t))
129
+ prod *= (g ** (sigma_attr/a_t))
130
+ key.append(prod)
131
+ key.append(g ** (-sigma_attr))
132
+ K[attr] = key
133
+
134
+ # compute [k + VBr]_1
135
+ Kp = []
136
+ g_k = msk['g_k']
137
+ sigma = self.group.random(ZR)
138
+ for t in range(self.assump_size):
139
+ prod = g_k[t]
140
+ a_t = A[t]
141
+ for l in range(self.assump_size + 1):
142
+ input_for_hash = '01' + str(l) + str(t)
143
+ prod *= (self.group.hash(input_for_hash, G1) ** (Br[l] / a_t))
144
+ prod *= (g ** (sigma / a_t))
145
+ Kp.append(prod)
146
+ Kp.append(g_k[self.assump_size] * (g ** (-sigma)))
147
+
148
+ return {'attr_list': attr_list, 'K_0': K_0, 'K': K, 'Kp': Kp}
149
+
150
+ def encrypt(self, pk, msg, policy_str):
151
+ """
152
+ Encrypt a message msg under a policy string.
153
+ """
154
+
155
+ if debug:
156
+ print('\nEncryption algorithm:\n')
157
+
158
+ policy = self.util.createPolicy(policy_str)
159
+ mono_span_prog = self.util.convert_policy_to_msp(policy)
160
+ num_cols = self.util.len_longest_row
161
+
162
+ # pick randomness
163
+ s = []
164
+ sum = 0
165
+ for i in range(self.assump_size):
166
+ rand = self.group.random(ZR)
167
+ s.append(rand)
168
+ sum += rand
169
+
170
+ # compute the [As]_2 term
171
+ C_0 = []
172
+ h_A = pk['h_A']
173
+ for i in range(self.assump_size):
174
+ C_0.append(h_A[i] ** s[i])
175
+ C_0.append(h_A[self.assump_size] ** sum)
176
+
177
+ # compute the [(V^T As||U^T_2 As||...) M^T_i + W^T_i As]_1 terms
178
+
179
+ # pre-compute hashes
180
+ hash_table = []
181
+ for j in range(num_cols):
182
+ x = []
183
+ input_for_hash1 = '0' + str(j + 1)
184
+ for l in range(self.assump_size + 1):
185
+ y = []
186
+ input_for_hash2 = input_for_hash1 + str(l)
187
+ for t in range(self.assump_size):
188
+ input_for_hash3 = input_for_hash2 + str(t)
189
+ hashed_value = self.group.hash(input_for_hash3, G1)
190
+ y.append(hashed_value)
191
+ # if debug: print ('Hash of', i+2, ',', j2, ',', j1, 'is', hashed_value)
192
+ x.append(y)
193
+ hash_table.append(x)
194
+
195
+ C = {}
196
+ for attr, row in mono_span_prog.items():
197
+ ct = []
198
+ attr_stripped = self.util.strip_index(attr) # no need, re-use not allowed
199
+ for l in range(self.assump_size + 1):
200
+ prod = 1
201
+ cols = len(row)
202
+ for t in range(self.assump_size):
203
+ input_for_hash = attr_stripped + str(l) + str(t)
204
+ prod1 = self.group.hash(input_for_hash, G1)
205
+ for j in range(cols):
206
+ # input_for_hash = '0' + str(j+1) + str(l) + str(t)
207
+ prod1 *= (hash_table[j][l][t] ** row[j])
208
+ prod *= (prod1 ** s[t])
209
+ ct.append(prod)
210
+ C[attr] = ct
211
+
212
+ # compute the e(g, h)^(k^T As) . m term
213
+ Cp = 1
214
+ for i in range(self.assump_size):
215
+ Cp = Cp * (pk['e_gh_kA'][i] ** s[i])
216
+ Cp = Cp * msg
217
+
218
+ return {'policy': policy, 'C_0': C_0, 'C': C, 'Cp': Cp}
219
+
220
+ def decrypt(self, pk, ctxt, key):
221
+ """
222
+ Decrypt ciphertext ctxt with key key.
223
+ """
224
+
225
+ if debug:
226
+ print('\nDecryption algorithm:\n')
227
+
228
+ nodes = self.util.prune(ctxt['policy'], key['attr_list'])
229
+ if not nodes:
230
+ print ("Policy not satisfied.")
231
+ return None
232
+
233
+ prod1_GT = 1
234
+ prod2_GT = 1
235
+ for i in range(self.assump_size + 1):
236
+ prod_H = 1
237
+ prod_G = 1
238
+ for node in nodes:
239
+ attr = node.getAttributeAndIndex()
240
+ attr_stripped = self.util.strip_index(attr) # no need, re-use not allowed
241
+ # prod_H *= key['K'][attr_stripped][i] ** coeff[attr]
242
+ # prod_G *= ctxt['C'][attr][i] ** coeff[attr]
243
+ prod_H *= key['K'][attr_stripped][i]
244
+ prod_G *= ctxt['C'][attr][i]
245
+ prod1_GT *= pair(key['Kp'][i] * prod_H, ctxt['C_0'][i])
246
+ prod2_GT *= pair(prod_G, key['K_0'][i])
247
+
248
+ return ctxt['Cp'] * prod2_GT / prod1_GT
@@ -0,0 +1,141 @@
1
+ '''
2
+ **Ciphertext-Policy Attribute-Based Encryption (BSW07) - Asymmetric**
3
+
4
+ *Authors:* John Bethencourt, Amit Sahai, Brent Waters
5
+
6
+ | **Title:** "Ciphertext-Policy Attribute-Based Encryption"
7
+ | **Published in:** IEEE Symposium on Security and Privacy, 2007
8
+ | **Available from:** https://doi.org/10.1109/SP.2007.11
9
+ | **Notes:** Asymmetric version of the scheme in Section 4.2
10
+
11
+ .. rubric:: Scheme Properties
12
+
13
+ * **Type:** ciphertext-policy attribute-based encryption
14
+ * **Setting:** Pairing groups
15
+ * **Assumption:** Generic group model
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 BSW07(ABEnc):
31
+
32
+ def __init__(self, group_obj, verbose=False):
33
+ ABEnc.__init__(self)
34
+ self.group = group_obj
35
+ self.util = MSP(self.group, verbose)
36
+
37
+ def setup(self):
38
+ """
39
+ Generates public key and master secret key.
40
+ """
41
+
42
+ if debug:
43
+ print('Setup algorithm:\n')
44
+
45
+ # pick a random element each from two source groups
46
+ g1 = self.group.random(G1)
47
+ g2 = self.group.random(G2)
48
+
49
+ beta = self.group.random(ZR)
50
+ h = g2 ** beta
51
+ f = g2 ** (1/beta)
52
+
53
+ alpha = self.group.random(ZR)
54
+ g1_alpha = g1 ** alpha
55
+ e_gg_alpha = pair (g1_alpha, g2)
56
+
57
+ pk = {'g1': g1, 'g2': g2, 'h': h, 'f': f, 'e_gg_alpha': e_gg_alpha}
58
+ msk = {'beta': beta, 'g1_alpha': g1_alpha}
59
+ return pk, msk
60
+
61
+ def keygen(self, pk, msk, attr_list):
62
+ """
63
+ Generate a key for a set of attributes.
64
+ """
65
+
66
+ if debug:
67
+ print('Key generation algorithm:\n')
68
+
69
+ r = self.group.random(ZR)
70
+ g1_r = pk['g1'] ** r
71
+ beta_inverse = 1 / msk['beta']
72
+ k0 = (msk['g1_alpha'] * g1_r) ** beta_inverse
73
+
74
+ K = {}
75
+ for attr in attr_list:
76
+ r_attr = self.group.random(ZR)
77
+ k_attr1 = g1_r * (self.group.hash(str(attr), G1) ** r_attr)
78
+ k_attr2 = pk['g2'] ** r_attr
79
+ K[attr] = (k_attr1, k_attr2)
80
+
81
+ return {'attr_list': attr_list, 'k0': k0, 'K': K}
82
+
83
+ def encrypt(self, pk, msg, policy_str):
84
+ """
85
+ Encrypt a message M under a policy string.
86
+ """
87
+
88
+ if debug:
89
+ print('Encryption algorithm:\n')
90
+
91
+ policy = self.util.createPolicy(policy_str)
92
+ mono_span_prog = self.util.convert_policy_to_msp(policy)
93
+ num_cols = self.util.len_longest_row
94
+
95
+ # pick randomness
96
+ u = []
97
+ for i in range(num_cols):
98
+ rand = self.group.random(ZR)
99
+ u.append(rand)
100
+ s = u[0] # shared secret
101
+
102
+ c0 = pk['h'] ** s
103
+
104
+ C = {}
105
+ for attr, row in mono_span_prog.items():
106
+ cols = len(row)
107
+ sum = 0
108
+ for i in range(cols):
109
+ sum += row[i] * u[i]
110
+ attr_stripped = self.util.strip_index(attr)
111
+ c_i1 = pk['g2'] ** sum
112
+ c_i2 = self.group.hash(str(attr_stripped), G1) ** sum
113
+ C[attr] = (c_i1, c_i2)
114
+
115
+ c_m = (pk['e_gg_alpha'] ** s) * msg
116
+
117
+ return {'policy': policy, 'c0': c0, 'C': C, 'c_m': c_m}
118
+
119
+ def decrypt(self, pk, ctxt, key):
120
+ """
121
+ Decrypt ciphertext ctxt with key key.
122
+ """
123
+
124
+ if debug:
125
+ print('Decryption algorithm:\n')
126
+
127
+ nodes = self.util.prune(ctxt['policy'], key['attr_list'])
128
+ if not nodes:
129
+ print ("Policy not satisfied.")
130
+ return None
131
+
132
+ prod = 1
133
+
134
+ for node in nodes:
135
+ attr = node.getAttributeAndIndex()
136
+ attr_stripped = self.util.strip_index(attr)
137
+ (c_attr1, c_attr2) = ctxt['C'][attr]
138
+ (k_attr1, k_attr2) = key['K'][attr_stripped]
139
+ prod *= (pair(k_attr1, c_attr1) / pair(c_attr2, k_attr2))
140
+
141
+ return (ctxt['c_m'] * prod) / (pair(key['k0'], ctxt['c0']))