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,91 @@
1
+ '''
2
+ **Canetti-Halevi-Katz IBE-to-PKE Transform (CHK04)**
3
+
4
+ *Description:* Transforms an Identity-Based Encryption scheme into a CCA-secure
5
+ Public Key Encryption scheme using generic composition of IBE + one-time signature.
6
+
7
+ | **Based on:** Chosen-Ciphertext Security from Identity-Based Encryption
8
+ | **Published in:** CRYPTO 2004
9
+ | **Available from:** https://eprint.iacr.org/2003/182
10
+ | **Notes:** Requires a selective-ID secure IBE scheme and an EU-CMA one-time signature scheme
11
+
12
+ .. rubric:: Adapter Properties
13
+
14
+ * **Type:** IBE-to-PKE transform
15
+ * **Underlying Scheme:** selective-ID secure IBE + EU-CMA one-time signature
16
+ * **Purpose:** constructs CCA-secure public key encryption from IBE and signatures
17
+
18
+ .. rubric:: Implementation
19
+
20
+ :Authors: J. Ayo Akinyele
21
+ :Date: 1/2011
22
+ '''
23
+ from charm.toolbox.PKEnc import *
24
+ from charm.toolbox.IBSig import *
25
+ from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
26
+
27
+ debug = False
28
+ class CHK04(PKEnc):
29
+ """
30
+ >>> from charm.adapters.ibenc_adapt_identityhash import HashIDAdapter
31
+ >>> from charm.schemes.ibenc.ibenc_bb03 import IBE_BB04
32
+ >>> from charm.schemes.pksig.pksig_bls04 import BLS01
33
+ >>> group = PairingGroup('SS512')
34
+ >>> ibe = IBE_BB04(group)
35
+ >>> hash_ibe = HashIDAdapter(ibe, group)
36
+ >>> ots = BLS01(group)
37
+ >>> pkenc = CHK04(hash_ibe, ots, group)
38
+ >>> (public_key, secret_key) = pkenc.keygen(0)
39
+ >>> msg = group.random(GT)
40
+ >>> cipher_text = pkenc.encrypt(public_key, msg)
41
+ >>> decrypted_msg = pkenc.decrypt(public_key, secret_key, cipher_text)
42
+ >>> decrypted_msg == msg
43
+ True
44
+ """
45
+ def __init__(self, ibe_scheme, ots_scheme, groupObj):
46
+ PKEnc.__init__(self)
47
+ global ibe, ots, group
48
+ criteria1 = [('secDef', 'IND_ID_CPA'), ('scheme', 'IBEnc'), ('id', str)]
49
+ criteria2 = [('secDef', 'EU_CMA'), ('scheme', 'IBSig')]
50
+ if PKEnc.checkProperty(self, ibe_scheme, criteria1): # and PKEnc.checkProperty(self, ots_scheme, criteria2):
51
+ PKEnc.updateProperty(self, ibe_scheme, secDef=IND_CCA, secModel=SM)
52
+ ibe = ibe_scheme
53
+ ots = ots_scheme
54
+ #PKEnc.printProperties(self)
55
+ else:
56
+ assert False, "Input scheme does not satisfy adapter properties: %s" % criteria
57
+
58
+ group = groupObj
59
+
60
+ def keygen(self, secparam):
61
+ # Run the IBE Setup routine to generate (mpk, msk)
62
+ (mpk, msk) = ibe.setup()
63
+
64
+ pk = { 'mpk' : mpk, 'secparam':secparam }
65
+ return (pk, msk)
66
+
67
+ def encrypt(self, pk, message):
68
+ # Generate a random keypair for the OTS
69
+ (svk, ssk) = ots.keygen(pk['secparam'])
70
+
71
+ # print("pub identity enc =>", _id)
72
+
73
+ # Encrypt message with the IBE scheme under 'identity' vk
74
+ C = ibe.encrypt(pk['mpk'],svk['identity'] , message)
75
+ # Sign the resulting ciphertext with sk
76
+ sigma = ots.sign(ssk['x'], C)
77
+ return { 'vk' : svk, 'C' : C, 'sigma' : sigma }
78
+
79
+ # NOTE: need to transform c['vk'] into a string to use as key
80
+ def decrypt(self, pk, sk, c):
81
+ # Given a ciphertext (vk, C, sigma), verify that sigma is a signature on C under public key vk
82
+ if not ots.verify(c['vk'], c['sigma'], c['C']):
83
+ return False
84
+
85
+ identity = c['vk']['identity']
86
+ # print("identity in dec =>", identity)
87
+ # Otherwise, extract an IBE key for identity 'vk' under the master secret params
88
+ dk = ibe.extract(sk, identity)
89
+ # Return the decryption of the ciphertext element "C" under key dk
90
+ return ibe.decrypt(pk, dk, c['C'])
91
+
@@ -0,0 +1,98 @@
1
+ '''
2
+ **Hybrid Encryption Adapter for PKE (PKE Hybrid)**
3
+
4
+ *Description:* Converts a Public Key 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 PKE scheme.
9
+ | Works with ElGamal and CS98 schemes.
10
+
11
+ .. rubric:: Adapter Properties
12
+
13
+ * **Type:** hybrid encryption adapter
14
+ * **Underlying Scheme:** any public key encryption scheme (e.g., ElGamal, CS98)
15
+ * **Purpose:** enables PKE schemes to encrypt arbitrary-length byte messages
16
+
17
+ .. rubric:: Implementation
18
+
19
+ :Authors: J. Ayo Akinyele
20
+ :Date: 2011
21
+ '''
22
+
23
+ # Works for ElGamal and CS98 schemes
24
+ from charm.toolbox.PKEnc import PKEnc
25
+ from charm.toolbox.securerandom import OpenSSLRand
26
+ from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction
27
+ from charm.toolbox.ecgroup import ECGroup
28
+ from charm.toolbox.eccurve import prime192v1
29
+ from charm.schemes.pkenc.pkenc_cs98 import CS98
30
+ from charm.core.crypto.cryptobase import AES
31
+ debug = False
32
+
33
+ # Adapter class for Hybrid Encryption Schemes
34
+ class HybridEnc(PKEnc):
35
+ """
36
+ >>> groupObj = ECGroup(prime192v1)
37
+ >>> pkenc = CS98(groupObj)
38
+ >>> hyenc = HybridEnc(pkenc, msg_len=groupObj.bitsize())
39
+ >>> (public_key, secret_key) = hyenc.keygen()
40
+ >>> msg = b'this is a new message'
41
+ >>> cipher_text = hyenc.encrypt(public_key, msg)
42
+ >>> decrypted_msg = hyenc.decrypt(public_key, secret_key, cipher_text)
43
+ >>> decrypted_msg == msg
44
+ True
45
+ """
46
+ def __init__(self, pkenc, msg_len=16, key_len=16, mode=AES):
47
+ PKEnc.__init__(self)
48
+ # check that pkenc satisfies properties of a pkenc scheme
49
+ if hasattr(pkenc, 'keygen') and hasattr(pkenc, 'encrypt') and hasattr(pkenc, 'decrypt'):
50
+ self.pkenc = pkenc
51
+ self.key_len = key_len # 128-bit session key by default
52
+ self.msg_len = msg_len
53
+ self.alg = mode
54
+ if debug: print("PKEnc satisfied.")
55
+
56
+ def keygen(self, secparam=None):
57
+ if secparam == None:
58
+ # ec module group
59
+ return self.pkenc.keygen()
60
+ # integer group
61
+ return self.pkenc.keygen(secparam)
62
+
63
+ def encrypt(self, pk, M):
64
+ # generate a short session key, K and encrypt using pkenc
65
+ key = OpenSSLRand().getRandomBytes(self.msg_len)
66
+ # encrypt session key using PKEnc
67
+ c1 = self.pkenc.encrypt(pk, key)
68
+ # use symmetric key encryption to enc actual message
69
+ c2 = AuthenticatedCryptoAbstraction(key).encrypt(M)
70
+ if debug: print("Ciphertext...")
71
+ if debug: print(c2)
72
+ return { 'c1':c1, 'c2':c2 }
73
+
74
+ def decrypt(self, pk, sk, ct):
75
+ c1, c2 = ct['c1'], ct['c2']
76
+ key = self.pkenc.decrypt(pk, sk, c1)[:self.key_len]
77
+ if debug: print("Rec key =>", key, ", len =", len(key))
78
+ msg = AuthenticatedCryptoAbstraction(key).decrypt(c2)
79
+ if debug: print("Rec msg =>", msg)
80
+ return msg
81
+
82
+ def main():
83
+ groupObj = ECGroup(prime192v1)
84
+ pkenc = CS98(groupObj)
85
+ hyenc = HybridEnc(pkenc)
86
+
87
+ (pk, sk) = hyenc.keygen()
88
+
89
+ m = b'this is a new message'
90
+
91
+ cipher = hyenc.encrypt(pk, m)
92
+ orig_m = hyenc.decrypt(pk, sk, cipher)
93
+ assert m == orig_m, "Failed Decryption"
94
+ if debug: print("Successful Decryption!!")
95
+
96
+ if __name__ == "__main__":
97
+ debug = True
98
+ main()
@@ -0,0 +1,89 @@
1
+ '''
2
+ **Naor's IBE-to-Signature Transform (Naor01)**
3
+
4
+ *Description:* Transforms a fully-secure Identity-Based Encryption scheme into a
5
+ digital signature scheme using Naor's construction.
6
+
7
+ | **Based on:** Identity-Based Encryption from the Weil Pairing
8
+ | **Published in:** CRYPTO 2001
9
+ | **Available from:** https://eprint.iacr.org/2001/090.pdf
10
+ | **Notes:** First described by Boneh and Franklin, credited to Moni Naor.
11
+ | Uses IBE key extraction as signing; verification via encrypt-then-decrypt.
12
+ | **Warning:** Not secure for selectively-secure IBE schemes!
13
+
14
+ .. rubric:: Adapter Properties
15
+
16
+ * **Type:** IBE-to-signature transform
17
+ * **Underlying Scheme:** any fully-secure IBE scheme
18
+ * **Purpose:** constructs digital signatures from Identity-Based Encryption
19
+
20
+ .. rubric:: Implementation
21
+
22
+ :Authors: J. Ayo Akinyele
23
+ :Date: 05/2011
24
+ '''
25
+
26
+ from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
27
+ from charm.toolbox.IBEnc import *
28
+ from charm.toolbox.PKSig import *
29
+
30
+ debug = False
31
+ class Sig_Generic_ibetosig_Naor01(PKSig):
32
+ """
33
+ >>> from charm.toolbox.pairinggroup import PairingGroup,ZR
34
+ >>> from charm.schemes.ibenc.ibenc_bb03 import IBE_BB04
35
+ >>> from charm.adapters.ibenc_adapt_identityhash import HashIDAdapter
36
+ >>> group = PairingGroup('MNT224')
37
+ >>> ibe = IBE_BB04(group)
38
+ >>> hashID = HashIDAdapter(ibe, group)
39
+ >>> ibsig = Sig_Generic_ibetosig_Naor01(hashID, group)
40
+ >>> (master_public_key, master_secret_key) = ibsig.keygen()
41
+ >>> msg = b"hello world!!!"
42
+ >>> signature = ibsig.sign(master_secret_key, msg)
43
+ >>> ibsig.verify(master_public_key, msg, signature)
44
+ True
45
+ """
46
+ def __init__(self, ibe_scheme, groupObj):
47
+ PKSig.__init__(self)
48
+ global ibe, group
49
+ # validate that we have the appropriate object
50
+ criteria = [('secDef', IND_ID_CPA), ('scheme', 'IBEnc'), ('messageSpace', GT)]
51
+ if PKSig.checkProperty(self, ibe_scheme, criteria):
52
+ # change our property as well
53
+ PKSig.updateProperty(self, ibe_scheme, secDef=EU_CMA, id=str, secModel=ROM)
54
+ ibe = ibe_scheme
55
+ #PKSig.printProperties(self)
56
+ else:
57
+ assert False, "Input scheme does not satisfy adapter properties: %s" % criteria
58
+ group = groupObj
59
+
60
+ def keygen(self):
61
+ (mpk, msk) = ibe.setup()
62
+ if debug: print("Keygen...")
63
+ group.debug(mpk)
64
+ group.debug(msk)
65
+ return (mpk, msk)
66
+
67
+ def sign(self, sk, m):
68
+ assert type(m) in [str, bytes], "invalid message type!"
69
+ return ibe.extract(sk, m)
70
+
71
+ def verify(self, pk, m, sig):
72
+ # Some IBE scheme support a native method for validating IBE keys. Use this if it exists.
73
+ if hasattr(ibe, 'verify'):
74
+ result = ibe.verify(pk, m, sig)
75
+ if result == False: return False
76
+
77
+ assert m == sig['IDstr'], "message not thesame as ID in signature"
78
+ # Encrypt a random message in the IBE's message space and try to decrypt it
79
+ new_m = group.random(GT)
80
+ if debug: print("\nRandom message =>", new_m)
81
+
82
+ C = ibe.encrypt(pk, sig['IDstr'], new_m)
83
+
84
+ if (ibe.decrypt(pk, sig, C) == new_m):
85
+ return True
86
+ else:
87
+ return False
88
+
89
+
charm/config.py ADDED
@@ -0,0 +1,7 @@
1
+ from charm.toolbox.enum import Enum
2
+
3
+ libs = Enum('openssl', 'gmp', 'pbc', 'miracl', 'relic')
4
+
5
+ pairing_lib=libs.pbc
6
+ ec_lib=libs.openssl
7
+ int_lib=libs.gmp
charm/core/__init__.py ADDED
File without changes
@@ -0,0 +1,353 @@
1
+
2
+ #if defined(__APPLE__)
3
+ // benchmark new
4
+ PyObject *Benchmark_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
5
+ {
6
+ Benchmark *self;
7
+ self = (Benchmark *)type->tp_alloc(type, 0);
8
+ if(self != NULL) {
9
+ self->bench_initialized = FALSE;
10
+ self->bench_inprogress = FALSE; // false until we StartBenchmark( ... )
11
+ self->op_add = self->op_sub = self->op_mult = 0;
12
+ self->op_div = self->op_exp = self->op_pair = 0;
13
+ self->cpu_time_ms = self->real_time_ms = 0.0;
14
+ self->cpu_option = self->real_option = FALSE;
15
+ debug("Creating new benchmark object.\n");
16
+ }
17
+ return (PyObject *) self;
18
+ }
19
+
20
+ // benchmark init
21
+ int Benchmark_init(Benchmark *self, PyObject *args, PyObject *kwds)
22
+ {
23
+ return 0;
24
+ }
25
+ // benchmark dealloc
26
+ void Benchmark_dealloc(Benchmark *self) {
27
+ debug("Releasing benchmark object.\n");
28
+ Py_TYPE(self)->tp_free((PyObject*)self);
29
+ }
30
+
31
+ PyTypeObject BenchmarkType = {
32
+ PyVarObject_HEAD_INIT(NULL, 0)
33
+ "profile.Benchmark", /*tp_name*/
34
+ sizeof(Benchmark), /*tp_basicsize*/
35
+ 0, /*tp_itemsize*/
36
+ (destructor)Benchmark_dealloc, /*tp_dealloc*/
37
+ 0, /*tp_print*/
38
+ 0, /*tp_getattr*/
39
+ 0, /*tp_setattr*/
40
+ 0, /*tp_reserved*/
41
+ 0, /*tp_repr*/
42
+ 0, /*tp_as_number*/
43
+ 0, /*tp_as_sequence*/
44
+ 0, /*tp_as_mapping*/
45
+ 0, /*tp_hash */
46
+ 0, /*tp_call*/
47
+ 0, /*tp_str*/
48
+ 0, /*tp_getattro*/
49
+ 0, /*tp_setattro*/
50
+ 0, /*tp_as_buffer*/
51
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
52
+ "Benchmark objects", /* tp_doc */
53
+ 0, /* tp_traverse */
54
+ 0, /* tp_clear */
55
+ 0, /* tp_richcompare */
56
+ 0, /* tp_weaklistoffset */
57
+ 0, /* tp_iter */
58
+ 0, /* tp_iternext */
59
+ 0, /* tp_methods */
60
+ 0, /* tp_members */
61
+ 0, /* tp_getset */
62
+ 0, /* tp_base */
63
+ 0, /* tp_dict */
64
+ 0, /* tp_descr_get */
65
+ 0, /* tp_descr_set */
66
+ 0, /* tp_dictoffset */
67
+ (initproc)Benchmark_init, /* tp_init */
68
+ 0, /* tp_alloc */
69
+ Benchmark_new, /* tp_new */
70
+ };
71
+
72
+ #endif
73
+
74
+ void Operations_dealloc(Operations *self)
75
+ {
76
+ debug("Releasing operations object.\n");
77
+ Py_TYPE(self)->tp_free((PyObject *) self);
78
+ }
79
+
80
+ PyObject *Operations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
81
+ {
82
+ Operations *self = (Operations *) type->tp_alloc(type, 0);
83
+ if(self != NULL) {
84
+ /* initialize */
85
+ self->op_init = FALSE;
86
+ }
87
+
88
+ return (PyObject *) self;
89
+ }
90
+
91
+ int Operations_init(Operations *self, PyObject *args, PyObject *kwds)
92
+ {
93
+ self->op_init = TRUE;
94
+ return 0;
95
+ }
96
+
97
+ /* for python 3.x */
98
+ PyTypeObject OperationsType = {
99
+ PyVarObject_HEAD_INIT(NULL, 0)
100
+ "profile.Operations", /*tp_name*/
101
+ sizeof(Operations), /*tp_basicsize*/
102
+ 0, /*tp_itemsize*/
103
+ (destructor)Operations_dealloc, /*tp_dealloc*/
104
+ 0, /*tp_print*/
105
+ 0, /*tp_getattr*/
106
+ 0, /*tp_setattr*/
107
+ 0, /*tp_reserved*/
108
+ 0, /*tp_repr*/
109
+ 0, /*tp_as_number*/
110
+ 0, /*tp_as_sequence*/
111
+ 0, /*tp_as_mapping*/
112
+ 0, /*tp_hash */
113
+ 0, /*tp_call*/
114
+ 0, /*tp_str*/
115
+ 0, /*tp_getattro*/
116
+ 0, /*tp_setattro*/
117
+ 0, /*tp_as_buffer*/
118
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
119
+ "Granular benchmark objects", /* tp_doc */
120
+ 0, /* tp_traverse */
121
+ 0, /* tp_clear */
122
+ 0, /* tp_richcompare */
123
+ 0, /* tp_weaklistoffset */
124
+ 0, /* tp_iter */
125
+ 0, /* tp_iternext */
126
+ 0, /* tp_methods */
127
+ 0, /* tp_members */
128
+ 0, /* tp_getset */
129
+ 0, /* tp_base */
130
+ 0, /* tp_dict */
131
+ 0, /* tp_descr_get */
132
+ 0, /* tp_descr_set */
133
+ 0, /* tp_dictoffset */
134
+ (initproc)Operations_init, /* tp_init */
135
+ 0, /* tp_alloc */
136
+ Operations_new, /* tp_new */
137
+ };
138
+
139
+ PyObject *InitBenchmark(PyObject *self, PyObject *args) {
140
+ Benchmark *benchObj = NULL;
141
+ GROUP_OBJECT *group = NULL;
142
+ if(!PyArg_ParseTuple(args, "O", &group)) {
143
+ PyErr_SetString(BENCH_ERROR, "InitBenchmark - invalid argument.");
144
+ return NULL;
145
+ }
146
+
147
+ VERIFY_GROUP(group);
148
+ if(group->dBench == NULL) {
149
+ benchObj = PyObject_New(Benchmark, &BenchmarkType);
150
+ if (benchObj == NULL) {
151
+ PyErr_SetString(BENCH_ERROR, "out of memory.");
152
+ return NULL;
153
+ }
154
+
155
+ /* setup granular options */
156
+ if(group->gBench == NULL) {
157
+ group->gBench = PyObject_New(Operations, &OperationsType);
158
+ CLEAR_ALLDBENCH(group->gBench);
159
+ }
160
+ benchObj->num_options = 0;
161
+ benchObj->op_add = benchObj->op_sub = benchObj->op_mult = 0;
162
+ benchObj->op_div = benchObj->op_exp = benchObj->op_pair = 0;
163
+ benchObj->cpu_time_ms = 0.0;
164
+ benchObj->real_time_ms = 0.0;
165
+ benchObj->bench_initialized = TRUE;
166
+ benchObj->bench_inprogress = FALSE;
167
+ benchObj->identifier = BenchmarkIdentifier;
168
+ debug("%s: bench id set: '%i'\n", __FUNCTION__, benchObj->identifier);
169
+ debug("Initialized benchmark object.\n");
170
+ // set benchmark field in group object
171
+ group->dBench = benchObj;
172
+ RAND_pseudo_bytes(group->bench_id, ID_LEN);
173
+ Py_RETURN_TRUE;
174
+ }
175
+ else if(group->dBench->bench_inprogress == FALSE && group->dBench->bench_initialized == TRUE) {
176
+ // if we have initialized the benchmark object and ended a benchmark execution:
177
+ // action: reset the fields
178
+ debug("Reset benchmark state.\n");
179
+ if(group->gBench != NULL) {
180
+ CLEAR_ALLDBENCH(group->gBench);
181
+ }
182
+ PyClearBenchmark(group->dBench);
183
+ group->dBench->bench_initialized = TRUE;
184
+ group->dBench->bench_inprogress = FALSE;
185
+ group->dBench->identifier = BenchmarkIdentifier;
186
+ Py_RETURN_TRUE;
187
+ }
188
+ else if(group->dBench->bench_inprogress == TRUE) {
189
+ debug("Benchmark in progress.\n");
190
+ }
191
+ debug("Benchmark already initialized.\n");
192
+ Py_RETURN_FALSE;
193
+ }
194
+
195
+ PyObject *StartBenchmark(PyObject *self, PyObject *args)
196
+ {
197
+ PyObject *list = NULL;
198
+ GROUP_OBJECT *group = NULL;
199
+ if(!PyArg_ParseTuple(args, "OO", &group, &list)) {
200
+ PyErr_SetString(BENCH_ERROR, "StartBenchmark - invalid argument.");
201
+ return NULL;
202
+ }
203
+
204
+ VERIFY_GROUP(group);
205
+ if(group->dBench == NULL) {
206
+ PyErr_SetString(BENCH_ERROR, "uninitialized benchmark object.");
207
+ return NULL;
208
+ }
209
+ else if(PyList_Check(list) && group->dBench->bench_initialized == TRUE && group->dBench->bench_inprogress == FALSE
210
+ && group->dBench->identifier == BenchmarkIdentifier)
211
+ {
212
+ debug("%s: bench id: '%i'\n", __FUNCTION__, group->dBench->identifier);
213
+ size_t size = PyList_Size(list);
214
+ PyStartBenchmark(group->dBench, list, size);
215
+ debug("list size => %zd\n", size);
216
+ debug("benchmark enabled and initialized!\n");
217
+ Py_RETURN_TRUE;
218
+ }
219
+ Py_RETURN_FALSE;
220
+ }
221
+
222
+ PyObject *EndBenchmark(PyObject *self, PyObject *args)
223
+ {
224
+ GROUP_OBJECT *group = NULL;
225
+ if(!PyArg_ParseTuple(args, "O", &group)) {
226
+ PyErr_SetString(BENCH_ERROR, "EndBenchmark - invalid argument.");
227
+ return NULL;
228
+ }
229
+
230
+ VERIFY_GROUP(group);
231
+ if(group->dBench == NULL) {
232
+ PyErr_SetString(BENCH_ERROR, "uninitialized benchmark object.");
233
+ return NULL;
234
+ }
235
+ else if(group->dBench->bench_initialized == TRUE && group->dBench->bench_inprogress == TRUE && group->dBench->identifier == BenchmarkIdentifier) {
236
+ PyEndBenchmark(group->dBench);
237
+ debug("%s: bench id: '%i'\n", __FUNCTION__, group->dBench->identifier);
238
+ Py_RETURN_TRUE;
239
+ }
240
+ Py_RETURN_FALSE;
241
+ }
242
+
243
+ PyObject *GetAllBenchmarks(PyObject *self, PyObject *args)
244
+ {
245
+ GROUP_OBJECT *group = NULL;
246
+ if(!PyArg_ParseTuple(args, "O", &group)) {
247
+ PyErr_SetString(BENCH_ERROR, "GetGeneralBenchmarks - invalid argument.");
248
+ return NULL;
249
+ }
250
+ VERIFY_GROUP(group);
251
+ if(group->dBench == NULL) {
252
+ PyErr_SetString(BENCH_ERROR, "uninitialized benchmark object.");
253
+ return NULL;
254
+ }
255
+ else if(group->dBench->bench_inprogress == FALSE && group->dBench->identifier == BenchmarkIdentifier) {
256
+ debug("%s: bench id: '%i'\n", __FUNCTION__, group->dBench->identifier);
257
+ // return GetResultsWithPair(group->dBench);
258
+ return GET_RESULTS_FUNC(group->dBench);
259
+ }
260
+ else if(group->dBench->bench_inprogress == TRUE) {
261
+ printf("Benchmark in progress.\n");
262
+ }
263
+ else {
264
+ debug("Invalid benchmark identifier.\n");
265
+ }
266
+ Py_RETURN_FALSE;
267
+ }
268
+
269
+ PyObject *GetBenchmark(PyObject *self, PyObject *args) {
270
+ char *opt = NULL;
271
+ GROUP_OBJECT *group = NULL;
272
+ if(!PyArg_ParseTuple(args, "Os", &group, &opt))
273
+ {
274
+ PyErr_SetString(BENCH_ERROR, "GetBenchmark - invalid argument.");
275
+ return NULL;
276
+ }
277
+
278
+ VERIFY_GROUP(group);
279
+ if(group->dBench == NULL) {
280
+ PyErr_SetString(BENCH_ERROR, "uninitialized benchmark object.");
281
+ return NULL;
282
+ }
283
+ else if(group->dBench->bench_inprogress == FALSE && group->dBench->identifier == BenchmarkIdentifier) {
284
+ return Retrieve_result(group->dBench, opt);
285
+ }
286
+ else if(group->dBench->bench_inprogress == TRUE) {
287
+ printf("Benchmark in progress.\n");
288
+ }
289
+ Py_RETURN_FALSE;
290
+ }
291
+
292
+ static PyObject *GranularBenchmark(PyObject *self, PyObject *args)
293
+ {
294
+ PyObject *dict = NULL;
295
+ GROUP_OBJECT *group = NULL;
296
+ if(!PyArg_ParseTuple(args, "O", &group)) {
297
+ PyErr_SetString(BENCH_ERROR, "GetGranularBenchmark - invalid argument.");
298
+ return NULL;
299
+ }
300
+
301
+ if(group->gBench == NULL || group->dBench == NULL) {
302
+ PyErr_SetString(BENCH_ERROR, "uninitialized benchmark object.");
303
+ return NULL;
304
+ }
305
+ else if(group->dBench->bench_inprogress == FALSE && BenchmarkIdentifier == group->dBench->identifier) {
306
+ if(group->dBench->granular_option == FALSE) {
307
+ PyErr_SetString(BENCH_ERROR, "granular option was not set.");
308
+ return NULL;
309
+ }
310
+ dict = PyDict_New();
311
+ if(dict == NULL) return NULL;
312
+ if(group->dBench->op_mult > 0) {
313
+ PyObject *MulList = PyCreateList(group->gBench, MULTIPLICATION);
314
+ //PrintPyRef('MulList Before =>', MulList);
315
+ PyDict_SetItemString(dict, "Mul", MulList);
316
+ Py_DECREF(MulList);
317
+ }
318
+
319
+ if(group->dBench->op_div > 0) {
320
+ PyObject *DivList = PyCreateList(group->gBench, DIVISION);
321
+ PyDict_SetItemString(dict, "Div", DivList);
322
+ Py_DECREF(DivList);
323
+ }
324
+
325
+ if(group->dBench->op_add > 0) {
326
+ PyObject *AddList = PyCreateList(group->gBench, ADDITION);
327
+ PyDict_SetItemString(dict, "Add", AddList);
328
+ Py_DECREF(AddList);
329
+ }
330
+
331
+ if(group->dBench->op_sub > 0) {
332
+ PyObject *SubList = PyCreateList(group->gBench, SUBTRACTION);
333
+ PyDict_SetItemString(dict, "Sub", SubList);
334
+ Py_DECREF(SubList);
335
+ }
336
+
337
+ if(group->dBench->op_exp > 0) {
338
+ PyObject *ExpList = PyCreateList(group->gBench, EXPONENTIATION);
339
+ PyDict_SetItemString(dict, "Exp", ExpList);
340
+ Py_DECREF(ExpList);
341
+ }
342
+ //PrintPyRef('MulList After =>', MulList);
343
+ }
344
+ else if(group->dBench->bench_inprogress == TRUE) {
345
+ printf("Benchmark in progress.\n");
346
+ }
347
+ else {
348
+ PyErr_SetString(BENCH_ERROR, "uninitialized benchmark object.");
349
+ }
350
+
351
+ return dict;
352
+ }
353
+