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,274 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Simulatable Adaptive Oblivious Transfer (CNS07)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Jan Camenisch, Gregory Neven, abhi shelat
|
|
5
|
+
|
|
6
|
+
| **Title:** "Simulatable Adaptive Oblivious Transfer"
|
|
7
|
+
| **Published in:** EUROCRYPT 2007
|
|
8
|
+
| **Available from:** http://eprint.iacr.org/2008/014
|
|
9
|
+
| **Notes:** Uses sigma protocols for interactive proofs
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** oblivious transfer protocol
|
|
14
|
+
* **Setting:** bilinear groups (asymmetric)
|
|
15
|
+
* **Assumption:** DBDH
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: J. Ayo Akinyele
|
|
20
|
+
:Date: 2/2012
|
|
21
|
+
'''
|
|
22
|
+
from charm.core.engine.protocol import *
|
|
23
|
+
from charm.core.engine.util import *
|
|
24
|
+
from socket import *
|
|
25
|
+
from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
|
|
26
|
+
from charm.schemes.sigma1 import *
|
|
27
|
+
from charm.schemes.sigma2 import *
|
|
28
|
+
from charm.schemes.sigma3 import *
|
|
29
|
+
import sys
|
|
30
|
+
|
|
31
|
+
SENDER,RECEIVER = 1,2
|
|
32
|
+
HOST, PORT = "", 8083
|
|
33
|
+
|
|
34
|
+
class ObliviousTransfer(Protocol):
|
|
35
|
+
def __init__(self, messages=None, groupObj=None, common_input=None):
|
|
36
|
+
Protocol.__init__(self, None)
|
|
37
|
+
receiver_states = { 2:self.receiver_init2, 4:self.receiver_transfer4, 6:self.receiver_transfer6, 8:self.receiver_transfer8 }
|
|
38
|
+
sender_states = { 1:self.sender_init1, 3:self.sender_init3, 5:self.sender_transfer5, 7:self.sender_transfer7, 9:self.sender_transfer9 }
|
|
39
|
+
|
|
40
|
+
receiver_trans = { 2:4, 4:6, 6:8 }
|
|
41
|
+
sender_trans = { 1:3, 3:[3,5], 5:7, 7:9 }
|
|
42
|
+
# describe the parties involved and the valid transitions
|
|
43
|
+
Protocol.addPartyType(self, RECEIVER, receiver_states, receiver_trans)
|
|
44
|
+
Protocol.addPartyType(self, SENDER, sender_states, sender_trans, True)
|
|
45
|
+
# Protocol.setSerializers(self, self.serialize, self.deserialize)
|
|
46
|
+
# make sure
|
|
47
|
+
if groupObj == None:
|
|
48
|
+
self.group = PairingGroup('SS512')
|
|
49
|
+
else:
|
|
50
|
+
self.group = groupObj
|
|
51
|
+
# proof parameter generation
|
|
52
|
+
if common_input == None: # generate common parameters to P and V
|
|
53
|
+
db = {}
|
|
54
|
+
self.__gen_setup = True
|
|
55
|
+
else: # can be used as a sub-protocol if common_input is specified by caller
|
|
56
|
+
db = common_input
|
|
57
|
+
self.__gen_setup = False
|
|
58
|
+
Protocol.setSubclassVars(self, self.group, db)
|
|
59
|
+
if messages != None:
|
|
60
|
+
self.M, self.sig = [], []
|
|
61
|
+
for i in range(0, len(messages)):
|
|
62
|
+
self.M.append( bytes(messages[i], 'utf8') )
|
|
63
|
+
print("bytes =>", self.M[i],", message =>", messages[i])
|
|
64
|
+
# self.M.append(self.group.hash(messages[i], ZR))
|
|
65
|
+
# self.sig.append(messages[i])
|
|
66
|
+
# dict to hold variables from interaction
|
|
67
|
+
|
|
68
|
+
def get_common(self):
|
|
69
|
+
if self.__gen_setup:
|
|
70
|
+
g, h = self.group.random(G1), self.group.random(G2)
|
|
71
|
+
H = pair(g, h)
|
|
72
|
+
Protocol.store(self, ('g', g), ('h', h), ('H', H) )
|
|
73
|
+
return (g, h, H)
|
|
74
|
+
else: # common parameters generated already
|
|
75
|
+
return Protocol.get(self, ['g', 'h', 'H'])
|
|
76
|
+
|
|
77
|
+
# msgs => dict of M -> H(M)
|
|
78
|
+
def sender_init1(self):
|
|
79
|
+
M = self.M
|
|
80
|
+
print("SENDER 1: ")
|
|
81
|
+
(g, h, H) = self.get_common()
|
|
82
|
+
x = self.group.random(ZR)
|
|
83
|
+
y = g ** x
|
|
84
|
+
print("send g =>", g)
|
|
85
|
+
print("send h =>", h)
|
|
86
|
+
print("send H =>", H)
|
|
87
|
+
print("send x =>", x)
|
|
88
|
+
print("send y =>", y)
|
|
89
|
+
A, B, C = {}, {}, {}
|
|
90
|
+
for i in range(0, len(self.M)):
|
|
91
|
+
j = self.group.init(ZR, i+1)
|
|
92
|
+
print("j =>", j)
|
|
93
|
+
A[i] = g ** ~(x + j)
|
|
94
|
+
B[i] = pair(A[i], h) #, M[i])
|
|
95
|
+
C[i] = { 'A':A[i], 'B':B[i] }
|
|
96
|
+
|
|
97
|
+
S = { 'g':g, 'h':h, 'H':H, 'y':y }
|
|
98
|
+
Protocol.store(self, ('x', y), ('y',y), ('C', C) )
|
|
99
|
+
Protocol.setState(self, 3)
|
|
100
|
+
return { 'S':S, 'C':C , 'PoK':'SigmaProtocol1' }
|
|
101
|
+
|
|
102
|
+
def sender_init3(self, input):
|
|
103
|
+
print("SENDER 3: ", input)
|
|
104
|
+
result = 'FAIL'
|
|
105
|
+
pk = Protocol.get(self, ['g', 'H', 'h'], dict)
|
|
106
|
+
if input == 'GO':
|
|
107
|
+
PoK1 = SigmaProtocol1(self.group, pk)
|
|
108
|
+
PoK1.setup( {'name':'prover', 'type':PoK1.PROVER, 'socket':self._socket} )
|
|
109
|
+
PoK1.execute(PoK1.PROVER, close_sock=False)
|
|
110
|
+
# print("PoK1 prover result =>", PoK1.result)
|
|
111
|
+
|
|
112
|
+
if PoK1.result == 'OK':
|
|
113
|
+
# transition to transfer phase
|
|
114
|
+
Protocol.setState(self, 5)
|
|
115
|
+
result = PoK1.result
|
|
116
|
+
# else: # JAA - something to this effect (Error case doesn't work yet)
|
|
117
|
+
# Protocol.setState(self, 3); return {'PoK': 'REDO' }
|
|
118
|
+
# need store and get functions for db
|
|
119
|
+
return {'PoK': result }
|
|
120
|
+
|
|
121
|
+
def sender_transfer5(self, input):
|
|
122
|
+
print("SENDER 5: query =>", input)
|
|
123
|
+
|
|
124
|
+
if input.get('PoK') != None: # continue
|
|
125
|
+
Protocol.setState(self, 7)
|
|
126
|
+
return 'OK'
|
|
127
|
+
Protocol.setState(self, None)
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
def sender_transfer7(self, input):
|
|
131
|
+
# print("SENDER 7: input =>", input)
|
|
132
|
+
if input.get('PoK2') != None:
|
|
133
|
+
# pk = Protocol.get(self, ['g','g2','y'], dict)
|
|
134
|
+
V = Protocol.get(self, ['V'])
|
|
135
|
+
pk = { 'V':V }
|
|
136
|
+
PoK2 = SigmaProtocol2(self.group, pk)
|
|
137
|
+
PoK2.setup( {'name':'verifier', 'type':PoK2.VERIFIER, 'socket':self._socket} )
|
|
138
|
+
Protocol.send_msg(self, 'GO')
|
|
139
|
+
PoK2.execute(PoK2.VERIFIER, close_sock=False)
|
|
140
|
+
# print("PoK2 verifier result =>", PoK2.result)
|
|
141
|
+
result = PoK2.result
|
|
142
|
+
|
|
143
|
+
if result == 'OK':
|
|
144
|
+
# print("transitioning to transfer9 result =>", result)
|
|
145
|
+
h, V = Protocol.get(self, ['h','V'])
|
|
146
|
+
W = pair(V, h)
|
|
147
|
+
Protocol.setState(self, 9)
|
|
148
|
+
return { 'PoK2':result, 'W':W, 'PoM':'SigmaProtocol3' }
|
|
149
|
+
Protocol.setState(self, None)
|
|
150
|
+
return None
|
|
151
|
+
|
|
152
|
+
def sender_transfer9(self, input):
|
|
153
|
+
# print("SENDER 9: PoM init =>", input)
|
|
154
|
+
|
|
155
|
+
if input == 'GO':
|
|
156
|
+
# print("Executing the PoM interactive proof.")
|
|
157
|
+
pk = Protocol.get(self, ['h','g','H','V'], dict)
|
|
158
|
+
PoM = SigmaProtocol3(self.group, pk)
|
|
159
|
+
PoM.setup( {'name':'prover', 'type':PoM.PROVER, 'socket':self._socket} )
|
|
160
|
+
PoM.execute(PoM.PROVER)
|
|
161
|
+
print("PoM prover result =>", PoM.result)
|
|
162
|
+
|
|
163
|
+
Protocol.setState(self, None)
|
|
164
|
+
return None
|
|
165
|
+
#################################
|
|
166
|
+
# END of SENDER state functions #
|
|
167
|
+
#################################
|
|
168
|
+
|
|
169
|
+
def receiver_init2(self, input):
|
|
170
|
+
print("RECEIVER 2: ")
|
|
171
|
+
pk = Sigma.get(self, ['S'])
|
|
172
|
+
if input['PoK'] == 'SigmaProtocol1':
|
|
173
|
+
PoK1 = SigmaProtocol1(self.group, pk)
|
|
174
|
+
PoK1.setup( {'name':'verifier', 'type':PoK1.VERIFIER, 'socket': self._socket} )
|
|
175
|
+
Protocol.send_msg(self, 'GO') # important: 1. acknowledges sub-protocol transition, 2. sends a short message using this socket
|
|
176
|
+
PoK1.execute(PoK1.VERIFIER, close_sock=False)
|
|
177
|
+
print("PoK1 verifier result =>", PoK1.result)
|
|
178
|
+
result = PoK1.result
|
|
179
|
+
|
|
180
|
+
if result == 'OK':
|
|
181
|
+
Protocol.setState(self, 4) # desired: 4 (TBD)
|
|
182
|
+
return {'PoK': result } # result should be R0 (state info) for Receiver
|
|
183
|
+
# let sender know to expect a PoK2 interaction next
|
|
184
|
+
|
|
185
|
+
def receiver_transfer4(self, input): # rec_tran4 -> sender_tran5
|
|
186
|
+
print("RECEIVER 4: Get query from end user.")
|
|
187
|
+
index = 0 # maps to position 0 in array (+1 indexed)
|
|
188
|
+
C = Protocol.get(self, ['C'])[0]
|
|
189
|
+
v = self.group.random(ZR) # secret for Receiver
|
|
190
|
+
V = C[index]['A'] ** v # public value
|
|
191
|
+
Protocol.setState(self, 6)
|
|
192
|
+
Protocol.store( self, ('v',v), ('V',V), ('query', index+1) )
|
|
193
|
+
return { 'V':V, 'PoK2':'SigmaProtocol2' }
|
|
194
|
+
|
|
195
|
+
def receiver_transfer6(self, input):
|
|
196
|
+
print("RECEIVER 6: input =>",input)
|
|
197
|
+
if input == 'GO':
|
|
198
|
+
(pk, V, v, query) = Protocol.get(self, ['S','V','v','query'])
|
|
199
|
+
pk['V'], pk['v'], pk['sigma'] = V, v, query
|
|
200
|
+
# set up client end of PoK2
|
|
201
|
+
PoK2 = SigmaProtocol2(self.group, pk)
|
|
202
|
+
PoK2.setup( {'name':'prover', 'type':PoK2.PROVER, 'socket':self._socket} )
|
|
203
|
+
PoK2.execute(PoK2.PROVER, close_sock=False)
|
|
204
|
+
print("PoK2 prover result =>", PoK2.result)
|
|
205
|
+
result = PoK2.result
|
|
206
|
+
Protocol.setState(self, 8)
|
|
207
|
+
return {'Pok2':result}
|
|
208
|
+
|
|
209
|
+
Protocol.setState(self, None)
|
|
210
|
+
return None
|
|
211
|
+
|
|
212
|
+
def receiver_transfer8(self, input):
|
|
213
|
+
print("RECEIVER 8:")
|
|
214
|
+
if input['PoK2'] != 'OK':
|
|
215
|
+
Protocol.setState(self, None)
|
|
216
|
+
return None
|
|
217
|
+
|
|
218
|
+
if input.get('PoM') != None:
|
|
219
|
+
# print("Executing the PoM interactive proof.")
|
|
220
|
+
pk = Protocol.get(self, ['W'], dict)
|
|
221
|
+
PoM = SigmaProtocol3(self.group, pk)
|
|
222
|
+
PoM.setup( {'name':'verifier', 'type':PoM.VERIFIER, 'socket': self._socket} )
|
|
223
|
+
Protocol.send_msg(self, 'GO') # important: 1. acknowledges sub-protocol transition, 2. sends a short message using this socket
|
|
224
|
+
PoM.execute(PoM.VERIFIER, close_sock=False)
|
|
225
|
+
result = PoM.result
|
|
226
|
+
print("PoM verifier result =>", result)
|
|
227
|
+
|
|
228
|
+
if result == 'OK':
|
|
229
|
+
# print("Now we recover ")
|
|
230
|
+
# W allows us to unlock the appropriate keyword, right?
|
|
231
|
+
# get query, B_query, and v
|
|
232
|
+
(W, v, C) = Protocol.get(self, ['W','v','C'])
|
|
233
|
+
index = 0
|
|
234
|
+
B = C[index]['B']
|
|
235
|
+
w = W ** ~v
|
|
236
|
+
# m = self.xor(B, w)
|
|
237
|
+
print("Query =>", index)
|
|
238
|
+
print("Corresponding B =>", B)
|
|
239
|
+
print("Original message key =>", w)
|
|
240
|
+
print("Search complete!!!")
|
|
241
|
+
Protocol.setState(self, None)
|
|
242
|
+
return None
|
|
243
|
+
|
|
244
|
+
if __name__ == "__main__":
|
|
245
|
+
if len(sys.argv) != 2:
|
|
246
|
+
print("Usage: %s [-r or -s]" % sys.argv[0])
|
|
247
|
+
exit(-1)
|
|
248
|
+
|
|
249
|
+
if sys.argv[1] == "-r":
|
|
250
|
+
print("Operating as receiver...")
|
|
251
|
+
svr = socket(AF_INET, SOCK_STREAM)
|
|
252
|
+
svr.bind((HOST, PORT))
|
|
253
|
+
svr.listen(1)
|
|
254
|
+
svr_sock, addr = svr.accept()
|
|
255
|
+
print("Connected by ", addr)
|
|
256
|
+
msgs = None
|
|
257
|
+
_name, _type, _sock = "receiver", RECEIVER, svr_sock
|
|
258
|
+
# sp.setup( {'name':"receiver", 'type':_type, 'socket':svr_sock} )
|
|
259
|
+
elif sys.argv[1] == "-s":
|
|
260
|
+
print("Operating as sender...")
|
|
261
|
+
clt = socket(AF_INET, SOCK_STREAM)
|
|
262
|
+
clt.connect((HOST, PORT))
|
|
263
|
+
clt.settimeout(15)
|
|
264
|
+
msgs = ['one', 'two', 'three']
|
|
265
|
+
_name, _type, _sock = "sender", SENDER, clt
|
|
266
|
+
else:
|
|
267
|
+
print("Usage: %s -r or -s" % sys.argv[0])
|
|
268
|
+
exit(-1)
|
|
269
|
+
|
|
270
|
+
# group = PairingGroup('library/a.param')
|
|
271
|
+
sp = ObliviousTransfer(msgs)
|
|
272
|
+
sp.setup( {'name':_name, 'type':_type, 'socket':_sock} )
|
|
273
|
+
# run as a thread...
|
|
274
|
+
sp.execute(_type)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Schnorr Zero-Knowledge Protocol (Schnorr91)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Claus-Peter Schnorr
|
|
5
|
+
|
|
6
|
+
| **Title:** "Efficient Signature Generation by Smart Cards"
|
|
7
|
+
| **Published in:** Journal of Cryptology, 1991
|
|
8
|
+
| **Notes:** Classic three-move zero-knowledge proof of knowledge of discrete log
|
|
9
|
+
|
|
10
|
+
.. rubric:: Scheme Properties
|
|
11
|
+
|
|
12
|
+
* **Type:** sigma protocol (zero-knowledge proof)
|
|
13
|
+
* **Setting:** elliptic curve groups
|
|
14
|
+
* **Assumption:** DL
|
|
15
|
+
|
|
16
|
+
.. rubric:: Implementation
|
|
17
|
+
|
|
18
|
+
:Authors: Charm Developers
|
|
19
|
+
:Date: Unknown
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
from charm.core.engine.protocol import *
|
|
24
|
+
from charm.toolbox.ecgroup import ECGroup,G
|
|
25
|
+
from socket import socket,AF_INET,SOCK_STREAM
|
|
26
|
+
from charm.toolbox.eccurve import prime192v1
|
|
27
|
+
from charm.toolbox.enum import Enum
|
|
28
|
+
import sys
|
|
29
|
+
|
|
30
|
+
party = Enum('Verifier', 'Prover')
|
|
31
|
+
PROVER,VERIFIER = party.Prover, party.Verifier
|
|
32
|
+
HOST, PORT = "", 8082
|
|
33
|
+
|
|
34
|
+
class SchnorrZK(Protocol):
|
|
35
|
+
def __init__(self, builtin_cv, common_input=None):
|
|
36
|
+
Protocol.__init__(self, None)
|
|
37
|
+
verifier_states = { 2:self.verifier_state2, 4:self.verifier_state4, 6:self.verifier_state6 }
|
|
38
|
+
prover_states = { 1:self.prover_state1, 3:self.prover_state3, 5:self.prover_state5 }
|
|
39
|
+
|
|
40
|
+
verifier_trans = { 2:4, 4:[2,6] }
|
|
41
|
+
prover_trans = { 1:3, 3:5, 5:1 }
|
|
42
|
+
# describe the parties involved and the valid transitions
|
|
43
|
+
Protocol.addPartyType(self, VERIFIER, verifier_states, verifier_trans)
|
|
44
|
+
Protocol.addPartyType(self, PROVER, prover_states, prover_trans, True)
|
|
45
|
+
|
|
46
|
+
self.group = ECGroup(builtin_cv)
|
|
47
|
+
#db = {}
|
|
48
|
+
Protocol.setSubclassVars(self, self.group) #, db)
|
|
49
|
+
|
|
50
|
+
# PROVER states
|
|
51
|
+
def prover_state1(self):
|
|
52
|
+
x = self.group.random()
|
|
53
|
+
r, g = self.group.random(), self.group.random(G)
|
|
54
|
+
t = g ** r
|
|
55
|
+
print('prover: ',"hello to verifier.")
|
|
56
|
+
Protocol.store(self, ('r',r), ('x',x))
|
|
57
|
+
Protocol.setState(self, 3)
|
|
58
|
+
return {'t':t, 'g':g, 'y':g ** x } # output goes to the next state.
|
|
59
|
+
|
|
60
|
+
def prover_state3( self, input):
|
|
61
|
+
print("state3 => ", input)
|
|
62
|
+
(r, x, c) = Protocol.get(self, ['r', 'x', 'c'])
|
|
63
|
+
s = r + c * x
|
|
64
|
+
Protocol.setState(self, 5)
|
|
65
|
+
return {'s':s}
|
|
66
|
+
|
|
67
|
+
def prover_state5( self, input ):
|
|
68
|
+
print("state5 => ", input)
|
|
69
|
+
result = input.split(':')[1]
|
|
70
|
+
if result == 'ACCEPTED': Protocol.setState(self, None)
|
|
71
|
+
else: Protocol.setState(self, 1); return 'REPEAT'
|
|
72
|
+
return None
|
|
73
|
+
|
|
74
|
+
# VERIFIER states
|
|
75
|
+
def verifier_state2(self, input):
|
|
76
|
+
#print("state2 received => ", input)
|
|
77
|
+
# compute challenge c and send to prover
|
|
78
|
+
c = self.group.random()
|
|
79
|
+
print("state2 generate c :=", c)
|
|
80
|
+
Protocol.store(self, ('c',c))
|
|
81
|
+
Protocol.setState(self, 4)
|
|
82
|
+
return {'c':c}
|
|
83
|
+
|
|
84
|
+
def verifier_state4( self, input ):
|
|
85
|
+
(t,g,y,c,s) = Protocol.get(self, ['t','g','y','c','s'])
|
|
86
|
+
print("state4: s :=", s)
|
|
87
|
+
|
|
88
|
+
if (g ** s == t * (y ** c)):
|
|
89
|
+
print("SUCCESSFUL VERIFICATION!!!")
|
|
90
|
+
output = "verifier : ACCEPTED!"
|
|
91
|
+
else:
|
|
92
|
+
print("FAILED TO VERIFY!!!")
|
|
93
|
+
output = "verifier : FAILED!"
|
|
94
|
+
Protocol.setState(self, 6)
|
|
95
|
+
return output
|
|
96
|
+
|
|
97
|
+
def verifier_state6(self, input ):
|
|
98
|
+
print("state6: => ", input)
|
|
99
|
+
Protocol.setState(self, None)
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
if __name__ == "__main__":
|
|
103
|
+
sp = SchnorrZK(prime192v1)
|
|
104
|
+
|
|
105
|
+
if sys.argv[1] == "-v":
|
|
106
|
+
print("Operating as verifier...")
|
|
107
|
+
svr = socket(AF_INET, SOCK_STREAM)
|
|
108
|
+
svr.bind((HOST, PORT))
|
|
109
|
+
svr.listen(1)
|
|
110
|
+
svr_sock, addr = svr.accept()
|
|
111
|
+
print("Connected by ", addr)
|
|
112
|
+
_name, _type, _sock = "verifier", VERIFIER, svr_sock
|
|
113
|
+
# sp.setup( {'name':"verifier", 'type':_type, 'socket':svr_sock} )
|
|
114
|
+
elif sys.argv[1] == "-p":
|
|
115
|
+
print("Operating as prover...")
|
|
116
|
+
clt = socket(AF_INET, SOCK_STREAM)
|
|
117
|
+
clt.connect((HOST, PORT))
|
|
118
|
+
clt.settimeout(15)
|
|
119
|
+
_name, _type, _sock = "prover", PROVER, clt
|
|
120
|
+
else:
|
|
121
|
+
print("Usage: %s [-v or -p]" % sys.argv[0])
|
|
122
|
+
exit(-1)
|
|
123
|
+
sp.setup( {'name':_name, 'type':_type, 'socket':_sock} )
|
|
124
|
+
# run as a thread...
|
|
125
|
+
sp.execute(_type)
|
charm/schemes/sigma1.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Sigma Protocol 1 (Sigma1)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Charm Developers
|
|
5
|
+
|
|
6
|
+
| **Notes:** Sigma protocol for proving knowledge in pairing-based settings
|
|
7
|
+
|
|
8
|
+
.. rubric:: Scheme Properties
|
|
9
|
+
|
|
10
|
+
* **Type:** sigma protocol (zero-knowledge proof)
|
|
11
|
+
* **Setting:** bilinear groups (pairing-based)
|
|
12
|
+
* **Assumption:** DL
|
|
13
|
+
|
|
14
|
+
.. rubric:: Implementation
|
|
15
|
+
|
|
16
|
+
:Authors: J. Ayo Akinyele
|
|
17
|
+
:Date: 2/2012
|
|
18
|
+
'''
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
from charm.toolbox.sigmaprotocol import Sigma
|
|
22
|
+
from charm.toolbox.pairinggroup import ZR,G2,pair
|
|
23
|
+
|
|
24
|
+
class SigmaProtocol1(Sigma):
|
|
25
|
+
def __init__(self, groupObj, common_input=None):
|
|
26
|
+
Sigma.__init__(self, groupObj, common_input)
|
|
27
|
+
|
|
28
|
+
def prover_state1(self):
|
|
29
|
+
(g, h, H) = Sigma.get(self, ['g', 'h', 'H'])
|
|
30
|
+
r = self.group.random(G2)
|
|
31
|
+
a = pair(g, r)
|
|
32
|
+
Sigma.setState(self, 3)
|
|
33
|
+
return { 'r':r, 'a':a, 'g':g, 'h':h, 'H':H }
|
|
34
|
+
|
|
35
|
+
def prover_state3(self, input):
|
|
36
|
+
(r, h, c) = Sigma.get(self, ['r','h','c'])
|
|
37
|
+
z = r * (h ** -c)
|
|
38
|
+
Sigma.setState(self, 5)
|
|
39
|
+
return {'z':z }
|
|
40
|
+
|
|
41
|
+
def prover_state5(self, input):
|
|
42
|
+
Sigma.setState(self, None)
|
|
43
|
+
Sigma.setErrorCode(self, input)
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
def verifier_state2(self, input):
|
|
47
|
+
c = self.group.random(ZR)
|
|
48
|
+
Sigma.setState(self, 4)
|
|
49
|
+
return {'c':c }
|
|
50
|
+
|
|
51
|
+
def verifier_state4(self, input):
|
|
52
|
+
(g, H, a, c, z) = Sigma.get(self, ['g','H','a','c','z'])
|
|
53
|
+
if a == (pair(g,z) * (H ** c)):
|
|
54
|
+
print("SUCCESS!!!!!!!"); result = 'OK'
|
|
55
|
+
else:
|
|
56
|
+
print("Failed!!!"); result = 'FAIL'
|
|
57
|
+
Sigma.setState(self, 6)
|
|
58
|
+
Sigma.setErrorCode(self, result)
|
|
59
|
+
return result
|
|
60
|
+
|
|
61
|
+
def verifier_state6(self, input):
|
|
62
|
+
Sigma.setState(self, None)
|
|
63
|
+
return None
|
|
64
|
+
|
charm/schemes/sigma2.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Sigma Protocol 2 (Sigma2)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Charm Developers
|
|
5
|
+
|
|
6
|
+
| **Notes:** Sigma protocol for proving knowledge with pairing-based verification
|
|
7
|
+
|
|
8
|
+
.. rubric:: Scheme Properties
|
|
9
|
+
|
|
10
|
+
* **Type:** sigma protocol (zero-knowledge proof)
|
|
11
|
+
* **Setting:** bilinear groups (pairing-based)
|
|
12
|
+
* **Assumption:** DL
|
|
13
|
+
|
|
14
|
+
.. rubric:: Implementation
|
|
15
|
+
|
|
16
|
+
:Authors: J. Ayo Akinyele
|
|
17
|
+
:Date: 2/2012
|
|
18
|
+
'''
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
from charm.toolbox.sigmaprotocol import Sigma
|
|
22
|
+
from charm.toolbox.pairinggroup import ZR,G1,pair
|
|
23
|
+
|
|
24
|
+
class SigmaProtocol2(Sigma):
|
|
25
|
+
def __init__(self, groupObj, common_input=None):
|
|
26
|
+
Sigma.__init__(self, groupObj, common_input)
|
|
27
|
+
if common_input == None:
|
|
28
|
+
self.gen_common()
|
|
29
|
+
|
|
30
|
+
def gen_common(self):
|
|
31
|
+
x, v = self.group.random(ZR, 2)
|
|
32
|
+
g = self.group.random(G1)
|
|
33
|
+
index = self.group.init(ZR, 1) # testing message 0 at index 1
|
|
34
|
+
V = (g ** ~(x+index)) ** v
|
|
35
|
+
y = g ** x
|
|
36
|
+
print("check: lhs = e(V,y) =>", pair(V,y))
|
|
37
|
+
print("check: rhs = e(V,g)^-o * e(g,g)^v =>", (pair(V,g) ** -index) * (pair(g,g) ** v))
|
|
38
|
+
Protocol.store(self, ('g', g), ('V', V), ('v',v), ('y',y), ('sigma', index) )
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
def prover_state1(self):
|
|
42
|
+
print("PROVER 1: ")
|
|
43
|
+
(g, V) = Sigma.get(self, ['g', 'V'])
|
|
44
|
+
r1, r2 = self.group.random(ZR, 2)
|
|
45
|
+
|
|
46
|
+
a = (pair(V, g) ** -r1) * (pair(g, g) ** r2)
|
|
47
|
+
print("send g =>", g)
|
|
48
|
+
print("send V =>", V)
|
|
49
|
+
print("send r1 =>", r1)
|
|
50
|
+
print("send r2 =>", r2)
|
|
51
|
+
print("send a =>", a)
|
|
52
|
+
|
|
53
|
+
pk = Sigma.get(self, ['g','V','y'], dict)
|
|
54
|
+
Sigma.store(self, ('r1',r1), ('r2',r2) )
|
|
55
|
+
Sigma.setState(self, 3)
|
|
56
|
+
return { 'a':a, 'pk':pk }
|
|
57
|
+
|
|
58
|
+
def prover_state3(self, input):
|
|
59
|
+
print("PROVER 3: ")
|
|
60
|
+
(r1, r2, v, sigma, c) = Sigma.get(self, ['r1','r2','v','sigma', 'c'])
|
|
61
|
+
print("input c =>", c)
|
|
62
|
+
z1 = r1 - sigma * c # need a way to get sigma index as part of init index (1..N)
|
|
63
|
+
z2 = r2 - v * c
|
|
64
|
+
print("send z1 =>", z1)
|
|
65
|
+
print("send z2 =>", z2)
|
|
66
|
+
Sigma.setState(self, 5)
|
|
67
|
+
return {'z1':z1, 'z2':z2 }
|
|
68
|
+
|
|
69
|
+
def prover_state5(self, input):
|
|
70
|
+
print("PROVER 5: result =>", input)
|
|
71
|
+
Sigma.setState(self, None)
|
|
72
|
+
Sigma.setErrorCode(self, input)
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
def verifier_state2(self, input):
|
|
76
|
+
print("VERIFIER 2: ")
|
|
77
|
+
c = self.group.random(ZR)
|
|
78
|
+
print("send c =>", c)
|
|
79
|
+
Sigma.setState(self, 4)
|
|
80
|
+
return {'c':c }
|
|
81
|
+
|
|
82
|
+
def verifier_state4(self, input):
|
|
83
|
+
print("VERIFIER 4: ")
|
|
84
|
+
(a, c, z1, z2, pk) = Sigma.get(self, ['a','c','z1','z2','pk'])
|
|
85
|
+
g, y, V = pk['g'], pk['y'], pk['V']
|
|
86
|
+
print("get a =>", a)
|
|
87
|
+
if a == (pair(V,y) ** c) * (pair(V,g) ** -z1) * (pair(g,g) ** z2):
|
|
88
|
+
print("SUCCESS!!!!!!!"); result = 'OK'
|
|
89
|
+
else:
|
|
90
|
+
print("Failed!!!"); result = 'FAIL'
|
|
91
|
+
Sigma.setState(self, 6)
|
|
92
|
+
Sigma.setErrorCode(self, result)
|
|
93
|
+
return result
|
|
94
|
+
|
|
95
|
+
def verifier_state6(self, input):
|
|
96
|
+
print("VERIFIER 6: done.")
|
|
97
|
+
Sigma.setState(self, None)
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
#if __name__ == "__main__":
|
|
101
|
+
# if len(sys.argv) != 2:
|
|
102
|
+
# print("Usage: %s [-v or -p]" % sys.argv[0])
|
|
103
|
+
# exit(-1)
|
|
104
|
+
#
|
|
105
|
+
# if sys.argv[1] == "-v":
|
|
106
|
+
# print("Operating as verifier...")
|
|
107
|
+
# svr = socket(AF_INET, SOCK_STREAM)
|
|
108
|
+
# svr.bind((HOST, PORT))
|
|
109
|
+
# svr.listen(1)
|
|
110
|
+
# svr_sock, addr = svr.accept()
|
|
111
|
+
# print("Connected by ", addr)
|
|
112
|
+
# _name, _type, _sock = "verifier", VERIFIER, svr_sock
|
|
113
|
+
# elif sys.argv[1] == "-p":
|
|
114
|
+
# print("Operating as prover...")
|
|
115
|
+
# clt = socket(AF_INET, SOCK_STREAM)
|
|
116
|
+
# clt.connect((HOST, PORT))
|
|
117
|
+
# clt.settimeout(15)
|
|
118
|
+
# _name, _type, _sock = "prover", PROVER, clt
|
|
119
|
+
# else:
|
|
120
|
+
# print("Usage: %s -v or -p" % sys.argv[0])
|
|
121
|
+
# exit(-1)
|
|
122
|
+
#
|
|
123
|
+
# group = PairingGroup('library/a.param')
|
|
124
|
+
# sp = SigmaProtocol2(group)
|
|
125
|
+
# sp.setup( {'name':_name, 'type':_type, 'socket':_sock} )
|
|
126
|
+
# # run as a thread...
|
|
127
|
+
# sp.execute(_type)
|
|
128
|
+
# print("Result of protocol =>", sp.result)
|
|
129
|
+
#
|