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.
- charm/__init__.py +5 -0
- charm/adapters/__init__.py +0 -0
- charm/adapters/abenc_adapt_hybrid.py +90 -0
- charm/adapters/dabenc_adapt_hybrid.py +145 -0
- charm/adapters/ibenc_adapt_hybrid.py +72 -0
- charm/adapters/ibenc_adapt_identityhash.py +80 -0
- charm/adapters/kpabenc_adapt_hybrid.py +91 -0
- charm/adapters/pkenc_adapt_bchk05.py +121 -0
- charm/adapters/pkenc_adapt_chk04.py +91 -0
- charm/adapters/pkenc_adapt_hybrid.py +98 -0
- charm/adapters/pksig_adapt_naor01.py +89 -0
- charm/config.py +7 -0
- charm/core/__init__.py +0 -0
- charm/core/benchmark/benchmark_util.c +353 -0
- charm/core/benchmark/benchmark_util.h +61 -0
- charm/core/benchmark/benchmarkmodule.c +476 -0
- charm/core/benchmark/benchmarkmodule.h +162 -0
- charm/core/benchmark.cpython-313-darwin.so +0 -0
- charm/core/crypto/AES/AES.c +1464 -0
- charm/core/crypto/AES.cpython-313-darwin.so +0 -0
- charm/core/crypto/DES/DES.c +113 -0
- charm/core/crypto/DES.cpython-313-darwin.so +0 -0
- charm/core/crypto/DES3/DES3.c +26 -0
- charm/core/crypto/DES3.cpython-313-darwin.so +0 -0
- charm/core/crypto/__init__.py +0 -0
- charm/core/crypto/cryptobase/XOR.c +80 -0
- charm/core/crypto/cryptobase/_counter.c +496 -0
- charm/core/crypto/cryptobase/_counter.h +54 -0
- charm/core/crypto/cryptobase/block_template.c +900 -0
- charm/core/crypto/cryptobase/block_template.h +69 -0
- charm/core/crypto/cryptobase/cryptobasemodule.c +220 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt.h +90 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_argchk.h +44 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_cfg.h +186 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_cipher.h +941 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_custom.h +556 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_des.c +1912 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_hash.h +407 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_mac.h +496 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_macros.h +435 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_math.h +534 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_misc.h +103 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_pk.h +653 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_pkcs.h +90 -0
- charm/core/crypto/cryptobase/libtom/tomcrypt_prng.h +199 -0
- charm/core/crypto/cryptobase/stream_template.c +271 -0
- charm/core/crypto/cryptobase/strxor.c +229 -0
- charm/core/crypto/cryptobase.cpython-313-darwin.so +0 -0
- charm/core/engine/__init__.py +5 -0
- charm/core/engine/protocol.py +293 -0
- charm/core/engine/util.py +174 -0
- charm/core/math/__init__.py +0 -0
- charm/core/math/elliptic_curve/ecmodule.c +1986 -0
- charm/core/math/elliptic_curve/ecmodule.h +230 -0
- charm/core/math/elliptic_curve.cpython-313-darwin.so +0 -0
- charm/core/math/elliptic_curve.pyi +63 -0
- charm/core/math/integer/integermodule.c +2539 -0
- charm/core/math/integer/integermodule.h +145 -0
- charm/core/math/integer.cpython-313-darwin.so +0 -0
- charm/core/math/integer.pyi +76 -0
- charm/core/math/pairing/miracl/miracl_config.h +37 -0
- charm/core/math/pairing/miracl/miracl_interface.h +118 -0
- charm/core/math/pairing/miracl/miracl_interface2.h +126 -0
- charm/core/math/pairing/miracl/pairingmodule2.c +2094 -0
- charm/core/math/pairing/miracl/pairingmodule2.h +307 -0
- charm/core/math/pairing/pairingmodule.c +2230 -0
- charm/core/math/pairing/pairingmodule.h +241 -0
- charm/core/math/pairing/relic/pairingmodule3.c +1853 -0
- charm/core/math/pairing/relic/pairingmodule3.h +233 -0
- charm/core/math/pairing/relic/relic_interface.c +1337 -0
- charm/core/math/pairing/relic/relic_interface.h +217 -0
- charm/core/math/pairing/relic/test_relic.c +171 -0
- charm/core/math/pairing.cpython-313-darwin.so +0 -0
- charm/core/math/pairing.pyi +69 -0
- charm/core/utilities/base64.c +248 -0
- charm/core/utilities/base64.h +15 -0
- charm/schemes/__init__.py +0 -0
- charm/schemes/abenc/__init__.py +0 -0
- charm/schemes/abenc/abenc_accountability_jyjxgd20.py +647 -0
- charm/schemes/abenc/abenc_bsw07.py +146 -0
- charm/schemes/abenc/abenc_ca_cpabe_ar17.py +684 -0
- charm/schemes/abenc/abenc_dacmacs_yj14.py +298 -0
- charm/schemes/abenc/abenc_lsw08.py +159 -0
- charm/schemes/abenc/abenc_maabe_rw15.py +236 -0
- charm/schemes/abenc/abenc_maabe_yj14.py +297 -0
- charm/schemes/abenc/abenc_tbpre_lww14.py +309 -0
- charm/schemes/abenc/abenc_unmcpabe_yahk14.py +223 -0
- charm/schemes/abenc/abenc_waters09.py +144 -0
- charm/schemes/abenc/abenc_yct14.py +208 -0
- charm/schemes/abenc/abenc_yllc15.py +178 -0
- charm/schemes/abenc/ac17.py +248 -0
- charm/schemes/abenc/bsw07.py +141 -0
- charm/schemes/abenc/cgw15.py +277 -0
- charm/schemes/abenc/dabe_aw11.py +204 -0
- charm/schemes/abenc/dfa_fe12.py +144 -0
- charm/schemes/abenc/pk_hve08.py +179 -0
- charm/schemes/abenc/waters11.py +143 -0
- charm/schemes/aggrsign_MuSig.py +150 -0
- charm/schemes/aggrsign_bls.py +267 -0
- charm/schemes/blindsig_ps16.py +654 -0
- charm/schemes/chamhash_adm05.py +113 -0
- charm/schemes/chamhash_rsa_hw09.py +100 -0
- charm/schemes/commit/__init__.py +0 -0
- charm/schemes/commit/commit_gs08.py +77 -0
- charm/schemes/commit/commit_pedersen92.py +53 -0
- charm/schemes/encap_bchk05.py +62 -0
- charm/schemes/grpsig/__init__.py +0 -0
- charm/schemes/grpsig/groupsig_bgls04.py +114 -0
- charm/schemes/grpsig/groupsig_bgls04_var.py +115 -0
- charm/schemes/hibenc/__init__.py +0 -0
- charm/schemes/hibenc/hibenc_bb04.py +105 -0
- charm/schemes/hibenc/hibenc_lew11.py +193 -0
- charm/schemes/ibenc/__init__.py +0 -0
- charm/schemes/ibenc/clpkc_rp03.py +119 -0
- charm/schemes/ibenc/ibenc_CW13_z.py +168 -0
- charm/schemes/ibenc/ibenc_bb03.py +94 -0
- charm/schemes/ibenc/ibenc_bf01.py +121 -0
- charm/schemes/ibenc/ibenc_ckrs09.py +120 -0
- charm/schemes/ibenc/ibenc_cllww12_z.py +172 -0
- charm/schemes/ibenc/ibenc_lsw08.py +120 -0
- charm/schemes/ibenc/ibenc_sw05.py +238 -0
- charm/schemes/ibenc/ibenc_waters05.py +144 -0
- charm/schemes/ibenc/ibenc_waters05_z.py +164 -0
- charm/schemes/ibenc/ibenc_waters09.py +107 -0
- charm/schemes/ibenc/ibenc_waters09_z.py +147 -0
- charm/schemes/joye_scheme.py +106 -0
- charm/schemes/lem_scheme.py +207 -0
- charm/schemes/pk_fre_ccv11.py +107 -0
- charm/schemes/pk_vrf.py +127 -0
- charm/schemes/pkenc/__init__.py +0 -0
- charm/schemes/pkenc/pkenc_cs98.py +108 -0
- charm/schemes/pkenc/pkenc_elgamal85.py +122 -0
- charm/schemes/pkenc/pkenc_gm82.py +98 -0
- charm/schemes/pkenc/pkenc_paillier99.py +118 -0
- charm/schemes/pkenc/pkenc_rabin.py +254 -0
- charm/schemes/pkenc/pkenc_rsa.py +186 -0
- charm/schemes/pksig/__init__.py +0 -0
- charm/schemes/pksig/pksig_CW13_z.py +135 -0
- charm/schemes/pksig/pksig_bls04.py +87 -0
- charm/schemes/pksig/pksig_boyen.py +156 -0
- charm/schemes/pksig/pksig_chch.py +97 -0
- charm/schemes/pksig/pksig_chp.py +70 -0
- charm/schemes/pksig/pksig_cl03.py +150 -0
- charm/schemes/pksig/pksig_cl04.py +87 -0
- charm/schemes/pksig/pksig_cllww12_z.py +142 -0
- charm/schemes/pksig/pksig_cyh.py +132 -0
- charm/schemes/pksig/pksig_dsa.py +76 -0
- charm/schemes/pksig/pksig_ecdsa.py +71 -0
- charm/schemes/pksig/pksig_hess.py +104 -0
- charm/schemes/pksig/pksig_hw.py +110 -0
- charm/schemes/pksig/pksig_lamport.py +63 -0
- charm/schemes/pksig/pksig_ps01.py +135 -0
- charm/schemes/pksig/pksig_ps02.py +124 -0
- charm/schemes/pksig/pksig_ps03.py +119 -0
- charm/schemes/pksig/pksig_rsa_hw09.py +206 -0
- charm/schemes/pksig/pksig_schnorr91.py +77 -0
- charm/schemes/pksig/pksig_waters.py +115 -0
- charm/schemes/pksig/pksig_waters05.py +121 -0
- charm/schemes/pksig/pksig_waters09.py +121 -0
- charm/schemes/pre_mg07.py +150 -0
- charm/schemes/prenc/pre_afgh06.py +126 -0
- charm/schemes/prenc/pre_bbs98.py +123 -0
- charm/schemes/prenc/pre_nal16.py +216 -0
- charm/schemes/protocol_a01.py +272 -0
- charm/schemes/protocol_ao00.py +215 -0
- charm/schemes/protocol_cns07.py +274 -0
- charm/schemes/protocol_schnorr91.py +125 -0
- charm/schemes/sigma1.py +64 -0
- charm/schemes/sigma2.py +129 -0
- charm/schemes/sigma3.py +126 -0
- charm/schemes/threshold/__init__.py +59 -0
- charm/schemes/threshold/dkls23_dkg.py +556 -0
- charm/schemes/threshold/dkls23_presign.py +1089 -0
- charm/schemes/threshold/dkls23_sign.py +761 -0
- charm/schemes/threshold/xrpl_wallet.py +967 -0
- charm/test/__init__.py +0 -0
- charm/test/adapters/__init__.py +0 -0
- charm/test/adapters/abenc_adapt_hybrid_test.py +29 -0
- charm/test/adapters/dabenc_adapt_hybrid_test.py +56 -0
- charm/test/adapters/ibenc_adapt_hybrid_test.py +36 -0
- charm/test/adapters/ibenc_adapt_identityhash_test.py +32 -0
- charm/test/adapters/kpabenc_adapt_hybrid_test.py +30 -0
- charm/test/benchmark/abenc_yllc15_bench.py +92 -0
- charm/test/benchmark/benchmark_test.py +148 -0
- charm/test/benchmark_threshold.py +260 -0
- charm/test/conftest.py +38 -0
- charm/test/fuzz/__init__.py +1 -0
- charm/test/fuzz/conftest.py +5 -0
- charm/test/fuzz/fuzz_policy_parser.py +76 -0
- charm/test/fuzz/fuzz_serialization.py +83 -0
- charm/test/schemes/__init__.py +0 -0
- charm/test/schemes/abenc/__init__.py +0 -0
- charm/test/schemes/abenc/abenc_bsw07_test.py +39 -0
- charm/test/schemes/abenc/abenc_dacmacs_yj14_test.py +16 -0
- charm/test/schemes/abenc/abenc_lsw08_test.py +33 -0
- charm/test/schemes/abenc/abenc_maabe_yj14_test.py +16 -0
- charm/test/schemes/abenc/abenc_tbpre_lww14_test.py +16 -0
- charm/test/schemes/abenc/abenc_waters09_test.py +38 -0
- charm/test/schemes/abenc/abenc_yllc15_test.py +74 -0
- charm/test/schemes/chamhash_adm05_test.py +31 -0
- charm/test/schemes/chamhash_rsa_hw09_test.py +29 -0
- charm/test/schemes/commit/__init__.py +0 -0
- charm/test/schemes/commit/commit_gs08_test.py +24 -0
- charm/test/schemes/commit/commit_pedersen92_test.py +26 -0
- charm/test/schemes/dabe_aw11_test.py +45 -0
- charm/test/schemes/encap_bchk05_test.py +21 -0
- charm/test/schemes/grpsig/__init__.py +0 -0
- charm/test/schemes/grpsig/groupsig_bgls04_test.py +35 -0
- charm/test/schemes/grpsig/groupsig_bgls04_var_test.py +39 -0
- charm/test/schemes/hibenc/__init__.py +0 -0
- charm/test/schemes/hibenc/hibenc_bb04_test.py +28 -0
- charm/test/schemes/ibenc/__init__.py +0 -0
- charm/test/schemes/ibenc/ibenc_bb03_test.py +26 -0
- charm/test/schemes/ibenc/ibenc_bf01_test.py +24 -0
- charm/test/schemes/ibenc/ibenc_ckrs09_test.py +25 -0
- charm/test/schemes/ibenc/ibenc_lsw08_test.py +31 -0
- charm/test/schemes/ibenc/ibenc_sw05_test.py +32 -0
- charm/test/schemes/ibenc/ibenc_waters05_test.py +31 -0
- charm/test/schemes/ibenc/ibenc_waters09_test.py +27 -0
- charm/test/schemes/pk_vrf_test.py +29 -0
- charm/test/schemes/pkenc/__init__.py +0 -0
- charm/test/schemes/pkenc_test.py +255 -0
- charm/test/schemes/pksig/__init__.py +0 -0
- charm/test/schemes/pksig_test.py +376 -0
- charm/test/schemes/rsa_alg_test.py +340 -0
- charm/test/schemes/threshold_test.py +1792 -0
- charm/test/serialize/__init__.py +0 -0
- charm/test/serialize/serialize_test.py +40 -0
- charm/test/toolbox/__init__.py +0 -0
- charm/test/toolbox/conversion_test.py +30 -0
- charm/test/toolbox/ecgroup_test.py +53 -0
- charm/test/toolbox/integer_arithmetic_test.py +441 -0
- charm/test/toolbox/paddingschemes_test.py +238 -0
- charm/test/toolbox/policy_parser_stress_test.py +969 -0
- charm/test/toolbox/secretshare_test.py +28 -0
- charm/test/toolbox/symcrypto_test.py +108 -0
- charm/test/toolbox/test_policy_expression.py +16 -0
- charm/test/vectors/__init__.py +1 -0
- charm/test/vectors/test_bls_vectors.py +289 -0
- charm/test/vectors/test_pedersen_vectors.py +315 -0
- charm/test/vectors/test_schnorr_vectors.py +368 -0
- charm/test/zkp_compiler/__init__.py +9 -0
- charm/test/zkp_compiler/benchmark_zkp.py +258 -0
- charm/test/zkp_compiler/test_and_proof.py +240 -0
- charm/test/zkp_compiler/test_batch_verify.py +248 -0
- charm/test/zkp_compiler/test_dleq_proof.py +264 -0
- charm/test/zkp_compiler/test_or_proof.py +231 -0
- charm/test/zkp_compiler/test_proof_serialization.py +121 -0
- charm/test/zkp_compiler/test_range_proof.py +241 -0
- charm/test/zkp_compiler/test_representation_proof.py +325 -0
- charm/test/zkp_compiler/test_schnorr_proof.py +221 -0
- charm/test/zkp_compiler/test_thread_safety.py +169 -0
- charm/test/zkp_compiler/test_zkp_parser.py +139 -0
- charm/toolbox/ABEnc.py +26 -0
- charm/toolbox/ABEncMultiAuth.py +66 -0
- charm/toolbox/ABEnumeric.py +800 -0
- charm/toolbox/Commit.py +24 -0
- charm/toolbox/DFA.py +89 -0
- charm/toolbox/FSA.py +1254 -0
- charm/toolbox/Hash.py +39 -0
- charm/toolbox/IBEnc.py +62 -0
- charm/toolbox/IBSig.py +64 -0
- charm/toolbox/PKEnc.py +66 -0
- charm/toolbox/PKSig.py +56 -0
- charm/toolbox/PREnc.py +32 -0
- charm/toolbox/ZKProof.py +289 -0
- charm/toolbox/__init__.py +0 -0
- charm/toolbox/bitstring.py +49 -0
- charm/toolbox/broadcast.py +220 -0
- charm/toolbox/conversion.py +100 -0
- charm/toolbox/eccurve.py +149 -0
- charm/toolbox/ecgroup.py +143 -0
- charm/toolbox/enum.py +60 -0
- charm/toolbox/hash_module.py +91 -0
- charm/toolbox/integergroup.py +323 -0
- charm/toolbox/iterate.py +22 -0
- charm/toolbox/matrixops.py +76 -0
- charm/toolbox/mpc_utils.py +296 -0
- charm/toolbox/msp.py +175 -0
- charm/toolbox/mta.py +985 -0
- charm/toolbox/node.py +120 -0
- charm/toolbox/ot/__init__.py +22 -0
- charm/toolbox/ot/base_ot.py +374 -0
- charm/toolbox/ot/dpf.py +642 -0
- charm/toolbox/ot/mpfss.py +228 -0
- charm/toolbox/ot/ot_extension.py +589 -0
- charm/toolbox/ot/silent_ot.py +378 -0
- charm/toolbox/paddingschemes.py +423 -0
- charm/toolbox/paddingschemes_test.py +238 -0
- charm/toolbox/pairingcurves.py +85 -0
- charm/toolbox/pairinggroup.py +186 -0
- charm/toolbox/policy_expression_spec.py +70 -0
- charm/toolbox/policytree.py +189 -0
- charm/toolbox/reCompiler.py +346 -0
- charm/toolbox/redundancyschemes.py +65 -0
- charm/toolbox/schemebase.py +188 -0
- charm/toolbox/secretshare.py +104 -0
- charm/toolbox/secretutil.py +174 -0
- charm/toolbox/securerandom.py +73 -0
- charm/toolbox/sigmaprotocol.py +46 -0
- charm/toolbox/specialprimes.py +45 -0
- charm/toolbox/symcrypto.py +279 -0
- charm/toolbox/threshold_sharing.py +553 -0
- charm/toolbox/xmlserialize.py +94 -0
- charm/toolbox/zknode.py +105 -0
- charm/zkp_compiler/__init__.py +89 -0
- charm/zkp_compiler/and_proof.py +460 -0
- charm/zkp_compiler/batch_verify.py +324 -0
- charm/zkp_compiler/dleq_proof.py +423 -0
- charm/zkp_compiler/or_proof.py +305 -0
- charm/zkp_compiler/range_proof.py +417 -0
- charm/zkp_compiler/representation_proof.py +466 -0
- charm/zkp_compiler/schnorr_proof.py +273 -0
- charm/zkp_compiler/thread_safe.py +150 -0
- charm/zkp_compiler/zk_demo.py +489 -0
- charm/zkp_compiler/zkp_factory.py +330 -0
- charm/zkp_compiler/zkp_generator.py +370 -0
- charm/zkp_compiler/zkparser.py +269 -0
- charm_crypto_framework-0.61.1.dist-info/METADATA +337 -0
- charm_crypto_framework-0.61.1.dist-info/RECORD +323 -0
- charm_crypto_framework-0.61.1.dist-info/WHEEL +5 -0
- charm_crypto_framework-0.61.1.dist-info/licenses/LICENSE.txt +165 -0
- 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
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
|
+
|