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
charm/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ # This fixes an issue where certain python interpeters/operating systems
2
+ # fail to properly load shared modules that c extensions depend on.
3
+ # In this case, the benchmark module is not handeled properly on osx
4
+ # as such we import it preimptively to force its symbols to be loaded.
5
+ import charm.core.benchmark
File without changes
@@ -0,0 +1,90 @@
1
+ '''
2
+ **Hybrid Encryption Adapter for CP-ABE (CP-ABE Hybrid)**
3
+
4
+ *Description:* Converts a Ciphertext-Policy Attribute-Based Encryption scheme into a hybrid
5
+ encryption scheme capable of encrypting arbitrary-length messages.
6
+
7
+ | **Notes:** Uses symmetric encryption (AES) with a randomly generated session key.
8
+ | The session key is encrypted using the underlying CP-ABE scheme.
9
+
10
+ .. rubric:: Adapter Properties
11
+
12
+ * **Type:** hybrid encryption adapter
13
+ * **Underlying Scheme:** any Ciphertext-Policy ABE scheme
14
+ * **Purpose:** enables CP-ABE schemes to encrypt arbitrary-length byte messages
15
+
16
+ .. rubric:: Implementation
17
+
18
+ :Authors: J. Ayo Akinyele
19
+ :Date: 2011
20
+ '''
21
+
22
+
23
+ from charm.toolbox.ABEnc import ABEnc
24
+ from charm.schemes.abenc.abenc_bsw07 import CPabe_BSW07
25
+ from charm.toolbox.pairinggroup import PairingGroup,GT
26
+ from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction
27
+ from charm.core.math.pairing import hashPair as sha2
28
+ from math import ceil
29
+
30
+ debug = False
31
+ class HybridABEnc(ABEnc):
32
+ """
33
+ >>> group = PairingGroup("SS512")
34
+ >>> cpabe = CPabe_BSW07(group)
35
+ >>> hyb_abe = HybridABEnc(cpabe, group)
36
+ >>> access_policy = '((four or three) and (two or one))'
37
+ >>> msg = b"hello world this is an important message."
38
+ >>> (master_public_key, master_key) = hyb_abe.setup()
39
+ >>> secret_key = hyb_abe.keygen(master_public_key, master_key, ['ONE', 'TWO', 'THREE'])
40
+ >>> cipher_text = hyb_abe.encrypt(master_public_key, msg, access_policy)
41
+ >>> hyb_abe.decrypt(master_public_key, secret_key, cipher_text)
42
+ b'hello world this is an important message.'
43
+ """
44
+ def __init__(self, scheme, groupObj):
45
+ ABEnc.__init__(self)
46
+ # check properties (TODO)
47
+ self.abenc = scheme
48
+ self.group = groupObj
49
+
50
+ def setup(self):
51
+ return self.abenc.setup()
52
+
53
+ def keygen(self, pk, mk, object):
54
+ return self.abenc.keygen(pk, mk, object)
55
+
56
+ def encrypt(self, pk, M, object):
57
+ key = self.group.random(GT)
58
+ c1 = self.abenc.encrypt(pk, key, object)
59
+ # instantiate a symmetric enc scheme from this key
60
+ cipher = AuthenticatedCryptoAbstraction(sha2(key))
61
+ c2 = cipher.encrypt(M)
62
+ return { 'c1':c1, 'c2':c2 }
63
+
64
+ def decrypt(self, pk, sk, ct):
65
+ c1, c2 = ct['c1'], ct['c2']
66
+ key = self.abenc.decrypt(pk, sk, c1)
67
+ if key is False:
68
+ raise Exception("failed to decrypt!")
69
+ cipher = AuthenticatedCryptoAbstraction(sha2(key))
70
+ return cipher.decrypt(c2)
71
+
72
+ def main():
73
+ groupObj = PairingGroup('SS512')
74
+ cpabe = CPabe_BSW07(groupObj)
75
+ hyb_abe = HybridABEnc(cpabe, groupObj)
76
+ access_policy = '((four or three) and (two or one))'
77
+ message = b"hello world this is an important message."
78
+ (pk, mk) = hyb_abe.setup()
79
+ if debug: print("pk => ", pk)
80
+ if debug: print("mk => ", mk)
81
+ sk = hyb_abe.keygen(pk, mk, ['ONE', 'TWO', 'THREE'])
82
+ if debug: print("sk => ", sk)
83
+ ct = hyb_abe.encrypt(pk, message, access_policy)
84
+ mdec = hyb_abe.decrypt(pk, sk, ct)
85
+ assert mdec == message, "Failed Decryption!!!"
86
+ if debug: print("Successful Decryption!!!")
87
+
88
+ if __name__ == "__main__":
89
+ debug = True
90
+ main()
@@ -0,0 +1,145 @@
1
+ '''
2
+ **Hybrid Encryption Adapter for Multi-Authority ABE (MA-ABE Hybrid)**
3
+
4
+ *Description:* Converts a Decentralized/Multi-Authority Attribute-Based Encryption scheme
5
+ into a hybrid encryption scheme capable of encrypting arbitrary-length messages.
6
+
7
+ | **Notes:** Uses symmetric encryption (AES) with a randomly generated session key.
8
+ | The session key is encrypted using the underlying Multi-Authority ABE scheme.
9
+
10
+ .. rubric:: Adapter Properties
11
+
12
+ * **Type:** hybrid encryption adapter
13
+ * **Underlying Scheme:** any Decentralized/Multi-Authority ABE scheme
14
+ * **Purpose:** enables Multi-Authority ABE schemes to encrypt arbitrary-length byte messages
15
+
16
+ .. rubric:: Implementation
17
+
18
+ :Authors: J. Ayo Akinyele
19
+ :Date: 2011
20
+ '''
21
+
22
+ from charm.core.math.pairing import hashPair as sha2
23
+ from charm.schemes.abenc.dabe_aw11 import Dabe
24
+ from charm.toolbox.ABEncMultiAuth import ABEncMultiAuth
25
+ from charm.toolbox.pairinggroup import PairingGroup,GT
26
+ from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction
27
+
28
+ debug = False
29
+ class HybridABEncMA(ABEncMultiAuth):
30
+ """
31
+ >>> from charm.toolbox.pairinggroup import PairingGroup,GT
32
+ >>> group = PairingGroup('SS512')
33
+ >>> dabe = Dabe(group)
34
+
35
+ Setup master authority.
36
+ >>> hyb_abema = HybridABEncMA(dabe, group)
37
+ >>> global_parameters = hyb_abema.setup()
38
+
39
+ Generate attributes for two different sub-authorities:
40
+ Johns Hopkins University, and Johns Hopkins Medical Institutions.
41
+ >>> jhu_attributes = ['jhu.professor', 'jhu.staff', 'jhu.student']
42
+ >>> jhmi_attributes = ['jhmi.doctor', 'jhmi.nurse', 'jhmi.staff', 'jhmi.researcher']
43
+
44
+ Johns Hopkins sub-authorities master key.
45
+ >>> (jhu_secret_key, jhu_public_key) = hyb_abema.authsetup(global_parameters, jhu_attributes)
46
+
47
+ JHMI sub-authorities master key
48
+ >>> (jhmi_secret_key, jhmi_public_key) = hyb_abema.authsetup(global_parameters, jhmi_attributes)
49
+
50
+ To encrypt messages we need all of the authorities' public keys.
51
+ >>> allAuth_public_key = {};
52
+ >>> allAuth_public_key.update(jhu_public_key);
53
+ >>> allAuth_public_key.update(jhmi_public_key)
54
+
55
+ An example user, Bob, who is both a professor at JHU and a researcher at JHMI.
56
+ >>> ID = "20110615 bob@gmail.com cryptokey"
57
+ >>> secrets_keys = {}
58
+ >>> hyb_abema.keygen(global_parameters, jhu_secret_key,'jhu.professor', ID, secrets_keys)
59
+ >>> hyb_abema.keygen(global_parameters, jhmi_secret_key,'jhmi.researcher', ID, secrets_keys)
60
+
61
+ Encrypt a message to anyone who is both a profesor at JHU and a researcher at JHMI.
62
+ >>> msg = b'Hello World, I am a sensitive record!'
63
+ >>> policy_str = "(jhmi.doctor or (jhmi.researcher and jhu.professor))"
64
+ >>> cipher_text = hyb_abema.encrypt(global_parameters, allAuth_public_key, msg, policy_str)
65
+ >>> hyb_abema.decrypt(global_parameters, secrets_keys, cipher_text)
66
+ b'Hello World, I am a sensitive record!'
67
+ """
68
+ def __init__(self, scheme, groupObj):
69
+ global abencma, group
70
+ # check properties (TODO)
71
+ abencma = scheme
72
+ group = groupObj
73
+
74
+ def setup(self):
75
+ return abencma.setup()
76
+
77
+ def authsetup(self, gp, attributes):
78
+ return abencma.authsetup(gp, attributes)
79
+
80
+ def keygen(self, gp, sk, i, gid, pkey):
81
+ return abencma.keygen(gp, sk, i, gid, pkey)
82
+
83
+ def encrypt(self, gp, pk, M, policy_str):
84
+ if type(M) != bytes and type(policy_str) != str:
85
+ raise Exception("message and policy not right type!")
86
+ key = group.random(GT)
87
+ c1 = abencma.encrypt(gp, pk, key, policy_str)
88
+ # instantiate a symmetric enc scheme from this key
89
+ cipher = AuthenticatedCryptoAbstraction(sha2(key))
90
+ c2 = cipher.encrypt(M)
91
+ return { 'c1':c1, 'c2':c2 }
92
+
93
+ def decrypt(self, gp, sk, ct):
94
+ c1, c2 = ct['c1'], ct['c2']
95
+ key = abencma.decrypt(gp, sk, c1)
96
+ if key is False:
97
+ raise Exception("failed to decrypt!")
98
+ cipher = AuthenticatedCryptoAbstraction(sha2(key))
99
+ return cipher.decrypt(c2)
100
+
101
+ def main():
102
+ groupObj = PairingGroup('SS512')
103
+ dabe = Dabe(groupObj)
104
+
105
+ hyb_abema = HybridABEncMA(dabe, groupObj)
106
+
107
+ #Setup global parameters for all new authorities
108
+ gp = hyb_abema.setup()
109
+
110
+ #Instantiate a few authorities
111
+ #Attribute names must be globally unique. HybridABEncMA
112
+ #Two authorities may not issue keys for the same attribute.
113
+ #Otherwise, the decryption algorithm will not know which private key to use
114
+ jhu_attributes = ['jhu.professor', 'jhu.staff', 'jhu.student']
115
+ jhmi_attributes = ['jhmi.doctor', 'jhmi.nurse', 'jhmi.staff', 'jhmi.researcher']
116
+ (jhuSK, jhuPK) = hyb_abema.authsetup(gp, jhu_attributes)
117
+ (jhmiSK, jhmiPK) = hyb_abema.authsetup(gp, jhmi_attributes)
118
+ allAuthPK = {}; allAuthPK.update(jhuPK); allAuthPK.update(jhmiPK)
119
+
120
+ #Setup a user with a few keys
121
+ bobs_gid = "20110615 bob@gmail.com cryptokey"
122
+ K = {}
123
+ hyb_abema.keygen(gp, jhuSK,'jhu.professor', bobs_gid, K)
124
+ hyb_abema.keygen(gp, jhmiSK,'jhmi.researcher', bobs_gid, K)
125
+
126
+
127
+ msg = b'Hello World, I am a sensitive record!'
128
+ size = len(msg)
129
+ policy_str = "(jhmi.doctor OR (jhmi.researcher AND jhu.professor))"
130
+ ct = hyb_abema.encrypt(allAuthPK, gp, msg, policy_str)
131
+
132
+ if debug:
133
+ print("Ciphertext")
134
+ print("c1 =>", ct['c1'])
135
+ print("c2 =>", ct['c2'])
136
+
137
+ orig_msg = hyb_abema.decrypt(gp, K, ct)
138
+ if debug: print("Result =>", orig_msg)
139
+ assert orig_msg == msg, "Failed Decryption!!!"
140
+ if debug: print("Successful Decryption!!!")
141
+
142
+ if __name__ == "__main__":
143
+ debug = True
144
+ main()
145
+
@@ -0,0 +1,72 @@
1
+ '''
2
+ **Hybrid Encryption Adapter for IBE (IBE Hybrid)**
3
+
4
+ *Description:* Converts an Identity-Based Encryption scheme into a hybrid encryption
5
+ scheme capable of encrypting arbitrary-length messages.
6
+
7
+ | **Notes:** Uses symmetric encryption (AES) with a randomly generated session key.
8
+ | The session key is encrypted using the underlying IBE scheme.
9
+
10
+ .. rubric:: Adapter Properties
11
+
12
+ * **Type:** hybrid encryption adapter
13
+ * **Underlying Scheme:** any Identity-Based Encryption scheme
14
+ * **Purpose:** enables IBE schemes to encrypt arbitrary-length byte messages
15
+
16
+ .. rubric:: Implementation
17
+
18
+ :Authors: J. Ayo Akinyele
19
+ :Date: 2011
20
+ '''
21
+
22
+ from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction
23
+ from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
24
+ from charm.core.math.pairing import hashPair as sha2
25
+ from charm.adapters.ibenc_adapt_identityhash import HashIDAdapter
26
+ from charm.toolbox.IBEnc import IBEnc
27
+ from charm.core.crypto.cryptobase import *
28
+
29
+ debug = False
30
+ class HybridIBEnc(IBEnc):
31
+ """
32
+ >>> from charm.schemes.ibenc.ibenc_bb03 import IBE_BB04
33
+ >>> group = PairingGroup('SS512')
34
+ >>> ibe = IBE_BB04(group)
35
+ >>> hashID = HashIDAdapter(ibe, group)
36
+ >>> hyb_ibe = HybridIBEnc(hashID, group)
37
+ >>> (master_public_key, master_key) = hyb_ibe.setup()
38
+ >>> ID = 'john.doe@example.com'
39
+ >>> secret_key = hyb_ibe.extract(master_key, ID)
40
+ >>> msg = b"Hello World!"
41
+ >>> cipher_text = hyb_ibe.encrypt(master_public_key, ID, msg)
42
+ >>> decrypted_msg = hyb_ibe.decrypt(master_public_key, secret_key, cipher_text)
43
+ >>> decrypted_msg == msg
44
+ True
45
+
46
+ """
47
+ def __init__(self, scheme, groupObj):
48
+ global ibenc, group
49
+ ibenc = scheme
50
+ group = groupObj
51
+
52
+ def setup(self):
53
+ return ibenc.setup()
54
+
55
+ def extract(self, mk, ID):
56
+ return ibenc.extract(mk, ID)
57
+
58
+ def encrypt(self, pk, ID, M):
59
+ if type(M) != bytes: raise "message not right type!"
60
+ key = group.random(GT)
61
+ c1 = ibenc.encrypt(pk, ID, key)
62
+ # instantiate a symmetric enc scheme from this key
63
+ cipher = AuthenticatedCryptoAbstraction(sha2(key))
64
+ c2 = cipher.encrypt(M)
65
+ return { 'c1':c1, 'c2':c2 }
66
+
67
+ def decrypt(self, pk, ID, ct):
68
+ c1, c2 = ct['c1'], ct['c2']
69
+ key = ibenc.decrypt(pk, ID, c1)
70
+ cipher = AuthenticatedCryptoAbstraction(sha2(key))
71
+ return cipher.decrypt(c2)
72
+
@@ -0,0 +1,80 @@
1
+ '''
2
+ **Identity Hashing Adapter for IBE (HashID Adapter)**
3
+
4
+ *Description:* Converts an Identity-Based Encryption scheme that requires ZR (integer)
5
+ identities into one that accepts arbitrary string identities via cryptographic hashing.
6
+
7
+ | **Notes:** Hashes string identities to ZR elements using the pairing group's hash function.
8
+ | Transforms security from selective-ID (IND-sID-CPA) to full-ID (IND-ID-CPA) under ROM.
9
+
10
+ .. rubric:: Adapter Properties
11
+
12
+ * **Type:** identity transform adapter
13
+ * **Underlying Scheme:** any IBE scheme with ZR identity space
14
+ * **Purpose:** enables use of human-readable string identities (e.g., email addresses)
15
+
16
+ .. rubric:: Implementation
17
+
18
+ :Authors: J. Ayo Akinyele
19
+ :Date: 2011
20
+ '''
21
+
22
+ from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
23
+ from charm.toolbox.IBEnc import *
24
+
25
+ debug = False
26
+ class HashIDAdapter(IBEnc):
27
+ """
28
+ >>> from charm.schemes.ibenc.ibenc_bb03 import IBE_BB04
29
+ >>> group = PairingGroup('SS512')
30
+ >>> ibe = IBE_BB04(group)
31
+ >>> hashID = HashIDAdapter(ibe, group)
32
+ >>> (master_public_key, master_key) = hashID.setup()
33
+ >>> ID = 'john.doe@example.com'
34
+ >>> secret_key = hashID.extract(master_key, ID)
35
+ >>> msg = group.random(GT)
36
+ >>> cipher_text = hashID.encrypt(master_public_key, ID, msg)
37
+ >>> decrypted_msg = hashID.decrypt(master_public_key, secret_key, cipher_text)
38
+ >>> msg == decrypted_msg
39
+ True
40
+ """
41
+ def __init__(self, scheme, group):
42
+ global ibe
43
+ IBEnc.__init__(self)
44
+ self.group = group
45
+ ibe = None
46
+ # validate that we have the appropriate object
47
+ criteria = [('secDef', IND_sID_CPA), ('scheme', 'IBEnc'), ('secModel', SM), ('id',ZR)]
48
+ if IBEnc.checkProperty(self, scheme, criteria):
49
+ # change our property as well
50
+ IBEnc.updateProperty(self, scheme, secDef=IND_ID_CPA, id=str, secModel=ROM)
51
+ ibe = scheme
52
+ #IBEnc.printProperties(self)
53
+ else:
54
+ assert False, "Input scheme does not satisfy adapter properties: %s" % criteria
55
+
56
+ def setup(self):
57
+ assert ibe != None, "IBEnc alg not set"
58
+ return ibe.setup()
59
+
60
+ def extract(self, mk, ID):
61
+ assert ibe != None, "IBEnc alg not set"
62
+ if type(ID) in [str, bytes]:
63
+ ID2 = self.group.hash(ID)
64
+ sk = ibe.extract(mk, ID2); sk['IDstr'] = ID
65
+ return sk
66
+ else:
67
+ assert False, "invalid type on ID."
68
+
69
+ def encrypt(self, pk, ID, msg):
70
+ assert ibe != None, "IBEnc alg not set"
71
+ if type(ID) in [str, bytes]:
72
+ ID2 = self.group.hash(ID)
73
+ return ibe.encrypt(pk, ID2, msg)
74
+ else:
75
+ assert False, "invalid type on ID."
76
+
77
+ def decrypt(self, pk, sk, ct):
78
+ assert ibe != None, "IBEnc alg not set"
79
+ return ibe.decrypt(pk, sk, ct)
80
+
@@ -0,0 +1,91 @@
1
+ '''
2
+ **Hybrid Encryption Adapter for KP-ABE (KP-ABE Hybrid)**
3
+
4
+ *Description:* Converts a Key-Policy Attribute-Based Encryption scheme into a hybrid
5
+ encryption scheme capable of encrypting arbitrary-length messages.
6
+
7
+ | **Notes:** Uses symmetric encryption (AES) with a randomly generated session key.
8
+ | The session key is encrypted using the underlying KP-ABE scheme.
9
+
10
+ .. rubric:: Adapter Properties
11
+
12
+ * **Type:** hybrid encryption adapter
13
+ * **Underlying Scheme:** any Key-Policy ABE scheme
14
+ * **Purpose:** enables KP-ABE schemes to encrypt arbitrary-length byte messages
15
+
16
+ .. rubric:: Implementation
17
+
18
+ :Authors: J. Ayo Akinyele
19
+ :Date: 2011
20
+ '''
21
+
22
+
23
+ from charm.toolbox.pairinggroup import PairingGroup,GT,extract_key
24
+ from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction
25
+ from charm.toolbox.ABEnc import ABEnc
26
+ from charm.schemes.abenc.abenc_lsw08 import KPabe
27
+
28
+ debug = False
29
+ class HybridABEnc(ABEnc):
30
+ """
31
+ >>> from charm.schemes.abenc.abenc_lsw08 import KPabe
32
+ >>> group = PairingGroup('SS512')
33
+ >>> kpabe = KPabe(group)
34
+ >>> hyb_abe = HybridABEnc(kpabe, group)
35
+ >>> access_policy = ['ONE', 'TWO', 'THREE']
36
+ >>> access_key = '((FOUR or THREE) and (TWO or ONE))'
37
+ >>> msg = b"hello world this is an important message."
38
+ >>> (master_public_key, master_key) = hyb_abe.setup()
39
+ >>> secret_key = hyb_abe.keygen(master_public_key, master_key, access_key)
40
+ >>> cipher_text = hyb_abe.encrypt(master_public_key, msg, access_policy)
41
+ >>> hyb_abe.decrypt(cipher_text, secret_key)
42
+ b'hello world this is an important message.'
43
+ """
44
+
45
+ def __init__(self, scheme, groupObj):
46
+ ABEnc.__init__(self)
47
+ global abenc
48
+ # check properties (TODO)
49
+ abenc = scheme
50
+ self.group = groupObj
51
+
52
+ def setup(self):
53
+ return abenc.setup()
54
+
55
+ def keygen(self, pk, mk, object):
56
+ return abenc.keygen(pk, mk, object)
57
+
58
+ def encrypt(self, pk, M, object):
59
+ key = self.group.random(GT)
60
+ c1 = abenc.encrypt(pk, key, object)
61
+ # instantiate a symmetric enc scheme from this key
62
+ cipher = AuthenticatedCryptoAbstraction(extract_key(key))
63
+ c2 = cipher.encrypt(M)
64
+ return { 'c1':c1, 'c2':c2 }
65
+
66
+ def decrypt(self, ct, sk):
67
+ c1, c2 = ct['c1'], ct['c2']
68
+ key = abenc.decrypt(c1, sk)
69
+ cipher = AuthenticatedCryptoAbstraction(extract_key(key))
70
+ return cipher.decrypt(c2)
71
+
72
+ def main():
73
+ groupObj = PairingGroup('SS512')
74
+ kpabe = KPabe(groupObj)
75
+ hyb_abe = HybridABEnc(kpabe, groupObj)
76
+ access_key = '((ONE or TWO) and THREE)'
77
+ access_policy = ['ONE', 'TWO', 'THREE']
78
+ message = b"hello world this is an important message."
79
+ (pk, mk) = hyb_abe.setup()
80
+ if debug: print("pk => ", pk)
81
+ if debug: print("mk => ", mk)
82
+ sk = hyb_abe.keygen(pk, mk, access_key)
83
+ if debug: print("sk => ", sk)
84
+ ct = hyb_abe.encrypt(pk, message, access_policy)
85
+ mdec = hyb_abe.decrypt(ct, sk)
86
+ assert mdec == message, "Failed Decryption!!!"
87
+ if debug: print("Successful Decryption!!!")
88
+
89
+ if __name__ == "__main__":
90
+ debug = True
91
+ main()
@@ -0,0 +1,121 @@
1
+ '''
2
+ **Boneh-Canetti-Halevi-Katz IBE-to-PKE Transform (BCHK05)**
3
+
4
+ *Description:* Transforms an Identity-Based Encryption scheme into a CCA-secure
5
+ Public Key Encryption scheme using the BCHK construction.
6
+
7
+ | **Based on:** Improved Efficiency for CCA-Secure Cryptosystems Built Using Identity-Based Encryption
8
+ | **Published in:** Topics in Cryptology, CT-RSA 2005
9
+ | **Available from:** https://eprint.iacr.org/2004/261.pdf
10
+ | **Notes:** Section 4 of the paper; more efficient than CHK04 transform
11
+
12
+ .. rubric:: Adapter Properties
13
+
14
+ * **Type:** IBE-to-PKE transform
15
+ * **Underlying Scheme:** any selective-ID secure IBE scheme
16
+ * **Purpose:** constructs CCA-secure public key encryption from IBE
17
+
18
+ .. rubric:: Implementation
19
+
20
+ :Authors: Christina Garman
21
+ :Date: 12/2011
22
+ '''
23
+ from charm.core.engine.util import pickleObject, serializeObject
24
+ import hmac, hashlib, math
25
+ from charm.schemes.ibenc.ibenc_bb03 import IBEnc, ZR, GT, sha2
26
+
27
+ debug = False
28
+ class BCHKIBEnc(IBEnc):
29
+ """
30
+ >>> from charm.schemes.encap_bchk05 import EncapBCHK
31
+ >>> from charm.schemes.ibenc.ibenc_bb03 import PairingGroup, IBE_BB04
32
+ >>> group = PairingGroup('SS512')
33
+ >>> ibe = IBE_BB04(group)
34
+ >>> encap = EncapBCHK()
35
+ >>> hyb_ibe = BCHKIBEnc(ibe, group, encap)
36
+ >>> (public_key, secret_key) = hyb_ibe.keygen()
37
+ >>> msg = b"Hello World!"
38
+ >>> cipher_text = hyb_ibe.encrypt(public_key, msg)
39
+ >>> decrypted_msg = hyb_ibe.decrypt(public_key, secret_key, cipher_text)
40
+ >>> decrypted_msg == msg
41
+ True
42
+ """
43
+ def str_XOR(self, m, k):
44
+ output = ""
45
+ for character in m:
46
+ for letter in k:
47
+ if(not type(character) == int):
48
+ character = ord(character)
49
+ if(not type(letter) == int):
50
+ letter = ord(letter)
51
+
52
+ character = chr(character ^ letter)
53
+ output += character
54
+ return output
55
+
56
+ def elmtToString(self, g, length):
57
+ hash_len = 20
58
+ b = math.ceil(length / hash_len)
59
+ gStr = b''
60
+ for i in range(1, b+1):
61
+ gStr += sha2(g, i)
62
+ return gStr[:length]
63
+
64
+ def __init__(self, scheme, groupObj, encscheme):
65
+ global ibenc, group, encap
66
+ ibenc = scheme
67
+ group = groupObj
68
+ encap = encscheme
69
+
70
+ def keygen(self):
71
+ (PK, msk) = ibenc.setup()
72
+ pub = encap.setup()
73
+ pk = { 'PK':PK, 'pub':pub }
74
+ sk = { 'msk': msk }
75
+ return (pk, sk)
76
+
77
+ def encrypt(self, pk, m):
78
+ (k, ID, x) = encap.S(pk['pub'])
79
+ if type(m) != bytes:
80
+ m = bytes(m, 'utf8')
81
+ if type(x) != bytes:
82
+ x = bytes(x, 'utf8')
83
+
84
+ ID2 = group.hash(ID, ZR)
85
+
86
+ m2 = m + b':' + x
87
+
88
+ kprime = group.random(GT)
89
+ kprimeStr = self.elmtToString(kprime, len(m2))
90
+
91
+ C1 = ibenc.encrypt(pk['PK'], ID2, kprime)
92
+
93
+ C2 = self.str_XOR(m2, kprimeStr)
94
+ C2 = C2.encode('utf8')
95
+
96
+ C1prime = pickleObject(serializeObject(C1, group))
97
+
98
+ tag = hmac.new(k, C1prime+C2, hashlib.sha256).digest()
99
+
100
+ cipher = { 'ID':ID, 'C1':C1, 'C2':C2, 'tag':tag }
101
+ return cipher
102
+
103
+ def decrypt(self, pk, sk, c):
104
+ ID2 = group.hash(c['ID'], ZR)
105
+ SK = ibenc.extract(sk['msk'], ID2)
106
+ kprime = ibenc.decrypt(pk, SK, c['C1'])
107
+
108
+ kprimeStr = self.elmtToString(kprime, len(c['C2']))
109
+
110
+ m2 = self.str_XOR(c['C2'], kprimeStr)
111
+
112
+ x = m2.split(':')[1]
113
+ k = encap.R(pk['pub'], c['ID'], x)
114
+
115
+ C1prime = pickleObject(serializeObject(c['C1'], group))
116
+
117
+ if hmac.compare_digest(c['tag'], hmac.new(k, C1prime+c['C2'], hashlib.sha256).digest()):
118
+ return bytes(m2.split(':')[0], 'utf8')
119
+ else:
120
+ return b'FALSE'
121
+