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,85 @@
|
|
|
1
|
+
from charm.config import libs, pairing_lib
|
|
2
|
+
|
|
3
|
+
a = """type a
|
|
4
|
+
q 8780710799663312522437781984754049815806883199414208211028653399266475630880222957078625179422662221423155858769582317459277713367317481324925129998224791
|
|
5
|
+
h 12016012264891146079388821366740534204802954401251311822919615131047207289359704531102844802183906537786776
|
|
6
|
+
r 730750818665451621361119245571504901405976559617
|
|
7
|
+
exp2 159
|
|
8
|
+
exp1 107
|
|
9
|
+
sign1 1
|
|
10
|
+
sign0 1"""
|
|
11
|
+
|
|
12
|
+
a1 = """type a1
|
|
13
|
+
p 48512875896303752499712277254589628516419352188294521198189567511009073158115045361294839347099315898960045398524682007334164928531594799149100548036445760110913157420655690361891290858441360807158247259460501343449199712532828063940008683740048500980441989713739689655610578458388126934242630557397618776539259
|
|
14
|
+
n 36203638728584889925158415861634051131656232976339194924022065306723188923966451762160327870969638730567198058600508960697138006366861790409776528385407283664860565239295291314844246909284597617282274074224254733917313218308080644731349763985110821627195514711746037056425804819692632040479575042834043863089
|
|
15
|
+
l 1340
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
d159 = """type d
|
|
19
|
+
q 625852803282871856053922297323874661378036491717
|
|
20
|
+
n 625852803282871856053923088432465995634661283063
|
|
21
|
+
h 3
|
|
22
|
+
r 208617601094290618684641029477488665211553761021
|
|
23
|
+
a 581595782028432961150765424293919699975513269268
|
|
24
|
+
b 517921465817243828776542439081147840953753552322
|
|
25
|
+
k 6
|
|
26
|
+
nk 60094290356408407130984161127310078516360031868417968262992864809623507269833854678414046779817844853757026858774966331434198257512457993293271849043664655146443229029069463392046837830267994222789160047337432075266619082657640364986415435746294498140589844832666082434658532589211525696
|
|
27
|
+
hk 1380801711862212484403205699005242141541629761433899149236405232528956996854655261075303661691995273080620762287276051361446528504633283152278831183711301329765591450680250000592437612973269056
|
|
28
|
+
coeff0 472731500571015189154958232321864199355792223347
|
|
29
|
+
coeff1 352243926696145937581894994871017455453604730246
|
|
30
|
+
coeff2 289113341693870057212775990719504267185772707305
|
|
31
|
+
nqr 431211441436589568382088865288592347194866189652
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
d201 = """type d
|
|
35
|
+
q 2094476214847295281570670320144695883131009753607350517892357
|
|
36
|
+
n 2094476214847295281570670320143248652598286201895740019876423
|
|
37
|
+
h 1122591
|
|
38
|
+
r 1865751832009427548920907365321162072917283500309320153
|
|
39
|
+
a 9937051644888803031325524114144300859517912378923477935510
|
|
40
|
+
b 6624701096592535354217016076096200573011941585948985290340
|
|
41
|
+
k 6
|
|
42
|
+
nk 84421409121513221644716967251498543569964760150943970280296295496165154657097987617093928595467244393873913569302597521196137376192587250931727762632568620562823714441576400096248911214941742242106512149305076320555351603145285797909942596124862593877499051211952936404822228308154770272833273836975042632765377879565229109013234552083886934379264203243445590336
|
|
43
|
+
hk 24251848326363771171270027814768648115136299306034875585195931346818912374815385257266068811350396365799298585287746735681314613260560203359251331805443378322987677594618057568388400134442772232086258797844238238645130212769322779762522643806720212266304
|
|
44
|
+
coeff0 362345194706722765382504711221797122584657971082977778415831
|
|
45
|
+
coeff1 856577648996637037517940613304411075703495574379408261091623
|
|
46
|
+
coeff2 372728063705230489408480761157081724912117414311754674153886
|
|
47
|
+
nqr 279252656555925299126768437760706333663688384547737180929542
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
d224 = """type d
|
|
51
|
+
q 15028799613985034465755506450771565229282832217860390155996483840017
|
|
52
|
+
n 15028799613985034465755506450771561352583254744125520639296541195021
|
|
53
|
+
h 1
|
|
54
|
+
r 15028799613985034465755506450771561352583254744125520639296541195021
|
|
55
|
+
a 1871224163624666631860092489128939059944978347142292177323825642096
|
|
56
|
+
b 9795501723343380547144152006776653149306466138012730640114125605701
|
|
57
|
+
k 6
|
|
58
|
+
nk 11522474695025217370062603013790980334538096429455689114222024912184432319228393204650383661781864806076247259556378350541669994344878430136202714945761488385890619925553457668158504202786580559970945936657636855346713598888067516214634859330554634505767198415857150479345944721710356274047707536156296215573412763735135600953865419000398920292535215757291539307525639675204597938919504807427238735811520
|
|
59
|
+
hk 51014915936684265604900487195256160848193571244274648855332475661658304506316301006112887177277345010864012988127829655449256424871024500368597989462373813062189274150916552689262852603254011248502356041206544262755481779137398040376281542938513970473990787064615734720
|
|
60
|
+
coeff0 11975189258259697166257037825227536931446707944682470951111859446192
|
|
61
|
+
coeff1 13433042200347934827742738095249546804006687562088254057411901362771
|
|
62
|
+
coeff2 8327464521117791238079105175448122006759863625508043495770887411614
|
|
63
|
+
nqr 142721363302176037340346936780070353538541593770301992936740616924
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
f254 = """type f
|
|
67
|
+
q 16283262548997601220198008118239886027035269286659395419233331082106632227801
|
|
68
|
+
r 16283262548997601220198008118239886026907663399064043451383740756301306087801
|
|
69
|
+
b 7068387321767010428383604447141585855811153344588123938605766847051945009302
|
|
70
|
+
beta 2144618501819208913782431868481640081004079749439232836584323016583030561512
|
|
71
|
+
alpha0 386316900221926659979169226002672231458011916057040420493277182727499227585
|
|
72
|
+
alpha1 12833444880567801377541563780933054992830992527850214079342609648119124982935
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
# Notes: pbc library parameters : SS means super singular curve with the following digits
|
|
76
|
+
# represents the size of the base field in bits. MNT curves were created by
|
|
77
|
+
# Miyaji, Nakabayashi and Takano. BN curve was created by Barreto and Naehrig
|
|
78
|
+
params = None
|
|
79
|
+
if pairing_lib == libs.pbc:
|
|
80
|
+
params = {'SS512':a, 'SS1024':a1, 'MNT159':d159, 'MNT201':d201, 'MNT224':d224, 'BN254':f254 }
|
|
81
|
+
elif pairing_lib == libs.miracl:
|
|
82
|
+
params = {'MNT160':80, 'BN256':128, 'SS512':80, 'SS1536':128}
|
|
83
|
+
elif pairing_lib == libs.relic:
|
|
84
|
+
params = {'BN158':0, 'BN254':1, 'BN256':2}
|
|
85
|
+
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
try:
|
|
2
|
+
from charm.toolbox.pairingcurves import params as param_info
|
|
3
|
+
from charm.core.math.pairing import pairing,pc_element,ZR,G1,G2,GT,init,pair,hashPair,H,random,serialize,deserialize,ismember,order
|
|
4
|
+
import charm.core.math.pairing as pg
|
|
5
|
+
from charm.config import libs,pairing_lib
|
|
6
|
+
except Exception as err:
|
|
7
|
+
raise ImportError("Cannot import pairing module. Ensure Charm crypto C extensions are compiled: %s" % err)
|
|
8
|
+
|
|
9
|
+
class PairingGroup():
|
|
10
|
+
def __init__(self, param_id, param_file = False, secparam = 512, verbose = False, seed1 = None, seed2 = None):
|
|
11
|
+
#legacy handler to handle calls that still pass in a file path
|
|
12
|
+
if param_file:
|
|
13
|
+
self.Pairing = pairing(file=param_id)
|
|
14
|
+
elif type(param_id) == str:
|
|
15
|
+
pairID = param_info.get(param_id)
|
|
16
|
+
assert pairID != None, "'%s' not recognized! See 'pairingcurves.py' in toolbox." % param_id
|
|
17
|
+
if pairing_lib == libs.pbc:
|
|
18
|
+
self.Pairing = pairing(string=pairID)
|
|
19
|
+
self.param = param_id
|
|
20
|
+
elif pairing_lib in [libs.miracl, libs.relic]:
|
|
21
|
+
self.Pairing = pairing(pairID)
|
|
22
|
+
self.param = pairID
|
|
23
|
+
elif type(param_id) == int:
|
|
24
|
+
self.Pairing = pairing(param_id)
|
|
25
|
+
self.param = param_id
|
|
26
|
+
|
|
27
|
+
""" the secure parameter $\\lambda$ should be a positive integer; otherwise, it may lead to computation errors in getting the message size """
|
|
28
|
+
assert isinstance(secparam, int) and secparam >= 1, "The security parameter $\\lambda$ should be a positive integer. "
|
|
29
|
+
|
|
30
|
+
self.secparam = secparam # number of bits
|
|
31
|
+
self._verbose = verbose
|
|
32
|
+
self.__gt = pair(self.random(G1, seed = seed1), self.random(G2, seed = seed2))
|
|
33
|
+
|
|
34
|
+
def __str__(self):
|
|
35
|
+
return str(self.Pairing)
|
|
36
|
+
|
|
37
|
+
def order(self):
|
|
38
|
+
"""returns the order of the group"""
|
|
39
|
+
return order(self.Pairing)
|
|
40
|
+
|
|
41
|
+
def paramgen(self, qbits, rbits):
|
|
42
|
+
return None
|
|
43
|
+
|
|
44
|
+
def ismember(self, obj):
|
|
45
|
+
"""membership test for a pairing object"""
|
|
46
|
+
return ismember(self.Pairing, obj)
|
|
47
|
+
|
|
48
|
+
def ismemberList(self, obj):
|
|
49
|
+
"""membership test for a list of pairing objects"""
|
|
50
|
+
for i in range(len(obj)):
|
|
51
|
+
if ismember(self.Pairing, obj[i]) == False: return False
|
|
52
|
+
return True
|
|
53
|
+
|
|
54
|
+
def ismemberDict(self, obj):
|
|
55
|
+
"""membership test for a dict of pairing objects"""
|
|
56
|
+
for i in obj.keys():
|
|
57
|
+
if ismember(self.Pairing, obj[i]) == False: return False
|
|
58
|
+
return True
|
|
59
|
+
|
|
60
|
+
def groupSetting(self):
|
|
61
|
+
return 'pairing'
|
|
62
|
+
|
|
63
|
+
def groupType(self):
|
|
64
|
+
return self.param
|
|
65
|
+
|
|
66
|
+
def messageSize(self):
|
|
67
|
+
""" after filling complete bytes with every 8 bits, any remaining 1, 2, ..., 7 more bits will occupy an additional byte, even if they do not form a complete byte """
|
|
68
|
+
return (self.secparam + 7) >> 3
|
|
69
|
+
|
|
70
|
+
def init(self, type, value=None):
|
|
71
|
+
"""initializes an object with a specified type and value"""
|
|
72
|
+
if value != None:
|
|
73
|
+
return init(self.Pairing, type, value)
|
|
74
|
+
return init(self.Pairing, type)
|
|
75
|
+
|
|
76
|
+
def random(self, _type = ZR, count = 1, seed = None):
|
|
77
|
+
"""selects one or more random elements in ZR, G1, G2 and GT"""
|
|
78
|
+
if _type == GT:
|
|
79
|
+
if 1 == count:
|
|
80
|
+
return self.__gt ** (random(self.Pairing, ZR) if seed is None else random(self.Pairing, ZR, seed))
|
|
81
|
+
elif count >= 2:
|
|
82
|
+
return tuple(self.__gt ** random(self.Pairing, ZR) for _ in range(count))
|
|
83
|
+
elif _type in (ZR, G1, G2):
|
|
84
|
+
if 1 == count:
|
|
85
|
+
return random(self.Pairing, _type) if seed is None else random(self.Pairing, _type, seed)
|
|
86
|
+
elif count >= 2:
|
|
87
|
+
return tuple(random(self.Pairing, _type) for _ in range(count))
|
|
88
|
+
else:
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
def encode(self, message):
|
|
92
|
+
raise NotImplementedException
|
|
93
|
+
|
|
94
|
+
def decode(self, element):
|
|
95
|
+
raise NotImplementedException
|
|
96
|
+
|
|
97
|
+
def hash(self, args, type=ZR):
|
|
98
|
+
"""hashes objects into ZR, G1 or G2 depending on the pairing curve"""
|
|
99
|
+
return H(self.Pairing, args, type)
|
|
100
|
+
|
|
101
|
+
def serialize(self, obj, compression=True):
|
|
102
|
+
"""Serialize a pairing object into bytes.
|
|
103
|
+
|
|
104
|
+
:param compression: serialize the compressed representation of the
|
|
105
|
+
curve element, taking about half the space but potentially
|
|
106
|
+
incurring in non-negligible computation costs when
|
|
107
|
+
deserializing. Default is True for compatibility with previous
|
|
108
|
+
versions of charm.
|
|
109
|
+
|
|
110
|
+
>>> p = PairingGroup('SS512')
|
|
111
|
+
>>> v1 = p.random(G1)
|
|
112
|
+
>>> b1 = p.serialize(v1)
|
|
113
|
+
>>> b1 == p.serialize(v1, compression=True)
|
|
114
|
+
True
|
|
115
|
+
>>> v1 == p.deserialize(b1)
|
|
116
|
+
True
|
|
117
|
+
>>> b1 = p.serialize(v1, compression=False)
|
|
118
|
+
>>> v1 == p.deserialize(b1, compression=False)
|
|
119
|
+
True
|
|
120
|
+
"""
|
|
121
|
+
return serialize(obj, compression)
|
|
122
|
+
|
|
123
|
+
def deserialize(self, obj, compression=True):
|
|
124
|
+
"""Deserialize a bytes serialized element into a pairing object.
|
|
125
|
+
|
|
126
|
+
:param compression: must be used for objects serialized with the
|
|
127
|
+
compression parameter set to True. Default is True for
|
|
128
|
+
compatibility with previous versions of charm.
|
|
129
|
+
"""
|
|
130
|
+
return deserialize(self.Pairing, obj, compression)
|
|
131
|
+
|
|
132
|
+
def debug(self, data, prefix=None):
|
|
133
|
+
if not self._verbose:
|
|
134
|
+
return
|
|
135
|
+
if type(data) == dict:
|
|
136
|
+
for k,v in data.items():
|
|
137
|
+
print(k,v)
|
|
138
|
+
elif type(data) == list:
|
|
139
|
+
for i in range(0, len(data)):
|
|
140
|
+
print(prefix, (i+1),':',data[i])
|
|
141
|
+
print('')
|
|
142
|
+
elif type(data) == str:
|
|
143
|
+
print(data)
|
|
144
|
+
else:
|
|
145
|
+
print(type(data), ':', data)
|
|
146
|
+
return
|
|
147
|
+
|
|
148
|
+
def pair_prod(self, lhs, rhs):
|
|
149
|
+
"""takes two lists of G1 & G2 and computes a pairing product"""
|
|
150
|
+
return pair(lhs, rhs, self.Pairing)
|
|
151
|
+
|
|
152
|
+
def InitBenchmark(self):
|
|
153
|
+
"""initiates the benchmark state"""
|
|
154
|
+
return pg.InitBenchmark(self.Pairing)
|
|
155
|
+
|
|
156
|
+
def StartBenchmark(self, options):
|
|
157
|
+
"""starts the benchmark with any of these options:
|
|
158
|
+
RealTime, CpuTime, Mul, Div, Add, Sub, Exp, Pair, Granular"""
|
|
159
|
+
return pg.StartBenchmark(self.Pairing, options)
|
|
160
|
+
|
|
161
|
+
def EndBenchmark(self):
|
|
162
|
+
"""ends an ongoing benchmark"""
|
|
163
|
+
return pg.EndBenchmark(self.Pairing)
|
|
164
|
+
|
|
165
|
+
def GetGeneralBenchmarks(self):
|
|
166
|
+
"""retrieves benchmark count for all group operations"""
|
|
167
|
+
return pg.GetGeneralBenchmarks(self.Pairing)
|
|
168
|
+
|
|
169
|
+
def GetGranularBenchmarks(self):
|
|
170
|
+
"""retrieves group operation count per type: ZR, G1, G2, and GT"""
|
|
171
|
+
return pg.GetGranularBenchmarks(self.Pairing)
|
|
172
|
+
|
|
173
|
+
def GetBenchmark(self, option):
|
|
174
|
+
"""retrieves benchmark results for any of these options:
|
|
175
|
+
RealTime, CpuTime, Mul, Div, Add, Sub, Exp, Pair, Granular"""
|
|
176
|
+
return pg.GetBenchmark(self.Pairing, option)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def extract_key(g):
|
|
180
|
+
"""
|
|
181
|
+
Given a group element, extract a symmetric key
|
|
182
|
+
:param g:
|
|
183
|
+
:return:
|
|
184
|
+
"""
|
|
185
|
+
g_in_hex = hashPair(g).decode('utf-8')
|
|
186
|
+
return bytes(bytearray.fromhex(g_in_hex))
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from hypothesis.strategies import text, composite, sampled_from, characters, one_of, integers
|
|
2
|
+
from functools import partial
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def policy_expressions_of_size(policy_expression_strategy, num_leaves):
|
|
6
|
+
if num_leaves == 1:
|
|
7
|
+
return one_of(attributes(), inequalities())
|
|
8
|
+
else:
|
|
9
|
+
return policy_expression_strategy(num_leaves)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@composite
|
|
13
|
+
def monotonic_policy_expression(draw, num_leaves):
|
|
14
|
+
left_leaves = draw(integers(min_value=1, max_value=num_leaves - 1))
|
|
15
|
+
right_leaves = num_leaves - left_leaves
|
|
16
|
+
left = draw(monotonic_policy_expressions_of_size(left_leaves))
|
|
17
|
+
right = draw(monotonic_policy_expressions_of_size(right_leaves))
|
|
18
|
+
gate = draw(gates())
|
|
19
|
+
return u'(' + u' '.join((left, gate, right)) + u')'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@composite
|
|
23
|
+
def alland_policy_expression(draw, num_leaves):
|
|
24
|
+
left_leaves = draw(integers(min_value=1, max_value=num_leaves - 1))
|
|
25
|
+
right_leaves = num_leaves - left_leaves
|
|
26
|
+
left = draw(alland_policy_expressions_of_size(left_leaves))
|
|
27
|
+
right = draw(alland_policy_expressions_of_size(right_leaves))
|
|
28
|
+
gate = draw(and_gates())
|
|
29
|
+
return u'(' + u' '.join((left, gate, right)) + u')'
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
monotonic_policy_expressions_of_size = partial(policy_expressions_of_size, monotonic_policy_expression)
|
|
33
|
+
alland_policy_expressions_of_size = partial(policy_expressions_of_size, alland_policy_expression)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def policy_expressions(min_leaves=1, max_leaves=25):
|
|
37
|
+
return integers(min_leaves, max_leaves).flatmap(monotonic_policy_expressions_of_size)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def alland_policy_expressions(min_leaves=1, max_leaves=25):
|
|
41
|
+
return integers(min_leaves, max_leaves).flatmap(alland_policy_expressions_of_size)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def attributes():
|
|
45
|
+
return text(min_size=1, alphabet=characters(whitelist_categories='L', max_codepoint=0x7e))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@composite
|
|
49
|
+
def inequalities(draw):
|
|
50
|
+
attr = draw(attributes())
|
|
51
|
+
oper = draw(inequality_operators())
|
|
52
|
+
numb = draw(integers(min_value=1))
|
|
53
|
+
return u' '.join((attr, oper, str(numb)))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def inequality_operators():
|
|
57
|
+
return sampled_from((u'<', u'>', u'<=', u'>='))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def gates():
|
|
61
|
+
return sampled_from((u'or', u'and'))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def and_gates():
|
|
65
|
+
return sampled_from((u'and',))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def assert_valid(policy_expression):
|
|
69
|
+
assert policy_expression # not empty
|
|
70
|
+
assert policy_expression.count(u'(') == policy_expression.count(u')')
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
|
|
3
|
+
from pyparsing import *
|
|
4
|
+
from charm.toolbox.node import *
|
|
5
|
+
import string
|
|
6
|
+
|
|
7
|
+
# Compatibility shim for pyparsing 2.x vs 3.x
|
|
8
|
+
# pyparsing 3.0+ uses snake_case (set_parse_action)
|
|
9
|
+
# pyparsing 2.x uses camelCase (setParseAction)
|
|
10
|
+
# This wrapper ensures compatibility with both versions
|
|
11
|
+
def _set_parse_action(parser_element, *fns, **kwargs):
|
|
12
|
+
"""
|
|
13
|
+
Compatibility wrapper for setParseAction/set_parse_action.
|
|
14
|
+
Works with both pyparsing 2.x (camelCase) and 3.x (snake_case).
|
|
15
|
+
"""
|
|
16
|
+
if hasattr(parser_element, 'set_parse_action'):
|
|
17
|
+
# pyparsing 3.x - use modern snake_case method
|
|
18
|
+
return parser_element.set_parse_action(*fns, **kwargs)
|
|
19
|
+
else:
|
|
20
|
+
# pyparsing 2.x - use legacy camelCase method
|
|
21
|
+
return parser_element.setParseAction(*fns, **kwargs)
|
|
22
|
+
|
|
23
|
+
objStack = []
|
|
24
|
+
|
|
25
|
+
def createAttribute(s, loc, toks):
|
|
26
|
+
if toks[0] == '!':
|
|
27
|
+
newtoks = ""
|
|
28
|
+
for i in toks:
|
|
29
|
+
newtoks += i
|
|
30
|
+
return BinNode(newtoks)
|
|
31
|
+
return BinNode(toks[0]) # create
|
|
32
|
+
|
|
33
|
+
# convert 'attr < value' to a binary tree based on 'or' and 'and'
|
|
34
|
+
def parseNumConditional(s, loc, toks):
|
|
35
|
+
print("print: %s" % toks)
|
|
36
|
+
return BinNode(toks[0])
|
|
37
|
+
|
|
38
|
+
def printStuff(s, loc, toks):
|
|
39
|
+
print("print: %s" % toks)
|
|
40
|
+
return toks
|
|
41
|
+
|
|
42
|
+
def pushFirst( s, loc, toks ):
|
|
43
|
+
objStack.append( toks[0] )
|
|
44
|
+
|
|
45
|
+
def createTree(op, node1, node2):
|
|
46
|
+
if(op == "or"):
|
|
47
|
+
node = BinNode(OpType.OR)
|
|
48
|
+
elif(op == "and"):
|
|
49
|
+
node = BinNode(OpType.AND)
|
|
50
|
+
else:
|
|
51
|
+
return None
|
|
52
|
+
node.addSubNode(node1, node2)
|
|
53
|
+
return node
|
|
54
|
+
|
|
55
|
+
def downcaseTokens(s, loc, toks):
|
|
56
|
+
return [t.lower() for t in toks]
|
|
57
|
+
|
|
58
|
+
class PolicyParser:
|
|
59
|
+
def __init__(self, verbose=False):
|
|
60
|
+
self.finalPol = self.getBNF()
|
|
61
|
+
self.verbose = verbose
|
|
62
|
+
|
|
63
|
+
def getBNF(self):
|
|
64
|
+
# supported operators => (OR, AND, <
|
|
65
|
+
OperatorOR = _set_parse_action(Literal("OR"), downcaseTokens) | Literal("or")
|
|
66
|
+
OperatorAND = _set_parse_action(Literal("AND"), downcaseTokens) | Literal("and")
|
|
67
|
+
Operator = OperatorAND | OperatorOR
|
|
68
|
+
lpar = Literal("(").suppress()
|
|
69
|
+
rpar = Literal(")").suppress()
|
|
70
|
+
|
|
71
|
+
BinOperator = Literal("<=") | Literal(">=") | Literal("==") | Word("<>", max=1)
|
|
72
|
+
|
|
73
|
+
# describes an individual leaf node
|
|
74
|
+
leafNode = _set_parse_action(Optional("!") + Word(alphanums+'-_./\\?!@#$^&*%'), createAttribute)
|
|
75
|
+
# describes expressions such as (attr < value)
|
|
76
|
+
leafConditional = _set_parse_action(Word(alphanums) + BinOperator + Word(nums), parseNumConditional)
|
|
77
|
+
|
|
78
|
+
# describes the node concept
|
|
79
|
+
node = leafConditional | leafNode
|
|
80
|
+
|
|
81
|
+
expr = Forward()
|
|
82
|
+
term = Forward()
|
|
83
|
+
atom = lpar + expr + rpar | _set_parse_action(node, pushFirst)
|
|
84
|
+
term = atom + ZeroOrMore(_set_parse_action(Operator + term, pushFirst))
|
|
85
|
+
expr << term + ZeroOrMore(_set_parse_action(Operator + term, pushFirst))
|
|
86
|
+
finalPol = expr # could add: _set_parse_action(expr, printStuff)
|
|
87
|
+
return finalPol
|
|
88
|
+
|
|
89
|
+
def evalStack(self, stack):
|
|
90
|
+
op = stack.pop()
|
|
91
|
+
if op in ["or", "and"]:
|
|
92
|
+
op2 = self.evalStack(stack)
|
|
93
|
+
op1 = self.evalStack(stack)
|
|
94
|
+
return createTree(op, op1, op2)
|
|
95
|
+
else:
|
|
96
|
+
# Node value (attribute)
|
|
97
|
+
return op
|
|
98
|
+
|
|
99
|
+
def parse(self, string):
|
|
100
|
+
global objStack
|
|
101
|
+
del objStack[:]
|
|
102
|
+
# Use parse_string (pyparsing 3.x) or parseString (pyparsing 2.x)
|
|
103
|
+
if hasattr(self.finalPol, 'parse_string'):
|
|
104
|
+
self.finalPol.parse_string(string)
|
|
105
|
+
else:
|
|
106
|
+
self.finalPol.parseString(string)
|
|
107
|
+
return self.evalStack(objStack)
|
|
108
|
+
|
|
109
|
+
def findDuplicates(self, tree, _dict):
|
|
110
|
+
if tree.left: self.findDuplicates(tree.left, _dict)
|
|
111
|
+
if tree.right: self.findDuplicates(tree.right, _dict)
|
|
112
|
+
if tree.getNodeType() == OpType.ATTR:
|
|
113
|
+
key = tree.getAttribute()
|
|
114
|
+
if _dict.get(key) == None: _dict[ key ] = 1
|
|
115
|
+
else: _dict[ key ] += 1
|
|
116
|
+
|
|
117
|
+
def labelDuplicates(self, tree, _dictLabel):
|
|
118
|
+
if tree.left: self.labelDuplicates(tree.left, _dictLabel)
|
|
119
|
+
if tree.right: self.labelDuplicates(tree.right, _dictLabel)
|
|
120
|
+
if tree.getNodeType() == OpType.ATTR:
|
|
121
|
+
key = tree.getAttribute()
|
|
122
|
+
if _dictLabel.get(key) != None:
|
|
123
|
+
tree.index = _dictLabel[ key ]
|
|
124
|
+
_dictLabel[ key ] += 1
|
|
125
|
+
|
|
126
|
+
def prune(self, tree, attributes):
|
|
127
|
+
"""given policy tree and attributes, determine whether the attributes satisfy the policy.
|
|
128
|
+
if not enough attributes to satisfy policy, return None otherwise, a pruned list of
|
|
129
|
+
attributes to potentially recover the associated secret.
|
|
130
|
+
"""
|
|
131
|
+
(policySatisfied, prunedList) = self.requiredAttributes(tree, attributes)
|
|
132
|
+
# print("pruned attrs: ", prunedList)
|
|
133
|
+
# if prunedList:
|
|
134
|
+
# for i in prunedList:
|
|
135
|
+
# print("node: ", i)
|
|
136
|
+
if not policySatisfied:
|
|
137
|
+
return policySatisfied
|
|
138
|
+
return prunedList
|
|
139
|
+
|
|
140
|
+
def requiredAttributes(self, tree, attrList):
|
|
141
|
+
""" determines the required attributes to satisfy policy tree and returns a list of BinNode
|
|
142
|
+
objects."""
|
|
143
|
+
if tree == None: return 0
|
|
144
|
+
Left = tree.getLeft()
|
|
145
|
+
Right = tree.getRight()
|
|
146
|
+
if Left: resultLeft, leftAttr = self.requiredAttributes(Left, attrList)
|
|
147
|
+
if Right: resultRight, rightAttr = self.requiredAttributes(Right, attrList)
|
|
148
|
+
|
|
149
|
+
if(tree.getNodeType() == OpType.OR):
|
|
150
|
+
# never return both attributes, basically the first one that matches from left to right
|
|
151
|
+
if resultLeft: sendThis = leftAttr
|
|
152
|
+
elif resultRight: sendThis = rightAttr
|
|
153
|
+
else: sendThis = None
|
|
154
|
+
|
|
155
|
+
result = (resultLeft or resultRight)
|
|
156
|
+
if result == False: return (False, sendThis)
|
|
157
|
+
return (True, sendThis)
|
|
158
|
+
if(tree.getNodeType() == OpType.AND):
|
|
159
|
+
if resultLeft and resultRight: sendThis = leftAttr + rightAttr
|
|
160
|
+
elif resultLeft: sendThis = leftAttr
|
|
161
|
+
elif resultRight: sendThis = rightAttr
|
|
162
|
+
else: sendThis = None
|
|
163
|
+
|
|
164
|
+
result = (resultLeft and resultRight)
|
|
165
|
+
if result == False: return (False, sendThis)
|
|
166
|
+
return (True, sendThis)
|
|
167
|
+
|
|
168
|
+
elif(tree.getNodeType() == OpType.ATTR):
|
|
169
|
+
if(tree.getAttribute() in attrList):
|
|
170
|
+
return (True, [tree])
|
|
171
|
+
else:
|
|
172
|
+
return (False, None)
|
|
173
|
+
|
|
174
|
+
return
|
|
175
|
+
|
|
176
|
+
if __name__ == "__main__":
|
|
177
|
+
# policy parser test cases
|
|
178
|
+
parser = PolicyParser()
|
|
179
|
+
attrs = ['1', '3']
|
|
180
|
+
print("Attrs in user set: ", attrs)
|
|
181
|
+
tree1 = parser.parse("(1 or 2) and (2 and 3))")
|
|
182
|
+
print("case 1: ", tree1, ", pruned: ", parser.prune(tree1, attrs))
|
|
183
|
+
|
|
184
|
+
tree2 = parser.parse("1 or (2 and 3)")
|
|
185
|
+
print("case 2: ", tree2, ", pruned: ", parser.prune(tree2, attrs))
|
|
186
|
+
|
|
187
|
+
tree3 = parser.parse("(1 or 2) and (4 or 3)")
|
|
188
|
+
print("case 3: ", tree3, ", pruned: ", parser.prune(tree3, attrs))
|
|
189
|
+
|