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,147 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Waters Dual System Encryption - Optimized (Waters09-Z)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Brent Waters
|
|
5
|
+
|
|
6
|
+
| **Title:** "Dual System Encryption: Realizing Fully Secure IBE and HIBE under Simple Assumptions"
|
|
7
|
+
| **Published in:** CRYPTO 2009
|
|
8
|
+
| **Available from:** http://eprint.iacr.org/2009/385.pdf
|
|
9
|
+
| **Notes:** Fully secure IBE construction - optimized for asymmetric groups
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** encryption (identity-based)
|
|
14
|
+
* **Setting:** bilinear groups (asymmetric pairings, MNT curves)
|
|
15
|
+
* **Assumption:** DLIN (Decisional Linear) and related assumptions
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: J. Ayo Akinyele
|
|
20
|
+
:Date: 03/2012
|
|
21
|
+
|
|
22
|
+
:Improved by: Fan Zhang (zfwise@gwu.edu), supported by GWU computer science department
|
|
23
|
+
:Date: 3/2013
|
|
24
|
+
:Notes:
|
|
25
|
+
1. Works with MNT curves (asymmetric pairings).
|
|
26
|
+
2. Elements u, w, h duplicated in both G1 and G2 in public params.
|
|
27
|
+
3. Pre-calculated g2^{-alpha} and g2^b stored in msk for faster keygen.
|
|
28
|
+
4. Minimal size for public params and msk.
|
|
29
|
+
5. extract() takes mpk as additional parameter.
|
|
30
|
+
'''
|
|
31
|
+
from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
|
|
32
|
+
from charm.toolbox.IBEnc import *
|
|
33
|
+
|
|
34
|
+
debug = False
|
|
35
|
+
class DSE09_z(IBEnc):
|
|
36
|
+
"""
|
|
37
|
+
>>> from charm.toolbox.pairinggroup import PairingGroup, GT
|
|
38
|
+
>>> group = PairingGroup('SS512')
|
|
39
|
+
>>> ibe = DSE09_z(group)
|
|
40
|
+
>>> ID = "user2@email.com"
|
|
41
|
+
>>> (master_public_key, master_secret_key) = ibe.setup()
|
|
42
|
+
>>> secret_key = ibe.keygen(master_public_key, master_secret_key, ID)
|
|
43
|
+
>>> msg = group.random(GT)
|
|
44
|
+
>>> cipher_text = ibe.encrypt(master_public_key, msg, ID)
|
|
45
|
+
>>> decrypted_msg = ibe.decrypt(cipher_text, secret_key)
|
|
46
|
+
>>> decrypted_msg == msg
|
|
47
|
+
True
|
|
48
|
+
"""
|
|
49
|
+
def __init__(self, groupObj):
|
|
50
|
+
IBEnc.__init__(self)
|
|
51
|
+
global group, util
|
|
52
|
+
group = groupObj
|
|
53
|
+
|
|
54
|
+
def setup(self):
|
|
55
|
+
g1 = group.random(G1)
|
|
56
|
+
g2 = group.random(G2)
|
|
57
|
+
w_z, u_z, h_z, v_z, v1_z, v2_z = group.random(ZR, 6)
|
|
58
|
+
a1, a2, b, alpha = group.random(ZR, 4)
|
|
59
|
+
|
|
60
|
+
v_G1 = g1 ** v_z
|
|
61
|
+
v1_G1 = g1 ** v1_z
|
|
62
|
+
v2_G1 = g1 ** v2_z
|
|
63
|
+
v_G2 = g2 ** v_z
|
|
64
|
+
v1_G2 = g2 ** v1_z
|
|
65
|
+
v2_G2 = g2 ** v2_z
|
|
66
|
+
w_G1 = g1 ** w_z
|
|
67
|
+
w_G2 = g2 ** w_z
|
|
68
|
+
h_G1 = g1 ** h_z
|
|
69
|
+
h_G2 = g2 ** h_z
|
|
70
|
+
u_G1 = g1 ** u_z
|
|
71
|
+
u_G2 = g2 ** u_z
|
|
72
|
+
|
|
73
|
+
tau1_G1 = v_G1 * (v1_G1 ** a1)
|
|
74
|
+
tau2_G1 = v_G1 * (v2_G1 ** a2)
|
|
75
|
+
mpk = { 'g1':g1, 'g2':g2, 'g1^b':g1 ** b, 'g1^a1':g1 ** a1, 'g1^a2':g1 ** a2,
|
|
76
|
+
'g1^ba1':g1 ** (b * a1), 'g1^ba2':g1 ** (b * a2), 'tau1_G1':tau1_G1,
|
|
77
|
+
'tau2_G1':tau2_G1,'tau1_G1^b':tau1_G1 ** b, 'tau2_G1^b':tau2_G1 ** b,
|
|
78
|
+
'w_G1':w_G1, 'w_G2':w_G2, 'u_G1':u_G1, 'u_G2':u_G2,'h_G1':h_G1, 'h_G2':h_G2,
|
|
79
|
+
'egg_alpha': pair(g1, g2) ** (alpha * a1 * b) }
|
|
80
|
+
msk = { 'g2^alph_a1':g2 ** (alpha * a1), 'g2^b':g2 ** b,
|
|
81
|
+
'v_G2':v_G2, 'v1_G2':v1_G2, 'v2_G2':v2_G2, 'g2^-alpha':g2 ** (-alpha) }
|
|
82
|
+
return (mpk, msk)
|
|
83
|
+
|
|
84
|
+
def keygen(self, mpk, msk, ID):
|
|
85
|
+
r1, r2, z1, z2, tag_k = group.random(ZR, 5)
|
|
86
|
+
r = r1 + r2
|
|
87
|
+
_ID = group.hash(ID)
|
|
88
|
+
D = {}
|
|
89
|
+
D[1] = msk['g2^alph_a1'] * (msk['v_G2'] ** r)
|
|
90
|
+
D[2] = msk['g2^-alpha'] * (msk['v1_G2'] ** r) * (mpk['g2'] ** z1)
|
|
91
|
+
D[3] = msk['g2^b'] ** -z1
|
|
92
|
+
D[4] = (msk['v2_G2'] ** r) * (mpk['g2'] ** z2)
|
|
93
|
+
D[5] = msk['g2^b'] ** -z2
|
|
94
|
+
D[6] = msk['g2^b'] ** r2
|
|
95
|
+
D[7] = mpk['g2'] ** r1
|
|
96
|
+
K = ((mpk['u_G2'] ** _ID) * (mpk['w_G2'] ** tag_k) * mpk['h_G2']) ** r1
|
|
97
|
+
|
|
98
|
+
sk = { 'ID':_ID, 'D':D, 'K':K, 'tag_k':tag_k }
|
|
99
|
+
return sk
|
|
100
|
+
|
|
101
|
+
def encrypt(self, mpk, M, ID):
|
|
102
|
+
s1, s2, t, tag_c = group.random(ZR, 4)
|
|
103
|
+
s = s1 + s2
|
|
104
|
+
_ID = group.hash(ID)
|
|
105
|
+
|
|
106
|
+
C = {}
|
|
107
|
+
C[0] = M * (mpk['egg_alpha'] ** s2)
|
|
108
|
+
C[1] = mpk['g1^b'] ** s
|
|
109
|
+
C[2] = mpk['g1^ba1'] ** s1
|
|
110
|
+
C[3] = mpk['g1^a1'] ** s1
|
|
111
|
+
C[4] = mpk['g1^ba2'] ** s2
|
|
112
|
+
C[5] = mpk['g1^a2'] ** s2
|
|
113
|
+
C[6] = (mpk['tau1_G1'] ** s1) * (mpk['tau2_G1'] ** s2)
|
|
114
|
+
C[7] = (mpk['tau1_G1^b'] ** s1) * (mpk['tau2_G1^b'] ** s2) * (mpk['w_G1'] ** -t)
|
|
115
|
+
|
|
116
|
+
C['E1'] = ((mpk['u_G1'] ** _ID) * (mpk['w_G1'] ** tag_c) * mpk['h_G1']) ** t
|
|
117
|
+
C['E2'] = mpk['g1'] ** t
|
|
118
|
+
C['tag_c'] = tag_c
|
|
119
|
+
return C
|
|
120
|
+
|
|
121
|
+
def decrypt(self, ct, sk):
|
|
122
|
+
tag = (1 / (ct['tag_c'] - sk['tag_k']))
|
|
123
|
+
E1, E2 = ct['E1'], ct['E2']
|
|
124
|
+
C, D, K = ct, sk['D'], sk['K']
|
|
125
|
+
_ID = sk['ID']
|
|
126
|
+
# hash IDs
|
|
127
|
+
A1 = pair(C[1], D[1]) * pair(C[2], D[2]) * pair(C[3], D[3]) * pair(C[4], D[4]) * pair(C[5], D[5])
|
|
128
|
+
A2 = pair(C[6], D[6]) * pair(C[7], D[7])
|
|
129
|
+
A3 = A1 / A2
|
|
130
|
+
A4 = (pair(E1, D[7]) / pair(E2, K)) ** tag
|
|
131
|
+
return C[0] / (A3 / A4)
|
|
132
|
+
|
|
133
|
+
def main():
|
|
134
|
+
group = PairingGroup('MNT224')
|
|
135
|
+
ibe = DSE09_z(group)
|
|
136
|
+
ID = "user2@email.com"
|
|
137
|
+
(master_public_key, master_secret_key) = ibe.setup()
|
|
138
|
+
secret_key = ibe.keygen(master_public_key, master_secret_key, ID)
|
|
139
|
+
msg = group.random(GT)
|
|
140
|
+
cipher_text = ibe.encrypt(master_public_key, msg, ID)
|
|
141
|
+
decrypted_msg = ibe.decrypt(cipher_text, secret_key)
|
|
142
|
+
print(decrypted_msg == msg)
|
|
143
|
+
|
|
144
|
+
if __name__ == "__main__":
|
|
145
|
+
debug = True
|
|
146
|
+
main()
|
|
147
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Privacy-Preserving Aggregation Scheme (JL13)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Marc Joye, Benoit Libert
|
|
5
|
+
|
|
6
|
+
| **Title:** "A Scalable Scheme for Privacy-Preserving Aggregation of Time-Series Data"
|
|
7
|
+
| **Published in:** Financial Crypto 2013
|
|
8
|
+
| **Available from:** http://joye.site88.net/papers/JL13aggreg.pdf
|
|
9
|
+
| **Notes:** Enables plaintext evaluation of sums from encrypted values
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** aggregation (privacy-preserving)
|
|
14
|
+
* **Setting:** integer groups
|
|
15
|
+
* **Assumption:** Paillier
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: Iraklis Leontiadis
|
|
20
|
+
:Date: 12/2013
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
from charm.toolbox.integergroup import RSAGroup
|
|
24
|
+
from charm.schemes.pkenc.pkenc_paillier99 import Pai99
|
|
25
|
+
from charm.toolbox.integergroup import lcm,integer
|
|
26
|
+
from charm.toolbox.PKEnc import PKEnc
|
|
27
|
+
from charm.core.engine.util import *
|
|
28
|
+
|
|
29
|
+
'''
|
|
30
|
+
Test script for two values
|
|
31
|
+
===========================
|
|
32
|
+
group = RSAGroup()
|
|
33
|
+
pai = Pai99(group)
|
|
34
|
+
(public_key, secret_key) = pai.keygen()
|
|
35
|
+
n=public_key['n']
|
|
36
|
+
n2=public_key['n2']
|
|
37
|
+
x1=3 #testing values for user 1
|
|
38
|
+
x2=2 #testing values for user 2
|
|
39
|
+
msg1 = pai.encode(n2, 1+x1*n)
|
|
40
|
+
msg2 = pai.encode(n2, 1+x2*n)
|
|
41
|
+
|
|
42
|
+
prod=pai.encode(n2,msg1*msg2)
|
|
43
|
+
print (integer(prod-integer(1)%n2)/n)
|
|
44
|
+
'''
|
|
45
|
+
class Joye():
|
|
46
|
+
|
|
47
|
+
def __init__(self,users=2):
|
|
48
|
+
global pai,group
|
|
49
|
+
group=RSAGroup()
|
|
50
|
+
pai=Pai99(group)
|
|
51
|
+
self.users=users
|
|
52
|
+
self.r=14 #this value act as the common hash output H(r) according to the protocol.
|
|
53
|
+
|
|
54
|
+
def destruction_keys(self,pk):
|
|
55
|
+
k={}
|
|
56
|
+
for i in range(self.users):
|
|
57
|
+
k['k'+str(i)]=integer(group.random(102))#exponentiation works only for small keys (needs investigation)
|
|
58
|
+
k[0]=integer(-1)*(sum(k.values())) #inverse of the sum of all user keys. Acts as annihilation for keys.
|
|
59
|
+
k[1]=(sum(k.values()))
|
|
60
|
+
#self.ak=integer(1)/integer(self.r)**integer(k[0])
|
|
61
|
+
return k
|
|
62
|
+
|
|
63
|
+
def encrypt(self,x,pk,sk):
|
|
64
|
+
c1=self.encode(x,pk)%pk['n2']
|
|
65
|
+
c2=pai.encode(pk['n2'],integer(self.r%pk['n2'])**integer(sk%pk['n2']))
|
|
66
|
+
cipher=pai.encode(pk['n2'],c1*c2)
|
|
67
|
+
return cipher
|
|
68
|
+
|
|
69
|
+
'''def decrypt(self,c,pk,sk):
|
|
70
|
+
c=pai.encode(pk['n2'],c)
|
|
71
|
+
mul=pai.encode(pk['n2'],integer(self.r)**integer(sk))
|
|
72
|
+
inter=pai.encode(pk['n2'],c*mul)
|
|
73
|
+
result =pai.encode(pk['n'],integer(inter-integer(1)%pk['n2'])/pk['n'])
|
|
74
|
+
return result
|
|
75
|
+
'''
|
|
76
|
+
def keygen(self):
|
|
77
|
+
public_key,secret_key = pai.keygen()
|
|
78
|
+
return public_key
|
|
79
|
+
|
|
80
|
+
def encode(self,x,pk):
|
|
81
|
+
return integer(pai.encode(pk['n2'], 1+integer(x)*pk['n']))
|
|
82
|
+
|
|
83
|
+
def sumfree(self,x1,x2,pk):
|
|
84
|
+
'''Tests sum evaluations without encryption'''
|
|
85
|
+
msg1 = self.encode(x1,pk)
|
|
86
|
+
msg2 = self.encode(x2,pk)
|
|
87
|
+
prod=pai.encode(pk['n2'],msg1*msg2)
|
|
88
|
+
sumres=integer(prod%pk['n2']-integer(1)%pk['n2'])/pk['n']
|
|
89
|
+
return sumres
|
|
90
|
+
|
|
91
|
+
def sum(self,x1,x2,pk,k0):
|
|
92
|
+
prod=pai.encode(pk['n2'],x1*x2)
|
|
93
|
+
inter=pai.encode(pk['n2'],integer(self.r)**integer(integer(-1)*k0))
|
|
94
|
+
inter2=(integer(prod)/integer(inter))
|
|
95
|
+
sumres=integer(inter2%pk['n2']-integer(1)%pk['n2'])/pk['n']
|
|
96
|
+
return sumres
|
|
97
|
+
|
|
98
|
+
if __name__=='__main__':
|
|
99
|
+
joye = Joye()
|
|
100
|
+
pk = joye.keygen()
|
|
101
|
+
k = joye.destruction_keys(pk)
|
|
102
|
+
|
|
103
|
+
c1 = joye.encrypt(2,pk,k['k0'])
|
|
104
|
+
c2 = joye.encrypt(4,pk,k['k1'])
|
|
105
|
+
|
|
106
|
+
print (joye.sum(c1,c2,pk,k[0]))
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Private and Dynamic Time-Series Data Aggregation (LEM14)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Iraklis Leontiadis, Kaoutar Elkhiyaoui, Refik Molva
|
|
5
|
+
|
|
6
|
+
| **Title:** "Private and Dynamic Time-Series Data Aggregation with Trust Relaxation"
|
|
7
|
+
| **Published in:** CANS 2014
|
|
8
|
+
| **Available from:** http://eprint.iacr.org/2014/256.pdf
|
|
9
|
+
| **Notes:** Enables plaintext evaluation of sums from encrypted time-series values
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** aggregation (privacy-preserving)
|
|
14
|
+
* **Setting:** integer groups
|
|
15
|
+
* **Assumption:** Paillier
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: Iraklis Leontiadis
|
|
20
|
+
:Date: 2/2015
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
#!/usr/bin/env python3
|
|
24
|
+
from charm.toolbox.integergroup import RSAGroup
|
|
25
|
+
from charm.schemes.pkenc.pkenc_paillier99 import Pai99
|
|
26
|
+
from charm.toolbox.integergroup import lcm,integer
|
|
27
|
+
from charm.toolbox.PKEnc import PKEnc
|
|
28
|
+
from charm.core.engine.util import *
|
|
29
|
+
from datetime import datetime
|
|
30
|
+
from time import mktime
|
|
31
|
+
import hashlib , os , math, sys, random
|
|
32
|
+
if sys.version_info < (3, 5):
|
|
33
|
+
from fractions import gcd
|
|
34
|
+
else:
|
|
35
|
+
from math import gcd
|
|
36
|
+
from timeit import default_timer as timer
|
|
37
|
+
|
|
38
|
+
#This generates values of p,q,n and n2
|
|
39
|
+
global n,n2
|
|
40
|
+
group=RSAGroup()
|
|
41
|
+
pai=Pai99(group)
|
|
42
|
+
(public_key,secret_key)=pai.keygen()
|
|
43
|
+
npom=public_key['n']
|
|
44
|
+
n=int(npom)
|
|
45
|
+
nn=public_key['n2']
|
|
46
|
+
n2=int(nn)
|
|
47
|
+
|
|
48
|
+
def hash():
|
|
49
|
+
'''
|
|
50
|
+
Computing hash value of time
|
|
51
|
+
'''
|
|
52
|
+
t = datetime.now()
|
|
53
|
+
d=t.strftime("%b/%d/%Y/%H:%M:%S")
|
|
54
|
+
e=d.encode('utf-8')
|
|
55
|
+
c=hashlib.sha256(e).hexdigest()
|
|
56
|
+
htp=int(c,16)
|
|
57
|
+
if htp < n2:
|
|
58
|
+
if gcd(htp,n2) == 1:
|
|
59
|
+
return htp
|
|
60
|
+
else:
|
|
61
|
+
hash()
|
|
62
|
+
else:
|
|
63
|
+
hash()
|
|
64
|
+
|
|
65
|
+
def secretkey():
|
|
66
|
+
'''
|
|
67
|
+
Generating random secret key smaller than n2
|
|
68
|
+
'''
|
|
69
|
+
b=os.urandom(256)
|
|
70
|
+
ska=int.from_bytes(b, byteorder='big')
|
|
71
|
+
if ska < n2:
|
|
72
|
+
return ska
|
|
73
|
+
else:
|
|
74
|
+
secretkey()
|
|
75
|
+
|
|
76
|
+
class Aggregator():
|
|
77
|
+
'''
|
|
78
|
+
Class for computing Pka and generating Ska
|
|
79
|
+
'''
|
|
80
|
+
|
|
81
|
+
def __init__(self):
|
|
82
|
+
global pka,ht
|
|
83
|
+
ht=hash()
|
|
84
|
+
self.ska=secretkey()
|
|
85
|
+
while 1:
|
|
86
|
+
if gcd(self.ska,n2)==1:
|
|
87
|
+
break
|
|
88
|
+
else:
|
|
89
|
+
self.ska=secretkey()
|
|
90
|
+
self.pkap=pow(ht,self.ska,n2)
|
|
91
|
+
pka=self.pkap
|
|
92
|
+
|
|
93
|
+
def decrypt(self,*encarray):
|
|
94
|
+
'''
|
|
95
|
+
Decrypting the sum
|
|
96
|
+
'''
|
|
97
|
+
|
|
98
|
+
cprod=1
|
|
99
|
+
#length=len(encarray)
|
|
100
|
+
#for x in range(length):
|
|
101
|
+
|
|
102
|
+
# cprod=(cprod*int(encarray[x]))
|
|
103
|
+
# cprodfin=cprod%n2
|
|
104
|
+
array = map(int, encarray)
|
|
105
|
+
for x in array:
|
|
106
|
+
cprod *= x
|
|
107
|
+
cprod %= n2
|
|
108
|
+
cprodfin=cprod
|
|
109
|
+
pt=pow(cprodfin,self.ska,n2)
|
|
110
|
+
auxin=modinv(auxt,n2)
|
|
111
|
+
it=(pt*auxin)%n2-1
|
|
112
|
+
pom1=it//n
|
|
113
|
+
skapr=self.ska%n
|
|
114
|
+
pom2=modinv(skapr,n)
|
|
115
|
+
rez=(pom2*pom1)%n
|
|
116
|
+
return rez
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def encryptfunc(a,d):
|
|
120
|
+
'''
|
|
121
|
+
Encryption of one value, where a=plaintext(number), d=ski
|
|
122
|
+
'''
|
|
123
|
+
v1=pow(ht,d,n2)
|
|
124
|
+
v2=(1+int(a)*n)%n2
|
|
125
|
+
v3=(v1*v2)%n2
|
|
126
|
+
rez=v3
|
|
127
|
+
return rez
|
|
128
|
+
|
|
129
|
+
def auxiliaryfunc(b):
|
|
130
|
+
'''
|
|
131
|
+
Auxiliary information of one value, where b=ski
|
|
132
|
+
'''
|
|
133
|
+
rez=pow(pka,b,n2)
|
|
134
|
+
return rez
|
|
135
|
+
|
|
136
|
+
def egcd(a, b):
|
|
137
|
+
'''
|
|
138
|
+
Extended Euclidian gcd function between a and b
|
|
139
|
+
'''
|
|
140
|
+
x,y, u,v = 0,1, 1,0
|
|
141
|
+
while a != 0:
|
|
142
|
+
q, r = b//a, b%a
|
|
143
|
+
m, n = x-u*q, y-v*q
|
|
144
|
+
b,a, x,y, u,v = a,r, u,v, m,n
|
|
145
|
+
gcd = b
|
|
146
|
+
return gcd, x, y
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def modinv(a, m):
|
|
150
|
+
'''
|
|
151
|
+
Finding modulo inverse of a mod m
|
|
152
|
+
'''
|
|
153
|
+
gcd, x, y = egcd(a, m)
|
|
154
|
+
if gcd != 1:
|
|
155
|
+
return None # modular inverse does not exist
|
|
156
|
+
else:
|
|
157
|
+
return x % m
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class Users():
|
|
161
|
+
'''
|
|
162
|
+
Computing users secret keys(ski) for users list *userdata
|
|
163
|
+
'''
|
|
164
|
+
|
|
165
|
+
def __init__(self,*userdata):
|
|
166
|
+
|
|
167
|
+
self.i=len(userdata)
|
|
168
|
+
self.dat=[int(userdata[x]) for x in range(self.i)]
|
|
169
|
+
self.sk=[secretkey() for x in range(self.i)]
|
|
170
|
+
|
|
171
|
+
def encrypt(self):
|
|
172
|
+
'''
|
|
173
|
+
Encrypts all user data into a list
|
|
174
|
+
'''
|
|
175
|
+
|
|
176
|
+
encp=[encryptfunc(self.dat[x],self.sk[x]) for x in range(self.i)]
|
|
177
|
+
return encp
|
|
178
|
+
|
|
179
|
+
def auxiliary(self):
|
|
180
|
+
'''
|
|
181
|
+
Computes auxiliary for all users into a list
|
|
182
|
+
'''
|
|
183
|
+
|
|
184
|
+
array=[auxiliaryfunc(self.sk[x]) for x in range(self.i)]
|
|
185
|
+
return array
|
|
186
|
+
|
|
187
|
+
class Collector():
|
|
188
|
+
'''
|
|
189
|
+
Computes auxt from list of auxiliary information from all users
|
|
190
|
+
'''
|
|
191
|
+
|
|
192
|
+
def __init__(self,*auxarray):
|
|
193
|
+
|
|
194
|
+
global auxt
|
|
195
|
+
auxtpom=1
|
|
196
|
+
#length=len(auxarray)
|
|
197
|
+
#for x in range(length):
|
|
198
|
+
# auxtpom=(auxtpom*int(auxarray[x]))%n2
|
|
199
|
+
|
|
200
|
+
#auxt=auxtpom
|
|
201
|
+
array = map(int, auxarray)
|
|
202
|
+
for x in array:
|
|
203
|
+
auxtpom *= x
|
|
204
|
+
auxtpom %= n2
|
|
205
|
+
auxt=auxtpom
|
|
206
|
+
|
|
207
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Collusion-Resistant Obfuscation and Functional Re-encryption (CCV11)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Nishanth Chandran, Melissa Chase, Vinod Vaikuntanathan
|
|
5
|
+
|
|
6
|
+
| **Title:** "Collusion-Resistant Obfuscation and Functional Re-encryption"
|
|
7
|
+
| **Published in:** ePrint Archive, 2011
|
|
8
|
+
| **Available from:** http://eprint.iacr.org/2011/337
|
|
9
|
+
| **Notes:** Status: NOT FINISHED/DOESN'T EXECUTE
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** functional re-encryption
|
|
14
|
+
* **Setting:** bilinear groups (asymmetric)
|
|
15
|
+
* **Assumption:** DBDH
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: J. Ayo Akinyele
|
|
20
|
+
:Date: 03/2012
|
|
21
|
+
'''
|
|
22
|
+
from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,pair as e
|
|
23
|
+
|
|
24
|
+
debug = False
|
|
25
|
+
class InputEnc:
|
|
26
|
+
def __init__(self, groupObj):
|
|
27
|
+
global group, proof
|
|
28
|
+
group = groupObj
|
|
29
|
+
proof = lambda a,b,c,d: group.hash((a, b, c, d), ZR)
|
|
30
|
+
|
|
31
|
+
def setup(self, d):
|
|
32
|
+
a = [group.random(ZR) for i in range(d)]
|
|
33
|
+
g = group.random(G1)
|
|
34
|
+
C = [g ** a[i] for i in range(d)]
|
|
35
|
+
|
|
36
|
+
# need to add 'crs'
|
|
37
|
+
i_pk = { 'g':g, 'C':C, 'd':d }
|
|
38
|
+
i_sk = { 'a':a }
|
|
39
|
+
return (i_pk, i_sk)
|
|
40
|
+
|
|
41
|
+
def encrypt(self, i_pk, i, M : G1):
|
|
42
|
+
if i > i_pk['d'] or i < 0:
|
|
43
|
+
print("i not in d. try again!")
|
|
44
|
+
return None
|
|
45
|
+
r, r_pr = group.random(ZR, 2)
|
|
46
|
+
|
|
47
|
+
C = [ i_pk['C'][i] ** r for i in range(i_pk['d']) ]
|
|
48
|
+
Cpr = [ i_pk['C'][i] ** r_pr for i in range(i_pk['d']) ]
|
|
49
|
+
D = (i_pk['g'] ** r) * M
|
|
50
|
+
Dpr = i_pk['g'] ** r_pr
|
|
51
|
+
E = { 'C':C, 'D':D }
|
|
52
|
+
Epr = { 'Cpr':Cpr, 'Dpr':Dpr }
|
|
53
|
+
|
|
54
|
+
# is this correct?
|
|
55
|
+
pi = None
|
|
56
|
+
# pi = proof(C, D, Cpr, Dpr) # group.hash((C, D, Cpr, Dpr), ZR)
|
|
57
|
+
return (E, Epr, pi)
|
|
58
|
+
|
|
59
|
+
def decrypt(self, i_sk, ct, M : [G1]):
|
|
60
|
+
E, Epr, pi = ct
|
|
61
|
+
C, D = E['C'], E['D']
|
|
62
|
+
a = i_sk['a']
|
|
63
|
+
# if pi != proof(C, D, Epr['Cpr'], Epr['Dpr']):
|
|
64
|
+
# print("proof did not verify.")
|
|
65
|
+
# return False
|
|
66
|
+
result = {}
|
|
67
|
+
for i in range(len(a)):
|
|
68
|
+
result[i] = D * ~(C ** (1 / a[i]))
|
|
69
|
+
|
|
70
|
+
m = result[0]
|
|
71
|
+
for i in range(1, len(result)):
|
|
72
|
+
if m != result[i]: return False
|
|
73
|
+
return m
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class OutputEnc:
|
|
77
|
+
def __init__(self, groupObj):
|
|
78
|
+
global group
|
|
79
|
+
group = groupObj
|
|
80
|
+
|
|
81
|
+
def setup(self):
|
|
82
|
+
h = group.random(G2)
|
|
83
|
+
a = group.random(ZR)
|
|
84
|
+
|
|
85
|
+
o_pk = { 'h':h, 'pk':h ** a }
|
|
86
|
+
o_sk = a
|
|
87
|
+
return (o_pk, o_sk)
|
|
88
|
+
|
|
89
|
+
def encrypt(self, i_pk, o_pk, M : G1):
|
|
90
|
+
r, s = group.random(ZR, 2)
|
|
91
|
+
Y = o_pk['pk'] ** r
|
|
92
|
+
W = o_pk['h'] ** r
|
|
93
|
+
S = i_pk['g'] ** s
|
|
94
|
+
|
|
95
|
+
F = e(S, Y)
|
|
96
|
+
H = o_pk['h'] ** s
|
|
97
|
+
G = e(S, W) * e(M, H)
|
|
98
|
+
return { 'F':F, 'G':G, 'H':H }
|
|
99
|
+
|
|
100
|
+
def decrypt(self, a, ct, M : [G1]):
|
|
101
|
+
F, G, H = ct['F'], ct['G'], ct['H']
|
|
102
|
+
Q = G * (F ** -(1 / a))
|
|
103
|
+
|
|
104
|
+
for m in M:
|
|
105
|
+
if e(m, H) == Q: return m
|
|
106
|
+
return False
|
|
107
|
+
|
charm/schemes/pk_vrf.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Verifiable Random Functions with Large Input Spaces (HW10)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Susan Hohenberger, Brent Waters
|
|
5
|
+
|
|
6
|
+
| **Title:** "Constructing Verifiable Random Functions with Large Input Spaces"
|
|
7
|
+
| **Published in:** ePrint Archive, 2010
|
|
8
|
+
| **Available from:** http://eprint.iacr.org/2010/102.pdf
|
|
9
|
+
| **Notes:** Applications to resettable ZK proofs, micropayment schemes, updatable ZK DBs
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** verifiable random function (VRF)
|
|
14
|
+
* **Setting:** bilinear groups (pairing-based)
|
|
15
|
+
* **Assumption:** q-DBDHI
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: J. Ayo Akinyele
|
|
20
|
+
:Date: 1/2012
|
|
21
|
+
'''
|
|
22
|
+
from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,pair
|
|
23
|
+
from charm.toolbox.iterate import dotprod
|
|
24
|
+
|
|
25
|
+
debug = False
|
|
26
|
+
class VRF10:
|
|
27
|
+
"""
|
|
28
|
+
>>> from charm.toolbox.pairinggroup import PairingGroup
|
|
29
|
+
>>> group = PairingGroup('MNT224')
|
|
30
|
+
>>> vrf = VRF10(group)
|
|
31
|
+
>>> statement = [0, 1, 1, 0, 1, 0, 1, 0]
|
|
32
|
+
>>> n = len(statement)
|
|
33
|
+
>>> (public_key, secret_key) = vrf.setup(n)
|
|
34
|
+
>>> witness = vrf.prove(secret_key, statement)
|
|
35
|
+
>>> vrf.verify(public_key, statement, witness)
|
|
36
|
+
True
|
|
37
|
+
"""
|
|
38
|
+
"""Definition in paper: behave as Pseudo Random Functions (PRFs) with an additional property that party
|
|
39
|
+
holding the seed will publish a commitment to the function and is able to non-interactively convince
|
|
40
|
+
a verifier that a given evaluation is correct (matches pub commitment) without sacrificing pseudo-
|
|
41
|
+
randomness property on other inputs."""
|
|
42
|
+
def __init__(self, groupObj):
|
|
43
|
+
global group, lam_func
|
|
44
|
+
group = groupObj
|
|
45
|
+
lam_func = lambda i,a,b: a[i] ** b[i]
|
|
46
|
+
|
|
47
|
+
def setup(self, n):
|
|
48
|
+
"""n = bit length of inputs"""
|
|
49
|
+
g1 = group.random(G1)
|
|
50
|
+
g2, h = group.random(G2), group.random(G2)
|
|
51
|
+
u_t = group.random(ZR)
|
|
52
|
+
u = [group.random(ZR) for i in range(n+1)]
|
|
53
|
+
U_t = g2 ** u_t
|
|
54
|
+
U1 = [g1 ** u[i] for i in range(0, n)]
|
|
55
|
+
U2 = [g2 ** u[i] for i in range(0, n)]
|
|
56
|
+
|
|
57
|
+
pk = { 'U1':U1, 'U2':U2,'U_t':U_t, 'g1':g1, 'g2':g2, 'h':h,'n':n }
|
|
58
|
+
sk = { 'u':u, 'u_t':u_t, 'g1':g1, 'h':h,'n':n }
|
|
59
|
+
return (pk, sk)
|
|
60
|
+
|
|
61
|
+
def F(self, sk, x):
|
|
62
|
+
result = dotprod(1, -1, sk['n'], lam_func, sk['u'], x)
|
|
63
|
+
return pair(sk['g1'] ** (sk['u_t'] * sk['u'][0] * result), sk['h'])
|
|
64
|
+
|
|
65
|
+
def prove(self, sk, x):
|
|
66
|
+
pi = {} # [i for i in range(sk['n'])]
|
|
67
|
+
for i in range(0, sk['n']):
|
|
68
|
+
dotProd0 = dotprod(1, -1, i+1, lam_func, sk['u'], x)
|
|
69
|
+
pi[i+1] = sk['g1'] ** (sk['u_t'] * dotProd0)
|
|
70
|
+
|
|
71
|
+
dotProd1 = dotprod(1, -1, sk['n'], lam_func, sk['u'], x)
|
|
72
|
+
pi[0] = sk['g1'] ** (sk['u_t'] * sk['u'][0] * dotProd1)
|
|
73
|
+
y = self.F(sk, x)
|
|
74
|
+
return { 'y':y, 'pi':pi } #, 'pi0':pi_0 }
|
|
75
|
+
|
|
76
|
+
def verify(self, pk, x, st):
|
|
77
|
+
n, y, pi = pk['n'], st['y'], st['pi']
|
|
78
|
+
# check first index
|
|
79
|
+
check1 = pair(pi[1], pk['g2'])
|
|
80
|
+
if x[0] == 0 and check1 == pair(pk['g1'], pk['U_t']):
|
|
81
|
+
if debug: print("Verify: check 0 successful!\t\tcase:", x[0])
|
|
82
|
+
elif x[0] == 1 and check1 == pair(pk['U1'][0], pk['U_t']):
|
|
83
|
+
if debug: print("Verify: check 0 successful!\t\tcase:", x[0])
|
|
84
|
+
else:
|
|
85
|
+
if debug: print("Verify: check 0 FAILURE!\t\t failed case:", x[0])
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
for i in range(2, n+1):
|
|
89
|
+
check2 = pair(pi[i], pk['g2'])
|
|
90
|
+
if x[i-1] == 0 and check2 == pair(pi[i-1], pk['g2']):
|
|
91
|
+
if debug: print("Verify: check", i-1 ,"successful!\t\tcase:", x[i-1])
|
|
92
|
+
elif x[i-1] == 1 and check2 == pair(pi[i-1], pk['U2'][i-1]):
|
|
93
|
+
if debug: print("Verify: check", i-1 ,"successful!\t\tcase:", x[i-1])
|
|
94
|
+
else:
|
|
95
|
+
if debug: print("Verify: check", i-1 ,"FAILURE!\t\tcase:", x[i-1])
|
|
96
|
+
return False
|
|
97
|
+
|
|
98
|
+
if pair(pi[0], pk['g2'] * pk['h']) == (pair(pi[n], pk['U2'][0]) * y): #and pair(pi_0, pk['h']) == y:
|
|
99
|
+
if debug: print("Verify: all and final check successful!!!")
|
|
100
|
+
return True
|
|
101
|
+
else:
|
|
102
|
+
return False
|
|
103
|
+
|
|
104
|
+
def main():
|
|
105
|
+
grp = PairingGroup('MNT224')
|
|
106
|
+
|
|
107
|
+
# bits
|
|
108
|
+
x1 = [0, 1, 1, 0, 1, 0, 1, 0]
|
|
109
|
+
#x2 = [1, 1, 1, 0, 1, 0, 1, 0]
|
|
110
|
+
# block of bits
|
|
111
|
+
n = 8
|
|
112
|
+
|
|
113
|
+
vrf = VRF10(grp)
|
|
114
|
+
|
|
115
|
+
# setup the VRF to accept input blocks of 8-bits
|
|
116
|
+
(pk, sk) = vrf.setup(n)
|
|
117
|
+
|
|
118
|
+
# generate proof over block x (using sk)
|
|
119
|
+
st = vrf.prove(sk, x1)
|
|
120
|
+
|
|
121
|
+
# verify bits using pk and proof
|
|
122
|
+
assert vrf.verify(pk, x1, st), "VRF failed verification"
|
|
123
|
+
#assert vrf.verify(pk, x2, st), "VRF should FAIL verification!!!"
|
|
124
|
+
|
|
125
|
+
if __name__ == "__main__":
|
|
126
|
+
debug = True
|
|
127
|
+
main()
|
|
File without changes
|