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,113 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Ateniese-Medeiros Chameleon Hash (ADM05)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Giuseppe Ateniese, Breno de Medeiros
|
|
5
|
+
|
|
6
|
+
| **Title:** "On the Key Exposure Problem in Chameleon Hashes"
|
|
7
|
+
| **Published in:** SCN 2004
|
|
8
|
+
| **Notes:** Section 4, Schnorr group-based construction
|
|
9
|
+
|
|
10
|
+
.. rubric:: Scheme Properties
|
|
11
|
+
|
|
12
|
+
* **Type:** chameleon hash function
|
|
13
|
+
* **Setting:** Schnorr groups
|
|
14
|
+
* **Assumption:** DL
|
|
15
|
+
|
|
16
|
+
.. rubric:: Implementation
|
|
17
|
+
|
|
18
|
+
:Authors: J. Ayo Akinyele
|
|
19
|
+
:Date: 4/2011
|
|
20
|
+
'''
|
|
21
|
+
from charm.toolbox.Hash import ChamHash
|
|
22
|
+
from charm.toolbox.integergroup import IntegerGroupQ
|
|
23
|
+
from charm.core.math.integer import integer
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
debug = False
|
|
27
|
+
class ChamHash_Adm05(ChamHash):
|
|
28
|
+
"""
|
|
29
|
+
>>> from charm.core.math.integer import integer
|
|
30
|
+
>>> p = integer(141660875619984104245410764464185421040193281776686085728248762539241852738181649330509191671665849071206347515263344232662465937366909502530516774705282764748558934610432918614104329009095808618770549804432868118610669336907161081169097403439689930233383598055540343198389409225338204714777812724565461351567)
|
|
31
|
+
>>> q = integer(70830437809992052122705382232092710520096640888343042864124381269620926369090824665254595835832924535603173757631672116331232968683454751265258387352641382374279467305216459307052164504547904309385274902216434059305334668453580540584548701719844965116691799027770171599194704612669102357388906362282730675783)
|
|
32
|
+
>>> chamHash = ChamHash_Adm05(p, q)
|
|
33
|
+
>>> (public_key, secret_key) = chamHash.paramgen()
|
|
34
|
+
>>> msg = "hello world this is the message"
|
|
35
|
+
>>> c = chamHash.hash(public_key, msg)
|
|
36
|
+
>>> c == chamHash.hash(public_key, msg, c[1], c[2])
|
|
37
|
+
True
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def __init__(self, p=0, q=0):
|
|
41
|
+
ChamHash.__init__(self)
|
|
42
|
+
self.group = IntegerGroupQ(0)
|
|
43
|
+
# if p and q parameters have already been selected
|
|
44
|
+
self.group.p, self.group.q, self.group.r = p, q, 2
|
|
45
|
+
|
|
46
|
+
def paramgen(self, secparam=1024):
|
|
47
|
+
if self.group.p == 0 or self.group.q == 0:
|
|
48
|
+
self.group.paramgen(secparam)
|
|
49
|
+
g, x = self.group.randomGen(), self.group.random() # g, [1,q-1]
|
|
50
|
+
y = g ** x
|
|
51
|
+
|
|
52
|
+
if debug:
|
|
53
|
+
print("Public params")
|
|
54
|
+
print("g =>", g); print("y =>", y)
|
|
55
|
+
|
|
56
|
+
pk = {'g': g, 'y': y}
|
|
57
|
+
sk = {'x': x}
|
|
58
|
+
return pk, sk
|
|
59
|
+
|
|
60
|
+
def hash(self, pk, m, r=0, s=0):
|
|
61
|
+
p, q = self.group.p, self.group.q
|
|
62
|
+
if r == 0:
|
|
63
|
+
r = self.group.random()
|
|
64
|
+
if s == 0:
|
|
65
|
+
s = self.group.random()
|
|
66
|
+
e = self.group.hash(m, r)
|
|
67
|
+
|
|
68
|
+
C = r - (((pk['y'] ** e) * (pk['g'] ** s)) % p) % q
|
|
69
|
+
return C, r, s
|
|
70
|
+
|
|
71
|
+
def find_collision(self, pk, sk, C, new_message):
|
|
72
|
+
p, q = self.group.p, self.group.q
|
|
73
|
+
k_prime = self.group.random()
|
|
74
|
+
r_prime = C + ((pk['g'] ** k_prime) % p) % q
|
|
75
|
+
e_prime = self.group.hash(new_message, r_prime)
|
|
76
|
+
s_prime = (k_prime - (e_prime * sk['x'])) % q
|
|
77
|
+
C_prime = r_prime - (((pk['y'] ** e_prime) * (pk['g'] ** s_prime)) % p) % q
|
|
78
|
+
return C_prime, r_prime, s_prime
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def main():
|
|
82
|
+
p = integer(141660875619984104245410764464185421040193281776686085728248762539241852738181649330509191671665849071206347515263344232662465937366909502530516774705282764748558934610432918614104329009095808618770549804432868118610669336907161081169097403439689930233383598055540343198389409225338204714777812724565461351567)
|
|
83
|
+
q = integer(70830437809992052122705382232092710520096640888343042864124381269620926369090824665254595835832924535603173757631672116331232968683454751265258387352641382374279467305216459307052164504547904309385274902216434059305334668453580540584548701719844965116691799027770171599194704612669102357388906362282730675783)
|
|
84
|
+
cham_hash = ChamHash_Adm05(p, q)
|
|
85
|
+
pk, sk = cham_hash.paramgen()
|
|
86
|
+
if debug:
|
|
87
|
+
print("Paramgen...")
|
|
88
|
+
print("pk :=", pk)
|
|
89
|
+
print("sk :=", sk)
|
|
90
|
+
|
|
91
|
+
msg = 'Some message to hash'
|
|
92
|
+
c, r, s = cham_hash.hash(pk, msg)
|
|
93
|
+
if debug:
|
|
94
|
+
print('Hashing: ', msg)
|
|
95
|
+
print('Hash is: ', c)
|
|
96
|
+
|
|
97
|
+
other_msg = 'Some other message to hash, different from previous message'
|
|
98
|
+
assert msg != other_msg
|
|
99
|
+
new_c, new_r, new_s = cham_hash.find_collision(pk, sk, c, other_msg)
|
|
100
|
+
if debug:
|
|
101
|
+
print('Hashing: ', other_msg)
|
|
102
|
+
print('Hash is: ', new_c)
|
|
103
|
+
|
|
104
|
+
assert new_c == c, 'Could not generate collision'
|
|
105
|
+
if debug:
|
|
106
|
+
print('Generated hash collision')
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
debug = True
|
|
111
|
+
main()
|
|
112
|
+
|
|
113
|
+
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Hohenberger-Waters Chameleon Hash (HW09)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Susan Hohenberger, Brent Waters
|
|
5
|
+
|
|
6
|
+
| **Title:** "Realizing Hash-and-Sign Signatures under Standard Assumptions"
|
|
7
|
+
| **Published in:** Eurocrypt 2009
|
|
8
|
+
| **Available from:** http://eprint.iacr.org/2009/028.pdf
|
|
9
|
+
| **Notes:** Appendix A, based on Ateniese-de Medeiros scheme
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** chameleon hash function
|
|
14
|
+
* **Setting:** RSA
|
|
15
|
+
* **Assumption:** RSA
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: J. Ayo Akinyele
|
|
20
|
+
:Date: 1/2011
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
from charm.toolbox.Hash import ChamHash,Hash
|
|
24
|
+
from charm.toolbox.integergroup import IntegerGroupQ,gcd,integer
|
|
25
|
+
from charm.toolbox.conversion import Conversion
|
|
26
|
+
|
|
27
|
+
debug=False
|
|
28
|
+
class ChamHash_HW09(ChamHash):
|
|
29
|
+
"""
|
|
30
|
+
>>> from charm.core.math.integer import integer
|
|
31
|
+
>>> p = integer(164960892556379843852747960442703555069442262500242170785496141408191025653791149960117681934982863436763270287998062485836533436731979391762052869620652382502450810563192532079839617163226459506619269739544815249458016088505187490329968102214003929285843634017082702266003694786919671197914296386150563930299)
|
|
32
|
+
>>> q = integer(82480446278189921926373980221351777534721131250121085392748070704095512826895574980058840967491431718381635143999031242918266718365989695881026434810326191251225405281596266039919808581613229753309634869772407624729008044252593745164984051107001964642921817008541351133001847393459835598957148193075281965149)
|
|
33
|
+
>>> chamHash = ChamHash_HW09()
|
|
34
|
+
>>> (public_key, secret_key) = chamHash.paramgen(1024, p, q)
|
|
35
|
+
>>> msg = "Hello world this is the message!"
|
|
36
|
+
>>> (hash1, r) = chamHash.hash(public_key, msg)
|
|
37
|
+
>>> (hash2, r) = chamHash.hash(public_key, msg, r)
|
|
38
|
+
>>> hash1 == hash2
|
|
39
|
+
True
|
|
40
|
+
"""
|
|
41
|
+
def __init__(self):
|
|
42
|
+
global group
|
|
43
|
+
group = IntegerGroupQ(0)
|
|
44
|
+
|
|
45
|
+
def paramgen(self, secparam, p = 0, q = 0):
|
|
46
|
+
# If we're given p, q, compute N = p*q. Otherwise select random p, q
|
|
47
|
+
if not (p == 0 or q == 0):
|
|
48
|
+
N = p * q
|
|
49
|
+
if debug: print("p :=", p)
|
|
50
|
+
if debug: print("q :=", q)
|
|
51
|
+
else:
|
|
52
|
+
group.paramgen(secparam)
|
|
53
|
+
p, q = group.p, group.q
|
|
54
|
+
N = p * q
|
|
55
|
+
|
|
56
|
+
phi_N = (p-1)*(q-1)
|
|
57
|
+
J = group.random(N)
|
|
58
|
+
|
|
59
|
+
# Use deterministic algorithm to find coprime value instead of random search
|
|
60
|
+
# This fixes Python 3.12+ hanging issue where random values share common factors
|
|
61
|
+
# Try common RSA public exponents first, then search incrementally
|
|
62
|
+
common_exponents = [65537, 3, 5, 17, 257, 641, 6700417]
|
|
63
|
+
e = None
|
|
64
|
+
|
|
65
|
+
for candidate in common_exponents:
|
|
66
|
+
# Use isCoPrime() method which properly checks gcd == 1
|
|
67
|
+
if phi_N.isCoPrime(candidate):
|
|
68
|
+
e = integer(candidate)
|
|
69
|
+
break
|
|
70
|
+
|
|
71
|
+
# If common exponents don't work, search incrementally starting from a larger value
|
|
72
|
+
if e is None:
|
|
73
|
+
e = integer(65537)
|
|
74
|
+
max_iterations = 10000000 # Large limit for deterministic search
|
|
75
|
+
|
|
76
|
+
for iterations in range(max_iterations):
|
|
77
|
+
# Use isCoPrime() method which properly checks gcd == 1
|
|
78
|
+
if phi_N.isCoPrime(e):
|
|
79
|
+
break
|
|
80
|
+
e += 2 # Only try odd numbers (even numbers can't be coprime with even phi_N)
|
|
81
|
+
|
|
82
|
+
# Check if we found a coprime value (either broke out of loop or on last iteration)
|
|
83
|
+
if not phi_N.isCoPrime(e):
|
|
84
|
+
raise RuntimeError(
|
|
85
|
+
f"Could not find coprime value after {max_iterations} iterations. "
|
|
86
|
+
f"phi_N={phi_N}, last e={e}, gcd(e, phi_N)={gcd(e, phi_N)}"
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
pk = { 'secparam': secparam, 'N': N, 'J': J, 'e': e }
|
|
90
|
+
sk = { 'p': p, 'q': q }
|
|
91
|
+
return (pk, sk)
|
|
92
|
+
|
|
93
|
+
def hash(self, pk, message, r = 0):
|
|
94
|
+
N, J, e = pk['N'], pk['J'], pk['e']
|
|
95
|
+
if r == 0:
|
|
96
|
+
r = group.random(N)
|
|
97
|
+
M = Conversion.bytes2integer(message)
|
|
98
|
+
h = ((J ** M) * (r ** e)) % N
|
|
99
|
+
return (h, r)
|
|
100
|
+
|
|
File without changes
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Groth-Sahai Commitment (GS08)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Jens Groth, Amit Sahai
|
|
5
|
+
|
|
6
|
+
| **Title:** "Efficient Non-interactive Proof Systems for Bilinear Groups"
|
|
7
|
+
| **Published in:** Eurocrypt 2008
|
|
8
|
+
| **Available from:** http://www.cs.ucl.ac.uk/staff/J.Groth/WImoduleFull.pdf
|
|
9
|
+
| **Notes:** Implements only the SXDH and DLIN instantiations, in prime-order groups
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** commitment scheme
|
|
14
|
+
* **Setting:** bilinear groups
|
|
15
|
+
* **Assumption:** SXDH or DLIN
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: Matthew Green
|
|
20
|
+
:Date: 6/2011
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
|
|
24
|
+
from charm.toolbox.Commit import *
|
|
25
|
+
|
|
26
|
+
debug=False
|
|
27
|
+
class Commitment_GS08(Commitment):
|
|
28
|
+
"""
|
|
29
|
+
>>> group = PairingGroup('SS512')
|
|
30
|
+
>>> alg = Commitment_GS08(group)
|
|
31
|
+
>>> public_key = alg.setup()
|
|
32
|
+
>>> msg = group.random(G1)
|
|
33
|
+
>>> (commit, decommit) = alg.commit(public_key, msg)
|
|
34
|
+
>>> alg.decommit(public_key, commit, decommit, msg)
|
|
35
|
+
True
|
|
36
|
+
"""
|
|
37
|
+
def __init__(self, groupObj, setting='SXDH'):
|
|
38
|
+
Commitment.__init__(self)
|
|
39
|
+
#Commitment.setProperty(self, secdef='CM_PHCB', assumption=['SXDH','DLIN'], message_space=[G1, 'KEM'], secmodel='SM')
|
|
40
|
+
global group
|
|
41
|
+
group = groupObj
|
|
42
|
+
|
|
43
|
+
# Generates commitment parameters for either G1 or G2 (specified by groupChoice).
|
|
44
|
+
# By default this generates the binding commitment parameters. Set commitType to 'hiding'
|
|
45
|
+
# in order to generate hiding parameters.
|
|
46
|
+
def setup(self, secparam=None, groupChoice=G1, commitType='binding'):
|
|
47
|
+
g1, h1 = group.random(groupChoice), group.random(groupChoice)
|
|
48
|
+
s, t = group.random(ZR), group.random(ZR)
|
|
49
|
+
if (commitType == 'binding'):
|
|
50
|
+
g2, h2 = g1 ** s, h1 ** s
|
|
51
|
+
else:
|
|
52
|
+
g2, h2 = g1 ** s, h1 ** t
|
|
53
|
+
|
|
54
|
+
return (g1, g2, h1, h2)
|
|
55
|
+
# msg => ZR
|
|
56
|
+
def commit(self, params, msg):
|
|
57
|
+
# TODO: check that the message is in the same group as the params
|
|
58
|
+
(g1, g2, h1, h2) = params
|
|
59
|
+
r1, r2 = group.random(ZR), group.random(ZR)
|
|
60
|
+
|
|
61
|
+
c1 = (g1 ** r1) * (h1 ** r2)
|
|
62
|
+
c2 = msg * (g2 ** r1) * (h2 ** r2)
|
|
63
|
+
|
|
64
|
+
return ({ 'c1':c1, 'c2':c2 }, { 'r1':r1, 'r2':r2 })
|
|
65
|
+
|
|
66
|
+
def decommit(self, params, c, d, msg):
|
|
67
|
+
# TODO: check that the message is in the same group as the params
|
|
68
|
+
(g1, g2, h1, h2) = params
|
|
69
|
+
|
|
70
|
+
if (not (c['c1'] == ((g1 ** d['r1']) * (h1 ** d['r2'])))):
|
|
71
|
+
return False
|
|
72
|
+
|
|
73
|
+
if (not ((c['c2'] / msg) == ((g2 ** d['r1']) * (h2 ** d['r2'])))):
|
|
74
|
+
return False
|
|
75
|
+
|
|
76
|
+
return True
|
|
77
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Pedersen Commitment (Ped92)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Torben P. Pedersen
|
|
5
|
+
|
|
6
|
+
| **Title:** "Non-Interactive and Information-Theoretic Secure Verifiable Secret Sharing"
|
|
7
|
+
| **Published in:** CRYPTO 1991
|
|
8
|
+
| **Available from:** https://link.springer.com/chapter/10.1007/3-540-46766-1_9
|
|
9
|
+
| **Notes:** Unconditionally hiding and computationally binding commitment scheme
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** commitment scheme
|
|
14
|
+
* **Setting:** elliptic curve groups
|
|
15
|
+
* **Assumption:** discrete logarithm
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: Charm Crypto
|
|
20
|
+
:Date: N/A
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
from charm.toolbox.ecgroup import ECGroup,ZR,G
|
|
24
|
+
from charm.toolbox.Commit import Commitment
|
|
25
|
+
|
|
26
|
+
debug = False
|
|
27
|
+
class CM_Ped92(Commitment):
|
|
28
|
+
"""
|
|
29
|
+
>>> group = ECGroup(410)
|
|
30
|
+
>>> alg = CM_Ped92(group)
|
|
31
|
+
>>> public_key = alg.setup()
|
|
32
|
+
>>> msg = group.random(ZR)
|
|
33
|
+
>>> (commit, decommit) = alg.commit(public_key, msg)
|
|
34
|
+
>>> alg.decommit(public_key, commit, decommit, msg)
|
|
35
|
+
True
|
|
36
|
+
"""
|
|
37
|
+
def __init__(self, groupObj):
|
|
38
|
+
Commitment.__init__(self)
|
|
39
|
+
global group
|
|
40
|
+
group = groupObj
|
|
41
|
+
|
|
42
|
+
def setup(self, secparam=None):
|
|
43
|
+
return {'g': group.random(G), 'h':group.random(G)}
|
|
44
|
+
|
|
45
|
+
def commit(self, pk, msg):
|
|
46
|
+
r = group.random(ZR)
|
|
47
|
+
c = (pk['g'] ** msg) * (pk['h'] ** r)
|
|
48
|
+
d = r
|
|
49
|
+
return (c,d)
|
|
50
|
+
|
|
51
|
+
def decommit(self, pk, c, d, msg):
|
|
52
|
+
return c == (pk['g'] ** msg) * (pk['h'] ** d)
|
|
53
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Key Encapsulation Mechanism (BCHK05)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Based on commitment scheme constructions
|
|
5
|
+
|
|
6
|
+
| **Title:** "Key Encapsulation from Commitment Schemes"
|
|
7
|
+
| **Notes:** Simple hash-based encapsulation scheme
|
|
8
|
+
|
|
9
|
+
.. rubric:: Scheme Properties
|
|
10
|
+
|
|
11
|
+
* **Type:** key encapsulation mechanism (KEM)
|
|
12
|
+
* **Setting:** hash-based
|
|
13
|
+
* **Assumption:** random oracle
|
|
14
|
+
|
|
15
|
+
.. rubric:: Implementation
|
|
16
|
+
|
|
17
|
+
:Authors: Charm Developers
|
|
18
|
+
:Date: Unknown
|
|
19
|
+
'''
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
from charm.core.math.integer import randomBits
|
|
23
|
+
import hashlib
|
|
24
|
+
|
|
25
|
+
debug = False
|
|
26
|
+
class EncapBCHK():
|
|
27
|
+
"""
|
|
28
|
+
>>> encap = EncapBCHK()
|
|
29
|
+
>>> hout = encap.setup()
|
|
30
|
+
>>> (r, com, dec) = encap.S(hout)
|
|
31
|
+
>>> rout = encap.R(hout, com, dec)
|
|
32
|
+
>>> r == rout
|
|
33
|
+
True
|
|
34
|
+
"""
|
|
35
|
+
def __init__(self):
|
|
36
|
+
global H
|
|
37
|
+
H = hashlib.sha1() # nosec B324 - SHA1 used for historical compatibility
|
|
38
|
+
|
|
39
|
+
def setup(self):
|
|
40
|
+
pub = hashlib.sha256()
|
|
41
|
+
return pub
|
|
42
|
+
|
|
43
|
+
def S(self, pub):
|
|
44
|
+
x = randomBits(448)
|
|
45
|
+
x = str(x).zfill(135)
|
|
46
|
+
|
|
47
|
+
r = hashlib.sha256(x.encode('utf-8')).digest()
|
|
48
|
+
|
|
49
|
+
com = hashlib.sha1(x.encode('utf-8')).digest()[:128] # nosec B324
|
|
50
|
+
|
|
51
|
+
dec = x
|
|
52
|
+
|
|
53
|
+
return (r, com, dec)
|
|
54
|
+
|
|
55
|
+
def R(self, pub, com, dec):
|
|
56
|
+
x = hashlib.sha1(str(dec).encode('utf-8')).digest()[:128] # nosec B324
|
|
57
|
+
|
|
58
|
+
if(x == com):
|
|
59
|
+
m = hashlib.sha256(str(dec).encode('utf-8')).digest()
|
|
60
|
+
return m
|
|
61
|
+
else:
|
|
62
|
+
return b'FALSE'
|
|
File without changes
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Short Group Signatures (BBS04)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Dan Boneh, Xavier Boyen, Hovav Shacham
|
|
5
|
+
|
|
6
|
+
| **Title:** "Short Group Signatures"
|
|
7
|
+
| **Published in:** CRYPTO 2004
|
|
8
|
+
| **Available from:** n/a
|
|
9
|
+
| **Notes:** An extended abstract of this paper appeared in Advances in Cryptology (2004)
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** group signature
|
|
14
|
+
* **Setting:** Pairing groups
|
|
15
|
+
* **Assumption:** Strong Diffie-Hellman (SDH) and Decision Linear
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: J. Ayo Akinyele
|
|
20
|
+
:Date: 12/2010
|
|
21
|
+
'''
|
|
22
|
+
from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
|
|
23
|
+
from charm.toolbox.PKSig import PKSig
|
|
24
|
+
|
|
25
|
+
debug=False
|
|
26
|
+
class ShortSig(PKSig):
|
|
27
|
+
"""
|
|
28
|
+
>>> group = PairingGroup('MNT224')
|
|
29
|
+
>>> n = 3 # how manu users are in the group
|
|
30
|
+
>>> user = 1 # which user's key we will sign a message with
|
|
31
|
+
>>> shortSig = ShortSig(group)
|
|
32
|
+
>>> (global_public_key, global_master_secret_key, user_secret_keys) = shortSig.keygen(n)
|
|
33
|
+
>>> msg = 'Hello World this is a message!'
|
|
34
|
+
>>> signature = shortSig.sign(global_public_key, user_secret_keys[user], msg)
|
|
35
|
+
>>> shortSig.verify(global_public_key, msg, signature)
|
|
36
|
+
True
|
|
37
|
+
"""
|
|
38
|
+
def __init__(self, groupObj):
|
|
39
|
+
PKSig.__init__(self)
|
|
40
|
+
global group
|
|
41
|
+
group = groupObj
|
|
42
|
+
|
|
43
|
+
def keygen(self, n):
|
|
44
|
+
g1, g2 = group.random(G1), group.random(G2)
|
|
45
|
+
h = group.random(G1)
|
|
46
|
+
xi1, xi2 = group.random(), group.random()
|
|
47
|
+
|
|
48
|
+
u,v = h ** ~xi1, h ** ~xi2
|
|
49
|
+
gamma = group.random(ZR)
|
|
50
|
+
w = g2 ** gamma
|
|
51
|
+
gpk = { 'g1':g1, 'g2':g2, 'h':h, 'u':u, 'v':v, 'w':w }
|
|
52
|
+
gmsk = { 'xi1':xi1, 'xi2':xi2 }
|
|
53
|
+
|
|
54
|
+
x = [group.random(ZR) for i in range(n)]
|
|
55
|
+
A = [gpk['g1'] ** ~(gamma + x[i]) for i in range(n)]
|
|
56
|
+
gsk = {}
|
|
57
|
+
if debug: print("\nSecret keys...")
|
|
58
|
+
for i in range(n):
|
|
59
|
+
if debug: print("User %d: A = %s, x = %s" % (i, A[i], x[i]))
|
|
60
|
+
gsk[i] = (A[i], x[i])
|
|
61
|
+
return (gpk, gmsk, gsk)
|
|
62
|
+
|
|
63
|
+
def sign(self, gpk, gsk, M):
|
|
64
|
+
alpha, beta = group.random(), group.random()
|
|
65
|
+
A, x = gsk[0], gsk[1]
|
|
66
|
+
T1 = gpk['u'] ** alpha
|
|
67
|
+
T2 = gpk['v'] ** beta
|
|
68
|
+
T3 = A * (gpk['h'] ** (alpha + beta))
|
|
69
|
+
|
|
70
|
+
delta1 = x * alpha
|
|
71
|
+
delta2 = x * beta
|
|
72
|
+
r = [group.random() for i in range(5)]
|
|
73
|
+
|
|
74
|
+
R1 = gpk['u'] ** r[0]
|
|
75
|
+
R2 = gpk['v'] ** r[1]
|
|
76
|
+
R3 = (pair(T3, gpk['g2']) ** r[2]) * (pair(gpk['h'], gpk['w']) ** (-r[0] - r[1])) * (pair(gpk['h'], gpk['g2']) ** (-r[3] - r[4]))
|
|
77
|
+
R4 = (T1 ** r[2]) * (gpk['u'] ** -r[3])
|
|
78
|
+
R5 = (T2 ** r[2]) * (gpk['v'] ** -r[4])
|
|
79
|
+
|
|
80
|
+
c = group.hash((M, T1, T2, T3, R1, R2, R3, R4, R5), ZR)
|
|
81
|
+
s1, s2 = r[0] + c * alpha, r[1] + c * beta
|
|
82
|
+
s3, s4 = r[2] + c * x, r[3] + c * delta1
|
|
83
|
+
s5 = r[4] + c * delta2
|
|
84
|
+
return {'T1':T1, 'T2':T2, 'T3':T3, 'c':c, 's_alpha':s1, 's_beta':s2, 's_x':s3, 's_delta1':s4, 's_delta2':s5}
|
|
85
|
+
|
|
86
|
+
def verify(self, gpk, M, sigma):
|
|
87
|
+
validSignature = False
|
|
88
|
+
|
|
89
|
+
c, t1, t2, t3 = sigma['c'], sigma['T1'], sigma['T2'], sigma['T3']
|
|
90
|
+
s_alpha, s_beta = sigma['s_alpha'], sigma['s_beta']
|
|
91
|
+
s_x, s_delta1, s_delta2 = sigma['s_x'], sigma['s_delta1'], sigma['s_delta2']
|
|
92
|
+
|
|
93
|
+
R1_ = (gpk['u'] ** s_alpha) * (t1 ** -c)
|
|
94
|
+
R2_ = (gpk['v'] ** s_beta) * (t2 ** -c)
|
|
95
|
+
R3_ = (pair(t3, gpk['g2']) ** s_x) * (pair(gpk['h'],gpk['w']) ** (-s_alpha - s_beta)) * (pair(gpk['h'], gpk['g2']) ** (-s_delta1 - s_delta2)) * ((pair(t3, gpk['w']) / pair(gpk['g1'], gpk['g2'])) ** c)
|
|
96
|
+
R4_ = (t1 ** s_x) * (gpk['u'] ** -s_delta1)
|
|
97
|
+
R5_ = (t2 ** s_x) * (gpk['v'] ** -s_delta2)
|
|
98
|
+
|
|
99
|
+
c_prime = group.hash((M, t1, t2, t3, R1_, R2_, R3_, R4_, R5_), ZR)
|
|
100
|
+
|
|
101
|
+
if c == c_prime:
|
|
102
|
+
if debug: print("c => '%s'" % c)
|
|
103
|
+
if debug: print("Valid Group Signature for message: '%s'" % M)
|
|
104
|
+
validSignature = True
|
|
105
|
+
else:
|
|
106
|
+
if debug: print("Not a valid signature for message!!!")
|
|
107
|
+
return validSignature
|
|
108
|
+
|
|
109
|
+
def open(self, gpk, gmsk, M, sigma):
|
|
110
|
+
t1, t2, t3, xi1, xi2 = sigma['T1'], sigma['T2'], sigma['T3'], gmsk['xi1'], gmsk['xi2']
|
|
111
|
+
|
|
112
|
+
A_prime = t3 / ((t1 ** xi1) * (t2 ** xi2))
|
|
113
|
+
return A_prime
|
|
114
|
+
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'''
|
|
2
|
+
**Short Group Signatures - Batch Verification Variant (BBS04-Var)**
|
|
3
|
+
|
|
4
|
+
*Authors:* Dan Boneh, Xavier Boyen, Hovav Shacham
|
|
5
|
+
|
|
6
|
+
| **Title:** "Short Group Signatures"
|
|
7
|
+
| **Published in:** CRYPTO 2004
|
|
8
|
+
| **Available from:** n/a
|
|
9
|
+
| **Notes:** Variant with alternative verification check that allows batch verification
|
|
10
|
+
|
|
11
|
+
.. rubric:: Scheme Properties
|
|
12
|
+
|
|
13
|
+
* **Type:** group signature
|
|
14
|
+
* **Setting:** Pairing groups
|
|
15
|
+
* **Assumption:** Strong Diffie-Hellman (SDH) and Decision Linear
|
|
16
|
+
|
|
17
|
+
.. rubric:: Implementation
|
|
18
|
+
|
|
19
|
+
:Authors: J. Ayo Akinyele
|
|
20
|
+
:Date: 12/2010
|
|
21
|
+
'''
|
|
22
|
+
from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
|
|
23
|
+
from charm.toolbox.PKSig import PKSig
|
|
24
|
+
|
|
25
|
+
debug=False
|
|
26
|
+
class ShortSig(PKSig):
|
|
27
|
+
"""
|
|
28
|
+
>>> group = PairingGroup('MNT224')
|
|
29
|
+
>>> n = 3 # how manu users in the group
|
|
30
|
+
>>> user = 1 # which user's key to sign a message with
|
|
31
|
+
>>> shortSig = ShortSig(group)
|
|
32
|
+
>>> (global_public_key, global_master_secret_key, user_secret_keys) = shortSig.keygen(n)
|
|
33
|
+
>>> msg = 'Hello World this is a message!'
|
|
34
|
+
>>> signature = shortSig.sign(global_public_key, user_secret_keys[user], msg)
|
|
35
|
+
>>> shortSig.verify(global_public_key, msg, signature)
|
|
36
|
+
True
|
|
37
|
+
"""
|
|
38
|
+
def __init__(self, groupObj):
|
|
39
|
+
PKSig.__init__(self)
|
|
40
|
+
global group
|
|
41
|
+
group = groupObj
|
|
42
|
+
|
|
43
|
+
def keygen(self, n):
|
|
44
|
+
g1, g2 = group.random(G1), group.random(G2)
|
|
45
|
+
h = group.random(G1)
|
|
46
|
+
xi1, xi2 = group.random(), group.random()
|
|
47
|
+
|
|
48
|
+
u,v = h ** ~xi1, h ** ~xi2
|
|
49
|
+
gamma = group.random(ZR)
|
|
50
|
+
w = g2 ** gamma
|
|
51
|
+
gpk = { 'g1':g1, 'g2':g2, 'h':h, 'u':u, 'v':v, 'w':w }
|
|
52
|
+
gmsk = { 'xi1':xi1, 'xi2':xi2 }
|
|
53
|
+
|
|
54
|
+
x = [group.random(ZR) for i in range(n)]
|
|
55
|
+
A = [gpk['g1'] ** ~(gamma + x[i]) for i in range(n)]
|
|
56
|
+
gsk = {}
|
|
57
|
+
if debug: print("\nSecret keys...")
|
|
58
|
+
for i in range(n):
|
|
59
|
+
if debug: print("User %d: A = %s, x = %s" % (i, A[i], x[i]))
|
|
60
|
+
gsk[i] = (A[i], x[i])
|
|
61
|
+
return (gpk, gmsk, gsk)
|
|
62
|
+
|
|
63
|
+
def sign(self, gpk, gsk, M):
|
|
64
|
+
alpha, beta = group.random(), group.random()
|
|
65
|
+
A, x = gsk[0], gsk[1]
|
|
66
|
+
T1 = gpk['u'] ** alpha
|
|
67
|
+
T2 = gpk['v'] ** beta
|
|
68
|
+
T3 = A * (gpk['h'] ** (alpha + beta))
|
|
69
|
+
|
|
70
|
+
gamma1 = x * alpha
|
|
71
|
+
gamma2 = x * beta
|
|
72
|
+
r = [group.random() for i in range(5)]
|
|
73
|
+
|
|
74
|
+
R1 = gpk['u'] ** r[0]
|
|
75
|
+
R2 = gpk['v'] ** r[1]
|
|
76
|
+
R3 = (pair(T3, gpk['g2']) ** r[2]) * (pair(gpk['h'], gpk['w']) ** (-r[0] - r[1])) * (pair(gpk['h'], gpk['g2']) ** (-r[3] - r[4]))
|
|
77
|
+
R4 = (T1 ** r[2]) * (gpk['u'] ** -r[3])
|
|
78
|
+
R5 = (T2 ** r[2]) * (gpk['v'] ** -r[4])
|
|
79
|
+
|
|
80
|
+
c = group.hash((M, T1, T2, T3, R1, R2, R3, R4, R5), ZR)
|
|
81
|
+
s1, s2 = r[0] + c * alpha, r[1] + c * beta
|
|
82
|
+
s3, s4 = r[2] + c * x, r[3] + c * gamma1
|
|
83
|
+
s5 = r[4] + c * gamma2
|
|
84
|
+
return { 'T1':T1, 'T2':T2, 'T3':T3, 'R3':R3,'c':c, 's_alpha':s1, 's_beta':s2, 's_x':s3, 's_gamma1':s4, 's_gamma2':s5 }
|
|
85
|
+
|
|
86
|
+
def verify(self, gpk, M, sigma):
|
|
87
|
+
"""alternative verification check for BGLS04 which allows it to be batched"""
|
|
88
|
+
c, T1, T2, T3 = sigma['c'], sigma['T1'], sigma['T2'], sigma['T3']
|
|
89
|
+
s_alpha, s_beta = sigma['s_alpha'], sigma['s_beta']
|
|
90
|
+
s_x, s_gamma1, s_gamma2 = sigma['s_x'], sigma['s_gamma1'], sigma['s_gamma2']
|
|
91
|
+
R3 = sigma['R3']
|
|
92
|
+
|
|
93
|
+
R1 = (gpk['u'] ** s_alpha) * (T1 ** -c)
|
|
94
|
+
R2 = (gpk['v'] ** s_beta) * (T2 ** -c)
|
|
95
|
+
R4 = (T1 ** s_x) * (gpk['u'] ** -s_gamma1)
|
|
96
|
+
R5 = (T2 ** s_x) * (gpk['v'] ** -s_gamma2)
|
|
97
|
+
if c == group.hash((M, T1, T2, T3, R1, R2, R3, R4, R5), ZR):
|
|
98
|
+
if debug: print("c => '%s'" % c)
|
|
99
|
+
if debug: print("Valid Group Signature for message: '%s'" % M)
|
|
100
|
+
pass
|
|
101
|
+
else:
|
|
102
|
+
if debug: print("Not a valid signature for message!!!")
|
|
103
|
+
return False
|
|
104
|
+
|
|
105
|
+
if ((pair(T3, gpk['g2']) ** s_x) * (pair(gpk['h'],gpk['w']) ** (-s_alpha - s_beta)) * (pair(gpk['h'], gpk['g2']) ** (-s_gamma1 - s_gamma2)) * (pair(T3, gpk['w']) ** c) * (pair(gpk['g1'], gpk['g2']) ** -c) ) == R3:
|
|
106
|
+
return True
|
|
107
|
+
else:
|
|
108
|
+
return False
|
|
109
|
+
|
|
110
|
+
def open(self, gpk, gmsk, M, sigma):
|
|
111
|
+
t1, t2, t3, xi1, xi2 = sigma['T1'], sigma['T2'], sigma['T3'], gmsk['xi1'], gmsk['xi2']
|
|
112
|
+
|
|
113
|
+
A_prime = t3 / ((t1 ** xi1) * (t2 ** xi2))
|
|
114
|
+
return A_prime
|
|
115
|
+
|
|
File without changes
|