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,269 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Zero-Knowledge Statement Parser.
|
|
3
|
+
|
|
4
|
+
This module provides a parser for ZK proof statements using pyparsing.
|
|
5
|
+
It converts statements like "h = g^x" or "(h = g^x) and (j = g^y)" into
|
|
6
|
+
a binary tree representation for processing by the ZKP compiler.
|
|
7
|
+
|
|
8
|
+
Supported Syntax:
|
|
9
|
+
- Single variable names: x, y, g, h (backwards compatible)
|
|
10
|
+
- Multi-character variable names: x1, x2, alpha, beta, gamma (NEW in v0.61)
|
|
11
|
+
- Exponentiation: g^x, g1^x1
|
|
12
|
+
- Equality: h = g^x
|
|
13
|
+
- Conjunction: (h = g^x) and (j = g^y)
|
|
14
|
+
- Disjunction: (h = g^x) or (j = g^y)
|
|
15
|
+
|
|
16
|
+
Examples::
|
|
17
|
+
|
|
18
|
+
parser = ZKParser()
|
|
19
|
+
result = parser.parse("h = g^x") # Single-char variables
|
|
20
|
+
result = parser.parse("h1 = g1^x1") # Multi-char variables
|
|
21
|
+
result = parser.parse("commitment = generator^secret") # Descriptive names
|
|
22
|
+
"""
|
|
23
|
+
from pyparsing import *
|
|
24
|
+
from charm.toolbox.zknode import *
|
|
25
|
+
import string
|
|
26
|
+
import sys
|
|
27
|
+
|
|
28
|
+
# Compatibility shim for pyparsing 3.x where upcaseTokens was moved to pyparsing_common
|
|
29
|
+
try:
|
|
30
|
+
# pyparsing 2.x has upcaseTokens at module level
|
|
31
|
+
upcaseTokens
|
|
32
|
+
except NameError:
|
|
33
|
+
# pyparsing 3.x moved it to pyparsing_common
|
|
34
|
+
try:
|
|
35
|
+
from pyparsing import pyparsing_common
|
|
36
|
+
upcaseTokens = pyparsing_common.upcase_tokens
|
|
37
|
+
except (ImportError, AttributeError):
|
|
38
|
+
# Fallback: define our own
|
|
39
|
+
def upcaseTokens(s, loc, toks):
|
|
40
|
+
return [t.upper() for t in toks]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _set_parse_action(element, action):
|
|
44
|
+
"""Compatibility wrapper for setParseAction/set_parse_action."""
|
|
45
|
+
if hasattr(element, 'set_parse_action'):
|
|
46
|
+
return element.set_parse_action(action)
|
|
47
|
+
else:
|
|
48
|
+
return element.setParseAction(action)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _parse_string(parser, string):
|
|
52
|
+
"""Compatibility wrapper for parseString/parse_string."""
|
|
53
|
+
if hasattr(parser, 'parse_string'):
|
|
54
|
+
return parser.parse_string(string)
|
|
55
|
+
else:
|
|
56
|
+
return parser.parseString(string)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
objStack = []
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def createNode(s, loc, toks):
|
|
63
|
+
"""Create a BinNode from a parsed token."""
|
|
64
|
+
print('createNode => ', toks)
|
|
65
|
+
return BinNode(toks[0])
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# convert 'attr < value' to a binary tree based on 'or' and 'and'
|
|
69
|
+
def parseNumConditional(s, loc, toks):
|
|
70
|
+
"""Parse numeric conditional expressions."""
|
|
71
|
+
print("print: %s" % toks)
|
|
72
|
+
return BinNode(toks[0])
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def debug(s, loc, toks):
|
|
76
|
+
"""Debug helper to print tokens."""
|
|
77
|
+
print("print: %s" % toks)
|
|
78
|
+
return toks
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def markPublic(s, loc, toks):
|
|
82
|
+
"""Mark tokens as public variables."""
|
|
83
|
+
print("public: %s" % toks)
|
|
84
|
+
return toks
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def markSecret(s, loc, toks):
|
|
88
|
+
"""Mark tokens as secret variables."""
|
|
89
|
+
print("secret: %s" % toks)
|
|
90
|
+
return toks
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def pushFirst(s, loc, toks):
|
|
94
|
+
"""Push the first token onto the object stack."""
|
|
95
|
+
# print("Pushing first =>", toks[0])
|
|
96
|
+
objStack.append(toks[0])
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def createTree(op, node1, node2):
|
|
100
|
+
"""
|
|
101
|
+
Create a binary tree node for an operator.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
op: The operator string ("OR", "AND", "^", "=")
|
|
105
|
+
node1: Left child node
|
|
106
|
+
node2: Right child node
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
BinNode with the operator type and children
|
|
110
|
+
"""
|
|
111
|
+
if op == "OR":
|
|
112
|
+
node = BinNode(1)
|
|
113
|
+
elif op == "AND":
|
|
114
|
+
node = BinNode(2)
|
|
115
|
+
elif op == "^":
|
|
116
|
+
node = BinNode(3)
|
|
117
|
+
elif op == "=":
|
|
118
|
+
node = BinNode(4)
|
|
119
|
+
else:
|
|
120
|
+
return None
|
|
121
|
+
node.addSubNode(node1, node2)
|
|
122
|
+
return node
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class ZKParser:
|
|
126
|
+
"""
|
|
127
|
+
Parser for Zero-Knowledge proof statements.
|
|
128
|
+
|
|
129
|
+
Converts ZK statements into binary tree representation for processing.
|
|
130
|
+
|
|
131
|
+
Supports both single-character variables (legacy) and multi-character
|
|
132
|
+
variable names (new in v0.61).
|
|
133
|
+
|
|
134
|
+
Examples::
|
|
135
|
+
|
|
136
|
+
parser = ZKParser()
|
|
137
|
+
|
|
138
|
+
# Single-character variables (legacy, still supported)
|
|
139
|
+
result = parser.parse("h = g^x")
|
|
140
|
+
|
|
141
|
+
# Multi-character variables (new in v0.61)
|
|
142
|
+
result = parser.parse("h1 = g1^x1")
|
|
143
|
+
result = parser.parse("commitment = generator^secret")
|
|
144
|
+
|
|
145
|
+
# Complex statements
|
|
146
|
+
result = parser.parse("(h = g^x) and (j = g^y)")
|
|
147
|
+
result = parser.parse("(pk1 = g^sk1) and (pk2 = g^sk2)")
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
def __init__(self, verbose=False):
|
|
151
|
+
"""
|
|
152
|
+
Initialize the ZK parser.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
verbose: If True, print debug information during parsing
|
|
156
|
+
"""
|
|
157
|
+
self.finalPol = self.getBNF()
|
|
158
|
+
self.verbose = verbose
|
|
159
|
+
|
|
160
|
+
def getBNF(self):
|
|
161
|
+
"""
|
|
162
|
+
Build the Backus-Naur Form grammar for ZK statements.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
pyparsing grammar object
|
|
166
|
+
|
|
167
|
+
Grammar supports:
|
|
168
|
+
- Variable names: alphanumeric starting with letter (e.g., x, x1, alpha)
|
|
169
|
+
- Operators: ^, =, AND, OR
|
|
170
|
+
- Parentheses for grouping
|
|
171
|
+
"""
|
|
172
|
+
# supported operators => (OR, AND, <
|
|
173
|
+
OperatorOR = Literal("OR") | _set_parse_action(Literal("or"), upcaseTokens)
|
|
174
|
+
OperatorAND = Literal("AND") | _set_parse_action(Literal("and"), upcaseTokens)
|
|
175
|
+
lpar = Literal("(").suppress()
|
|
176
|
+
rpar = Literal(")").suppress()
|
|
177
|
+
|
|
178
|
+
ExpOp = Literal("^")
|
|
179
|
+
Equality = Literal("=") # | Literal("==") | Word("<>", max=1)
|
|
180
|
+
Token = Equality | ExpOp
|
|
181
|
+
Operator = OperatorAND | OperatorOR | Token
|
|
182
|
+
|
|
183
|
+
# describes an individual leaf node
|
|
184
|
+
# UPDATED in v0.61: Support multi-character variable names
|
|
185
|
+
# Old: Word(alphas, max=1) - only single characters like x, y, g
|
|
186
|
+
# New: Word(alphas, alphanums) - alphanumeric starting with letter
|
|
187
|
+
# Examples: x, x1, x2, alpha, beta, generator, secret
|
|
188
|
+
leafNode = _set_parse_action(Word(alphas, alphanums), createNode)
|
|
189
|
+
# describes expressions such as (attr < value)
|
|
190
|
+
# leafConditional = (Word(alphanums) + ExpOp + Word(nums)).setParseAction( parseNumConditional )
|
|
191
|
+
|
|
192
|
+
# describes the node concept
|
|
193
|
+
node = leafNode
|
|
194
|
+
# secret = variable.setParseAction( markSecret )
|
|
195
|
+
# public = variable.setParseAction( markPublic )
|
|
196
|
+
|
|
197
|
+
# expr = public + Equality + public + ExpOp + secret.setParseAction( pushFirst )
|
|
198
|
+
expr = Forward()
|
|
199
|
+
term = Forward()
|
|
200
|
+
factor = Forward()
|
|
201
|
+
atom = lpar + expr + rpar | _set_parse_action(leafNode, pushFirst)
|
|
202
|
+
|
|
203
|
+
# NEED TO UNDERSTAND THIS SEQUENCE AND WHY IT WORKS FOR PARSING ^ and = in logical order?!?
|
|
204
|
+
# Place more value on atom [ ^ factor}, so gets pushed on the stack before atom [ = factor], right?
|
|
205
|
+
# In other words, adds order of precedence to how we parse the string. This means we are parsing from right
|
|
206
|
+
# to left. a^b has precedence over b = c essentially
|
|
207
|
+
factor << atom + ZeroOrMore(_set_parse_action(ExpOp + factor, pushFirst))
|
|
208
|
+
|
|
209
|
+
term = atom + ZeroOrMore(_set_parse_action(Operator + factor, pushFirst))
|
|
210
|
+
# define placeholder set earlier with a 'term' + Operator + another term, where there can be
|
|
211
|
+
# more than zero or more of the latter. Once we find a term, we first push that into
|
|
212
|
+
# the stack, then if ther's an operand + term, then we first push the term, then the Operator.
|
|
213
|
+
# so on and so forth (follows post fix notation).
|
|
214
|
+
expr << term + ZeroOrMore(_set_parse_action(Operator + term, pushFirst))
|
|
215
|
+
# final bnf object
|
|
216
|
+
finalPol = expr#.setParseAction( debug )
|
|
217
|
+
return finalPol
|
|
218
|
+
|
|
219
|
+
# method for evaluating stack assumes operators have two operands and pops them accordingly
|
|
220
|
+
def evalStack(self, stack):
|
|
221
|
+
op = stack.pop()
|
|
222
|
+
# print("op: %s" % op)
|
|
223
|
+
if op in ["AND","OR", "^", "="]: # == "AND" or op == "OR" or op == "^" or op == "=":
|
|
224
|
+
op2 = self.evalStack(stack)
|
|
225
|
+
op1 = self.evalStack(stack)
|
|
226
|
+
return createTree(op, op1, op2)
|
|
227
|
+
# print("debug tree => ", res)
|
|
228
|
+
# return res
|
|
229
|
+
else:
|
|
230
|
+
# Node value
|
|
231
|
+
return op
|
|
232
|
+
|
|
233
|
+
# main loop for parser. 1) declare new stack, then parse the string (using defined BNF) to extract all
|
|
234
|
+
# the tokens from the string (not used for anything). 3) evaluate the stack which is in a post
|
|
235
|
+
# fix format so that we can pop an OR, AND, ^ or = nodes then pull 2 subsequent variables off the stack. Then,
|
|
236
|
+
# recursively evaluate those variables whether they are internal nodes or leaf nodes, etc.
|
|
237
|
+
def parse(self, str):
|
|
238
|
+
global objStack
|
|
239
|
+
del objStack[:]
|
|
240
|
+
tokens = _parse_string(self.finalPol, str)
|
|
241
|
+
print("stack =>", objStack)
|
|
242
|
+
return self.evalStack(objStack)
|
|
243
|
+
|
|
244
|
+
# experimental - type checking
|
|
245
|
+
def type_check(self, node, pk, sk):
|
|
246
|
+
if node.type == node.EXP:
|
|
247
|
+
print("public =>", node.getLeft(), "in pk?", pk.get(node.getLeft()))
|
|
248
|
+
print("secret =>", node.getRight(), "in sk?", sk.get(node.getRight()))
|
|
249
|
+
|
|
250
|
+
elif node.type == node.EQ:
|
|
251
|
+
print("public =>", node.getLeft(), "in pk?", pk.get(node.getLeft()))
|
|
252
|
+
self.type_check(node.getRight(), pk, sk)
|
|
253
|
+
elif node.type == node.AND:
|
|
254
|
+
self.type_check(node.getLeft(), pk, sk)
|
|
255
|
+
self.type_check(node.getRight(), pk, sk)
|
|
256
|
+
else:
|
|
257
|
+
return None
|
|
258
|
+
return None
|
|
259
|
+
|
|
260
|
+
if __name__ == "__main__":
|
|
261
|
+
print(sys.argv[1:])
|
|
262
|
+
statement = sys.argv[1]
|
|
263
|
+
|
|
264
|
+
parser = ZKParser()
|
|
265
|
+
final = parser.parse(statement)
|
|
266
|
+
print("Final statement: '%s'" % final)
|
|
267
|
+
pk = { 'g':1, 'h':2, 'j':3 }
|
|
268
|
+
sk = { 'x':4, 'y':5 }
|
|
269
|
+
parser.type_check(final, pk, sk)
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: charm-crypto-framework
|
|
3
|
+
Version: 0.61.1
|
|
4
|
+
Summary: Charm is a framework for rapid prototyping of cryptosystems
|
|
5
|
+
Home-page: https://charm-crypto.io/
|
|
6
|
+
Author: J. Ayo Akinyele
|
|
7
|
+
Author-email: "J. Ayo Akinyele" <jakinye3@jhu.edu>
|
|
8
|
+
Maintainer-email: "J. Ayo Akinyele" <jakinye3@jhu.edu>
|
|
9
|
+
License: LGPL-3.0-or-later
|
|
10
|
+
Project-URL: Homepage, https://github.com/JHUISI/charm
|
|
11
|
+
Project-URL: Documentation, https://jhuisi.github.io/charm/
|
|
12
|
+
Project-URL: Repository, https://github.com/JHUISI/charm
|
|
13
|
+
Project-URL: Issues, https://github.com/JHUISI/charm/issues
|
|
14
|
+
Project-URL: Changelog, https://github.com/JHUISI/charm/blob/dev/CHANGELOG
|
|
15
|
+
Keywords: cryptography,pairing-based cryptography,attribute-based encryption,identity-based encryption,digital signatures,elliptic curves,bilinear pairings
|
|
16
|
+
Classifier: Development Status :: 4 - Beta
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
20
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
21
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
30
|
+
Classifier: Programming Language :: C
|
|
31
|
+
Classifier: Topic :: Security :: Cryptography
|
|
32
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
33
|
+
Requires-Python: >=3.8
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
License-File: LICENSE.txt
|
|
36
|
+
Requires-Dist: pyparsing<4.0,>=2.1.5
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
39
|
+
Requires-Dist: hypothesis>=6.0; extra == "dev"
|
|
40
|
+
Requires-Dist: build; extra == "dev"
|
|
41
|
+
Requires-Dist: twine; extra == "dev"
|
|
42
|
+
Provides-Extra: docs
|
|
43
|
+
Requires-Dist: sphinx>=4.0; extra == "docs"
|
|
44
|
+
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
|
45
|
+
Dynamic: author
|
|
46
|
+
Dynamic: home-page
|
|
47
|
+
Dynamic: license
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
Dynamic: requires-python
|
|
50
|
+
|
|
51
|
+
Charm-Crypto
|
|
52
|
+
============
|
|
53
|
+
|
|
54
|
+
| Branch | Status |
|
|
55
|
+
| ----------- | --------------------------------------------------------------------------------------------------------------- |
|
|
56
|
+
| `dev` |  |
|
|
57
|
+
|
|
58
|
+
Charm is a framework for rapidly prototyping advanced cryptosystems. Based on the Python language, it was designed from the ground up to minimize development time and code complexity while promoting the reuse of components.
|
|
59
|
+
|
|
60
|
+
Charm uses a hybrid design: performance-intensive mathematical operations are implemented in native C modules, while cryptosystems themselves are written in a readable, high-level language. Charm additionally provides a number of new components to facilitate the rapid development of new schemes and protocols.
|
|
61
|
+
|
|
62
|
+
## Features
|
|
63
|
+
|
|
64
|
+
* **Mathematical Settings**: Integer rings/fields, bilinear (BN254) and non-bilinear Elliptic Curve groups
|
|
65
|
+
* **Base Crypto Library**: Symmetric encryption, hash functions, PRNGs
|
|
66
|
+
* **Standard APIs**: Digital signatures, encryption, commitments
|
|
67
|
+
* **Protocol Engine**: Simplifies multi-party protocol implementation
|
|
68
|
+
* **ZKP Compiler**: Production-ready compiler for interactive and non-interactive zero-knowledge proofs
|
|
69
|
+
- Discrete Log Equality (DLEQ) proofs
|
|
70
|
+
- Knowledge of Representation proofs
|
|
71
|
+
- AND/OR composition
|
|
72
|
+
- Range proofs
|
|
73
|
+
- Batch verification
|
|
74
|
+
* **C/C++ Embed API**: Native applications can embed Charm via the Python C API
|
|
75
|
+
* **Integrated Benchmarking**: Built-in performance measurement
|
|
76
|
+
|
|
77
|
+
## Requirements
|
|
78
|
+
|
|
79
|
+
| Component | Supported Versions |
|
|
80
|
+
|-----------|-------------------|
|
|
81
|
+
| **Python** | 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14 |
|
|
82
|
+
| **Operating Systems** | Linux, macOS, Windows |
|
|
83
|
+
| **OpenSSL** | 3.0+ |
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
### Quick Install (pip)
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pip install charm-crypto-framework
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> **Note:** System libraries (GMP, PBC, OpenSSL) must be installed first. See [Prerequisites](#prerequisites) below.
|
|
94
|
+
|
|
95
|
+
### Prerequisites
|
|
96
|
+
|
|
97
|
+
Charm requires the following system libraries:
|
|
98
|
+
|
|
99
|
+
| Library | Version | Purpose |
|
|
100
|
+
|---------|---------|---------|
|
|
101
|
+
| [GMP](http://gmplib.org/) | 5.0+ | Arbitrary precision arithmetic |
|
|
102
|
+
| [PBC](http://crypto.stanford.edu/pbc/download.html) | 1.0.0 | Pairing-based cryptography |
|
|
103
|
+
| [OpenSSL](http://www.openssl.org/source/) | 3.0+ | Cryptographic primitives |
|
|
104
|
+
|
|
105
|
+
**Ubuntu/Debian:**
|
|
106
|
+
```bash
|
|
107
|
+
sudo apt-get install libgmp-dev libssl-dev libpbc-dev flex bison
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**macOS (Homebrew):**
|
|
111
|
+
```bash
|
|
112
|
+
brew install gmp openssl@3 pbc
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**PBC from Source** (if not available via package manager):
|
|
116
|
+
```bash
|
|
117
|
+
wget https://crypto.stanford.edu/pbc/files/pbc-1.0.0.tar.gz
|
|
118
|
+
tar xzf pbc-1.0.0.tar.gz
|
|
119
|
+
cd pbc-1.0.0
|
|
120
|
+
./configure && make && sudo make install
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### From Source (Development)
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
git clone https://github.com/JHUISI/charm.git
|
|
127
|
+
cd charm
|
|
128
|
+
./configure.sh # add --enable-darwin on macOS
|
|
129
|
+
pip install -e ".[dev]"
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Verify Installation
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
python -c "from charm.toolbox.pairinggroup import PairingGroup; print('Charm installed successfully\!')"
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Testing
|
|
139
|
+
|
|
140
|
+
Charm includes comprehensive test suites:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Run all tests
|
|
144
|
+
make test-all
|
|
145
|
+
|
|
146
|
+
# Run specific test categories
|
|
147
|
+
make test-unit # Unit tests (toolbox, serialize, vectors)
|
|
148
|
+
make test-schemes # Cryptographic scheme tests
|
|
149
|
+
make test-zkp # ZKP compiler tests
|
|
150
|
+
make test-adapters # Adapter tests
|
|
151
|
+
make test-embed # C/C++ embed API tests
|
|
152
|
+
|
|
153
|
+
# Threshold ECDSA (DKLS23) tests
|
|
154
|
+
pytest charm/test/schemes/threshold_test.py -v
|
|
155
|
+
|
|
156
|
+
# Run with coverage
|
|
157
|
+
pytest --cov=charm charm/test/ -v
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Documentation
|
|
161
|
+
|
|
162
|
+
* [Installation Guide](https://jhuisi.github.io/charm/install_source.html)
|
|
163
|
+
* [Scheme Examples](https://jhuisi.github.io/charm/schemes.html)
|
|
164
|
+
* [API Reference](https://jhuisi.github.io/charm/)
|
|
165
|
+
* [C/C++ Embed API](embed/README.md)
|
|
166
|
+
|
|
167
|
+
## Quick Examples
|
|
168
|
+
|
|
169
|
+
### BLS Signatures (Pairing-Based)
|
|
170
|
+
|
|
171
|
+
BLS signatures (Boneh-Lynn-Shacham) — standardized in [IETF RFC 9380](https://datatracker.ietf.org/doc/rfc9380/) and used in Ethereum 2.0:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from charm.toolbox.pairinggroup import PairingGroup
|
|
175
|
+
from charm.schemes.pksig.pksig_bls04 import BLS01
|
|
176
|
+
|
|
177
|
+
# Initialize pairing group (BN254 curve, ~128-bit security)
|
|
178
|
+
group = PairingGroup('BN254')
|
|
179
|
+
bls = BLS01(group)
|
|
180
|
+
|
|
181
|
+
# Ethereum 2.0 validator attestation
|
|
182
|
+
attestation = {'slot': 1234, 'epoch': 38, 'beacon_block_root': '0xabc...'}
|
|
183
|
+
|
|
184
|
+
(pk, sk) = bls.keygen()
|
|
185
|
+
signature = bls.sign(sk['x'], attestation)
|
|
186
|
+
assert bls.verify(pk, signature, attestation)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### ECDSA with secp256k1 (Bitcoin)
|
|
190
|
+
|
|
191
|
+
ECDSA on secp256k1 — the curve used by Bitcoin ([SEC 2](https://www.secg.org/sec2-v2.pdf), [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki)):
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
import hashlib
|
|
195
|
+
import json
|
|
196
|
+
from charm.toolbox.ecgroup import ECGroup
|
|
197
|
+
from charm.toolbox.eccurve import secp256k1
|
|
198
|
+
from charm.schemes.pksig.pksig_ecdsa import ECDSA
|
|
199
|
+
|
|
200
|
+
group = ECGroup(secp256k1)
|
|
201
|
+
ecdsa = ECDSA(group)
|
|
202
|
+
|
|
203
|
+
# Bitcoin transaction (simplified)
|
|
204
|
+
tx = {
|
|
205
|
+
'inputs': [{'txid': 'a1b2c3...', 'vout': 0, 'address': '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'}],
|
|
206
|
+
'outputs': [{'address': '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy', 'satoshis': 50000}],
|
|
207
|
+
'fee': 1000
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
# Serialize and double SHA-256 (SHA-256d) per Bitcoin protocol
|
|
211
|
+
tx_bytes = json.dumps(tx, sort_keys=True).encode('utf-8')
|
|
212
|
+
tx_hash = hashlib.sha256(hashlib.sha256(tx_bytes).digest()).hexdigest()
|
|
213
|
+
|
|
214
|
+
(pk, sk) = ecdsa.keygen(0)
|
|
215
|
+
signature = ecdsa.sign(pk, sk, tx_hash)
|
|
216
|
+
assert ecdsa.verify(pk, signature, tx_hash)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
> **Note:** Production Bitcoin implementations should use proper transaction serialization
|
|
220
|
+
> per [Bitcoin Developer Documentation](https://developer.bitcoin.org/reference/transactions.html).
|
|
221
|
+
|
|
222
|
+
### ECDSA with secp256k1 (XRPL)
|
|
223
|
+
|
|
224
|
+
ECDSA on secp256k1 — also used by XRP Ledger ([SEC 2](https://www.secg.org/sec2-v2.pdf)):
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
import hashlib
|
|
228
|
+
import json
|
|
229
|
+
from charm.toolbox.ecgroup import ECGroup
|
|
230
|
+
from charm.toolbox.eccurve import secp256k1
|
|
231
|
+
from charm.schemes.pksig.pksig_ecdsa import ECDSA
|
|
232
|
+
|
|
233
|
+
group = ECGroup(secp256k1)
|
|
234
|
+
ecdsa = ECDSA(group)
|
|
235
|
+
|
|
236
|
+
# XRPL Payment transaction
|
|
237
|
+
tx = {
|
|
238
|
+
'TransactionType': 'Payment',
|
|
239
|
+
'Account': 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
|
240
|
+
'Destination': 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe',
|
|
241
|
+
'Amount': '1000000', # drops of XRP
|
|
242
|
+
'Sequence': 1
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
# Serialize and hash (XRPL uses canonical binary + SHA-512Half)
|
|
246
|
+
tx_bytes = json.dumps(tx, sort_keys=True).encode('utf-8')
|
|
247
|
+
tx_hash = hashlib.sha512(tx_bytes).hexdigest()[:64] # SHA-512Half
|
|
248
|
+
|
|
249
|
+
(pk, sk) = ecdsa.keygen(0)
|
|
250
|
+
signature = ecdsa.sign(pk, sk, tx_hash)
|
|
251
|
+
assert ecdsa.verify(pk, signature, tx_hash)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
> **Note:** Production XRPL implementations should use canonical binary serialization
|
|
255
|
+
> per [XRPL documentation](https://xrpl.org/serialization.html).
|
|
256
|
+
|
|
257
|
+
### Threshold ECDSA (DKLS23) with XRPL testnet
|
|
258
|
+
|
|
259
|
+
Charm also includes a threshold ECDSA scheme based on DKLS23, together with an XRPL
|
|
260
|
+
testnet demo that shows how to use it end to end.
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
from charm.toolbox.eccurve import secp256k1
|
|
264
|
+
from charm.toolbox.ecgroup import ECGroup
|
|
265
|
+
from charm.core.math.elliptic_curve import G
|
|
266
|
+
from charm.schemes.threshold.dkls23_sign import DKLS23
|
|
267
|
+
from charm.schemes.threshold.xrpl_wallet import (
|
|
268
|
+
XRPLThresholdWallet,
|
|
269
|
+
XRPLClient,
|
|
270
|
+
sign_xrpl_transaction,
|
|
271
|
+
create_payment_with_memo,
|
|
272
|
+
get_secp256k1_generator,
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
group = ECGroup(secp256k1)
|
|
276
|
+
dkls = DKLS23(group, threshold=2, num_parties=3)
|
|
277
|
+
g = get_secp256k1_generator(group)
|
|
278
|
+
key_shares, public_key = dkls.distributed_keygen(g)
|
|
279
|
+
wallet = XRPLThresholdWallet(group, public_key)
|
|
280
|
+
client = XRPLClient(is_testnet=True)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
See `examples/xrpl_memo_demo.py` for a complete XRPL testnet flow (fund account, create
|
|
284
|
+
threshold wallet, send payment with memo).
|
|
285
|
+
|
|
286
|
+
## Schemes
|
|
287
|
+
|
|
288
|
+
Charm includes implementations of many cryptographic schemes:
|
|
289
|
+
|
|
290
|
+
| Category | Examples |
|
|
291
|
+
|----------|----------|
|
|
292
|
+
| **ABE** | CP-ABE (BSW07), KP-ABE, FAME |
|
|
293
|
+
| **IBE** | Waters05, BB04 |
|
|
294
|
+
| **Signatures** | BLS, Waters, CL04 |
|
|
295
|
+
| **Commitments** | Pedersen |
|
|
296
|
+
| **Group Signatures** | BBS+, PS16 |
|
|
297
|
+
|
|
298
|
+
See the [schemes directory](charm/schemes/) for all available implementations.
|
|
299
|
+
|
|
300
|
+
## Contributing
|
|
301
|
+
|
|
302
|
+
We welcome contributions\! Please note:
|
|
303
|
+
|
|
304
|
+
* All schemes must include doctests for inclusion in `make test`
|
|
305
|
+
* Follow the existing code style
|
|
306
|
+
* Add tests for new functionality
|
|
307
|
+
* Update documentation as needed
|
|
308
|
+
|
|
309
|
+
## Security
|
|
310
|
+
|
|
311
|
+
Charm uses the BN254 curve which provides approximately **128-bit security**. For production use:
|
|
312
|
+
|
|
313
|
+
* Keep dependencies updated
|
|
314
|
+
* Use the production-ready ZKP compiler (not the legacy `exec()`-based version)
|
|
315
|
+
* Review scheme implementations for your specific security requirements
|
|
316
|
+
|
|
317
|
+
## Support
|
|
318
|
+
|
|
319
|
+
* **Issues**: [GitHub Issues](https://github.com/JHUISI/charm/issues)
|
|
320
|
+
* **Email**: jakinye3@jhu.edu
|
|
321
|
+
|
|
322
|
+
## License
|
|
323
|
+
|
|
324
|
+
Charm is released under the **LGPL version 3** license. See [LICENSE.txt](LICENSE.txt) for details.
|
|
325
|
+
|
|
326
|
+
## Citation
|
|
327
|
+
|
|
328
|
+
If you use Charm in academic work, please cite:
|
|
329
|
+
|
|
330
|
+
```bibtex
|
|
331
|
+
@article{charm,
|
|
332
|
+
author = {Akinyele, Joseph A. and Garman, Christina and Miers, Ian and Pagano, Matthew W. and Rushanan, Michael and Green, Matthew and Rubin, Aviel D.},
|
|
333
|
+
title = {Charm: A Framework for Rapidly Prototyping Cryptosystems},
|
|
334
|
+
journal = {Journal of Cryptographic Engineering},
|
|
335
|
+
year = {2013}
|
|
336
|
+
}
|
|
337
|
+
```
|