├── .gitignore ├── Charm ├── CHANGELOG ├── Charm_Crypto.egg-info │ ├── PKG-INFO │ ├── SOURCES.txt │ ├── dependency_links.txt │ ├── requires.txt │ └── top_level.txt ├── INSTALL ├── MANIFEST.in ├── Makefile ├── PKG-INFO ├── README ├── VERSION ├── __init__.py ├── build │ ├── lib.macosx-10.6-intel-2.7 │ │ └── charm │ │ │ ├── __init__.py │ │ │ ├── adapters │ │ │ ├── __init__.py │ │ │ ├── abenc_adapt_hybrid.py │ │ │ ├── dabenc_adapt_hybrid.py │ │ │ ├── ibenc_adapt_hybrid.py │ │ │ ├── ibenc_adapt_identityhash.py │ │ │ ├── kpabenc_adapt_hybrid.py │ │ │ ├── pkenc_adapt_bchk05.py │ │ │ ├── pkenc_adapt_chk04.py │ │ │ ├── pkenc_adapt_hybrid.py │ │ │ └── pksig_adapt_naor01.py │ │ │ ├── core │ │ │ ├── __init__.py │ │ │ ├── benchmark.so │ │ │ ├── crypto │ │ │ │ ├── AES.so │ │ │ │ ├── DES.so │ │ │ │ ├── DES3.so │ │ │ │ ├── __init__.py │ │ │ │ └── cryptobase.so │ │ │ ├── engine │ │ │ │ ├── __init__.py │ │ │ │ ├── protocol.py │ │ │ │ └── util.py │ │ │ └── math │ │ │ │ ├── __init__.py │ │ │ │ ├── elliptic_curve.so │ │ │ │ ├── integer.so │ │ │ │ └── pairing.so │ │ │ ├── schemes │ │ │ ├── __init__.py │ │ │ ├── abenc │ │ │ │ ├── __init__.py │ │ │ │ ├── abenc_bsw07.py │ │ │ │ ├── abenc_lsw08.py │ │ │ │ └── abenc_waters09.py │ │ │ ├── chamhash_adm05.py │ │ │ ├── chamhash_rsa_hw09.py │ │ │ ├── commit │ │ │ │ ├── __init__.py │ │ │ │ ├── commit_gs08.py │ │ │ │ └── commit_pedersen92.py │ │ │ ├── dabe_aw11.py │ │ │ ├── encap_bchk05.py │ │ │ ├── grpsig │ │ │ │ ├── __init__.py │ │ │ │ ├── groupsig_bgls04.py │ │ │ │ └── groupsig_bgls04_var.py │ │ │ ├── hibenc │ │ │ │ ├── __init__.py │ │ │ │ └── hibenc_bb04.py │ │ │ ├── ibenc │ │ │ │ ├── __init__.py │ │ │ │ ├── ibenc_bb03.py │ │ │ │ ├── ibenc_bf01.py │ │ │ │ ├── ibenc_ckrs09.py │ │ │ │ ├── ibenc_lsw08.py │ │ │ │ ├── ibenc_sw05.py │ │ │ │ ├── ibenc_waters05.py │ │ │ │ └── ibenc_waters09.py │ │ │ ├── pk_vrf.py │ │ │ ├── pkenc │ │ │ │ ├── __init__.py │ │ │ │ ├── pkenc_cs98.py │ │ │ │ ├── pkenc_elgamal85.py │ │ │ │ ├── pkenc_paillier99.py │ │ │ │ ├── pkenc_rabin.py │ │ │ │ └── pkenc_rsa.py │ │ │ ├── pksig │ │ │ │ ├── __init__.py │ │ │ │ ├── pksig_bls04.py │ │ │ │ ├── pksig_boyen.py │ │ │ │ ├── pksig_chch.py │ │ │ │ ├── pksig_chp.py │ │ │ │ ├── pksig_cl03.py │ │ │ │ ├── pksig_cl04.py │ │ │ │ ├── pksig_cyh.py │ │ │ │ ├── pksig_dsa.py │ │ │ │ ├── pksig_ecdsa.py │ │ │ │ ├── pksig_hess.py │ │ │ │ ├── pksig_hw.py │ │ │ │ ├── pksig_rsa_hw09.py │ │ │ │ ├── pksig_schnorr91.py │ │ │ │ ├── pksig_waters.py │ │ │ │ ├── pksig_waters05.py │ │ │ │ └── pksig_waters09.py │ │ │ ├── protocol_cns07.py │ │ │ ├── protocol_schnorr91.py │ │ │ ├── sigma1.py │ │ │ ├── sigma2.py │ │ │ └── sigma3.py │ │ │ ├── test │ │ │ ├── __init__.py │ │ │ ├── schemes │ │ │ │ ├── __init__.py │ │ │ │ ├── abenc_test.py │ │ │ │ ├── chamhash_test.py │ │ │ │ ├── commit_test.py │ │ │ │ ├── dabenc_test.py │ │ │ │ ├── encap_bchk05_test.py │ │ │ │ ├── grpsig_test.py │ │ │ │ ├── hibenc_test.py │ │ │ │ ├── ibenc_test.py │ │ │ │ ├── pk_vrf_test.py │ │ │ │ ├── pkenc_test.py │ │ │ │ ├── pksig_test.py │ │ │ │ └── rsa_alg_test.py │ │ │ └── toolbox │ │ │ │ ├── __init__.py │ │ │ │ ├── conversion_test.py │ │ │ │ ├── paddingschemes_test.py │ │ │ │ ├── secretshare_test.py │ │ │ │ └── symcrypto_test.py │ │ │ ├── toolbox │ │ │ ├── ABEnc.py │ │ │ ├── ABEncMultiAuth.py │ │ │ ├── Commit.py │ │ │ ├── Hash.py │ │ │ ├── IBEnc.py │ │ │ ├── PKEnc.py │ │ │ ├── PKSig.py │ │ │ ├── __init__.py │ │ │ ├── bitstring.py │ │ │ ├── conversion.py │ │ │ ├── eccurve.py │ │ │ ├── ecgroup.py │ │ │ ├── enum.py │ │ │ ├── hash_module.py │ │ │ ├── integergroup.py │ │ │ ├── iterate.py │ │ │ ├── node.py │ │ │ ├── paddingschemes.py │ │ │ ├── paddingschemes_test.py │ │ │ ├── pairingcurves.py │ │ │ ├── pairinggroup.py │ │ │ ├── policytree.py │ │ │ ├── redundancyschemes.py │ │ │ ├── schemebase.py │ │ │ ├── secretshare.py │ │ │ ├── secretutil.py │ │ │ ├── securerandom.py │ │ │ ├── serialize.py │ │ │ ├── sigmaprotocol.py │ │ │ ├── specialprimes.py │ │ │ ├── symcrypto.py │ │ │ └── zknode.py │ │ │ └── zkp_compiler │ │ │ ├── __init__.py │ │ │ ├── zk_demo.py │ │ │ ├── zkp_generator.py │ │ │ └── zkparser.py │ └── temp.macosx-10.6-intel-2.7 │ │ └── charm │ │ └── core │ │ ├── benchmark │ │ └── benchmarkmodule.o │ │ ├── crypto │ │ ├── AES │ │ │ └── AES.o │ │ ├── DES │ │ │ └── DES.o │ │ ├── DES3 │ │ │ └── DES3.o │ │ └── cryptobase │ │ │ └── cryptobasemodule.o │ │ ├── math │ │ ├── elliptic_curve │ │ │ └── ecmodule.o │ │ ├── integer │ │ │ └── integermodule.o │ │ └── pairing │ │ │ └── pairingmodule.o │ │ └── utilities │ │ ├── base64.o │ │ └── sha1.o ├── charm │ ├── __init__.py │ ├── adapters │ │ ├── __init__.py │ │ ├── abenc_adapt_hybrid.py │ │ ├── dabenc_adapt_hybrid.py │ │ ├── ibenc_adapt_hybrid.py │ │ ├── ibenc_adapt_identityhash.py │ │ ├── kpabenc_adapt_hybrid.py │ │ ├── pkenc_adapt_bchk05.py │ │ ├── pkenc_adapt_chk04.py │ │ ├── pkenc_adapt_hybrid.py │ │ └── pksig_adapt_naor01.py │ ├── core │ │ ├── __init__.py │ │ ├── benchmark.so │ │ ├── benchmark │ │ │ ├── benchmarkmodule.c │ │ │ └── benchmarkmodule.h │ │ ├── crypto │ │ │ ├── AES.so │ │ │ ├── AES │ │ │ │ └── AES.c │ │ │ ├── DES.so │ │ │ ├── DES │ │ │ │ └── DES.c │ │ │ ├── DES3.so │ │ │ ├── DES3 │ │ │ │ └── DES3.c │ │ │ ├── __init__.py │ │ │ ├── cryptobase.so │ │ │ └── cryptobase │ │ │ │ ├── XOR.c │ │ │ │ ├── _counter.c │ │ │ │ ├── _counter.h │ │ │ │ ├── block_template.c │ │ │ │ ├── block_template.h │ │ │ │ ├── cryptobasemodule.c │ │ │ │ ├── libtom │ │ │ │ ├── tomcrypt.h │ │ │ │ ├── tomcrypt_argchk.h │ │ │ │ ├── tomcrypt_cfg.h │ │ │ │ ├── tomcrypt_cipher.h │ │ │ │ ├── tomcrypt_custom.h │ │ │ │ ├── tomcrypt_des.c │ │ │ │ ├── tomcrypt_hash.h │ │ │ │ ├── tomcrypt_mac.h │ │ │ │ ├── tomcrypt_macros.h │ │ │ │ ├── tomcrypt_math.h │ │ │ │ ├── tomcrypt_misc.h │ │ │ │ ├── tomcrypt_pk.h │ │ │ │ ├── tomcrypt_pkcs.h │ │ │ │ └── tomcrypt_prng.h │ │ │ │ ├── stream_template.c │ │ │ │ └── strxor.c │ │ ├── engine │ │ │ ├── __init__.py │ │ │ ├── protocol.py │ │ │ └── util.py │ │ ├── math │ │ │ ├── __init__.py │ │ │ ├── elliptic_curve.so │ │ │ ├── elliptic_curve │ │ │ │ ├── ecmodule.c │ │ │ │ └── ecmodule.h │ │ │ ├── integer.so │ │ │ ├── integer │ │ │ │ ├── integermodule.c │ │ │ │ └── integermodule.h │ │ │ ├── pairing.so │ │ │ └── pairing │ │ │ │ ├── miracl │ │ │ │ ├── miracl_interface.h │ │ │ │ ├── pairingmodule2.c │ │ │ │ └── pairingmodule2.h │ │ │ │ ├── pairingmodule.c │ │ │ │ ├── pairingmodule.h │ │ │ │ └── relic │ │ │ │ ├── pairingmodule3.c │ │ │ │ ├── pairingmodule3.h │ │ │ │ ├── relic_interface.c │ │ │ │ ├── relic_interface.h │ │ │ │ └── test_relic.c │ │ └── utilities │ │ │ ├── base64.c │ │ │ ├── base64.h │ │ │ ├── sha1.c │ │ │ └── sha1.h │ ├── schemes │ │ ├── __init__.py │ │ ├── abenc │ │ │ ├── __init__.py │ │ │ ├── abenc_bsw07.py │ │ │ ├── abenc_lsw08.py │ │ │ └── abenc_waters09.py │ │ ├── chamhash_adm05.py │ │ ├── chamhash_rsa_hw09.py │ │ ├── commit │ │ │ ├── __init__.py │ │ │ ├── commit_gs08.py │ │ │ └── commit_pedersen92.py │ │ ├── dabe_aw11.py │ │ ├── encap_bchk05.py │ │ ├── grpsig │ │ │ ├── __init__.py │ │ │ ├── groupsig_bgls04.py │ │ │ └── groupsig_bgls04_var.py │ │ ├── hibenc │ │ │ ├── __init__.py │ │ │ └── hibenc_bb04.py │ │ ├── ibenc │ │ │ ├── __init__.py │ │ │ ├── ibenc_bb03.py │ │ │ ├── ibenc_bf01.py │ │ │ ├── ibenc_ckrs09.py │ │ │ ├── ibenc_lsw08.py │ │ │ ├── ibenc_sw05.py │ │ │ ├── ibenc_waters05.py │ │ │ └── ibenc_waters09.py │ │ ├── pk_vrf.py │ │ ├── pkenc │ │ │ ├── __init__.py │ │ │ ├── pkenc_cs98.py │ │ │ ├── pkenc_elgamal85.py │ │ │ ├── pkenc_paillier99.py │ │ │ ├── pkenc_rabin.py │ │ │ └── pkenc_rsa.py │ │ ├── pksig │ │ │ ├── __init__.py │ │ │ ├── pksig_bls04.py │ │ │ ├── pksig_boyen.py │ │ │ ├── pksig_chch.py │ │ │ ├── pksig_chp.py │ │ │ ├── pksig_cl03.py │ │ │ ├── pksig_cl04.py │ │ │ ├── pksig_cyh.py │ │ │ ├── pksig_dsa.py │ │ │ ├── pksig_ecdsa.py │ │ │ ├── pksig_hess.py │ │ │ ├── pksig_hw.py │ │ │ ├── pksig_rsa_hw09.py │ │ │ ├── pksig_schnorr91.py │ │ │ ├── pksig_waters.py │ │ │ ├── pksig_waters05.py │ │ │ └── pksig_waters09.py │ │ ├── protocol_cns07.py │ │ ├── protocol_schnorr91.py │ │ ├── sigma1.py │ │ ├── sigma2.py │ │ └── sigma3.py │ ├── test │ │ ├── __init__.py │ │ ├── schemes │ │ │ ├── __init__.py │ │ │ ├── abenc_test.py │ │ │ ├── chamhash_test.py │ │ │ ├── commit_test.py │ │ │ ├── dabenc_test.py │ │ │ ├── encap_bchk05_test.py │ │ │ ├── grpsig_test.py │ │ │ ├── hibenc_test.py │ │ │ ├── ibenc_test.py │ │ │ ├── pk_vrf_test.py │ │ │ ├── pkenc_test.py │ │ │ ├── pksig_test.py │ │ │ └── rsa_alg_test.py │ │ └── toolbox │ │ │ ├── __init__.py │ │ │ ├── conversion_test.py │ │ │ ├── paddingschemes_test.py │ │ │ ├── secretshare_test.py │ │ │ └── symcrypto_test.py │ ├── toolbox │ │ ├── ABEnc.py │ │ ├── ABEncMultiAuth.py │ │ ├── Commit.py │ │ ├── Hash.py │ │ ├── IBEnc.py │ │ ├── PKEnc.py │ │ ├── PKSig.py │ │ ├── __init__.py │ │ ├── bitstring.py │ │ ├── conversion.py │ │ ├── eccurve.py │ │ ├── ecgroup.py │ │ ├── enum.py │ │ ├── hash_module.py │ │ ├── integergroup.py │ │ ├── iterate.py │ │ ├── node.py │ │ ├── paddingschemes.py │ │ ├── paddingschemes_test.py │ │ ├── pairingcurves.py │ │ ├── pairinggroup.py │ │ ├── policytree.py │ │ ├── redundancyschemes.py │ │ ├── schemebase.py │ │ ├── secretshare.py │ │ ├── secretutil.py │ │ ├── securerandom.py │ │ ├── serialize.py │ │ ├── sigmaprotocol.py │ │ ├── specialprimes.py │ │ ├── symcrypto.py │ │ └── zknode.py │ └── zkp_compiler │ │ ├── __init__.py │ │ ├── zk_demo.py │ │ ├── zkp_generator.py │ │ └── zkparser.py ├── config.log ├── config.mk ├── configure.sh ├── dist │ └── Charm_Crypto-0.42-py2.7-macosx-10.6-intel.egg ├── distribute_setup.py ├── doc │ ├── Makefile │ ├── autoschemes.py │ ├── config.py │ └── source │ │ ├── conf.py │ │ ├── cryptographers.rst │ │ ├── developers.rst │ │ ├── index.rst │ │ ├── install_source.rst │ │ ├── miracl.rst │ │ ├── mobile.rst │ │ ├── sample.rst │ │ ├── schemes.rst │ │ ├── todo.rst │ │ ├── toolbox.rst │ │ └── tutorial.rst ├── pytest.ini ├── setup.cfg └── setup.py ├── Procfile ├── README.md ├── abescheme ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py ├── manage.py ├── privacy.db ├── privacy ├── __init__.py ├── admin.py ├── form.py ├── models.py ├── templates │ ├── authority.html │ ├── index.html │ └── policy.html ├── tests.py ├── urls.py └── views.py ├── requirements.txt ├── thesisOutline.txt └── writeup ├── authority3.png ├── authoritydb.png ├── finalwriteup.aux ├── finalwriteup.log ├── finalwriteup.pdf ├── finalwriteup.synctex.gz ├── finalwriteup.tex ├── policy.png ├── policy2.png ├── policycreation.png ├── policydiagram.pdf └── posteddata.png /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | venv -------------------------------------------------------------------------------- /Charm/CHANGELOG: -------------------------------------------------------------------------------- 1 | v0.42 beta release (infrastructure changes) 2 | ------------------------------------------- 3 | - Several bug fixes to base modules (mem leaks, interface issues): pairing (PBC & Miracl), ecc, and integer 4 | - Added new base module for RELIC and fixed bugs for MIRACL (Note: unified abstract interface for base modules coming in v0.43) 5 | - Refactored charm package structure. This affects schemes, toolbox, adapters, etc. 6 | - setup.py now creates Python egg 7 | - Integrated pytest to replace unit testing framework 8 | - Added doctests to all Charm schemes 9 | - Updated documentation 10 | 11 | v0.4 beta release 12 | ----------------- 13 | - Several bug fixes to base modules: pairing (PBC & Miracl), ecc, and integer 14 | - Major changes to base module API. Recommend using the group abstraction wrappers: PairingGroup, ECGroup, and IntegerGroup 15 | - Removed pairing curve params in favor of a unified 'toolbox/pairingcurve.py' with curve identifiers (e.g., SS512, MNT224, etc) 16 | - Deleted the 'params' dir (See previous bullet) 17 | - Added high-level serialization API to simplify managing ciphertexts and keys in applications 18 | - Added PKCS #7 padding to toolbox 19 | - Added public key encryption schemes: 2 new IBE schemes (ibenc_ckrs09, ibenc_lsw08) 20 | - Added signature schemes: CL04 (anony. creds) 21 | - Added verifiable random function (VRF) scheme 22 | - Updates to KPABE scheme with new adapter 23 | - Improved protocol engine: automatically store data transmitted between parties and more flexibility in state transition map 24 | - Updated CNS07 scheme 25 | - Name updates to authenticated crypto abstraction 26 | - Updated documentation for generating group parameters and using our serialization interface 27 | -------------------------------------------------------------------------------- /Charm/Charm_Crypto.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.0 2 | Name: Charm-Crypto 3 | Version: 0.42 4 | Summary: Charm is a framework for rapid prototyping of cryptosystems 5 | Home-page: http://charm-crypto.com/ 6 | Author: J. Ayo Akinyele 7 | Author-email: ayo.akinyele@charm-crypto.com 8 | License: LGPL 9 | Description: UNKNOWN 10 | Platform: UNKNOWN 11 | -------------------------------------------------------------------------------- /Charm/Charm_Crypto.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Charm/Charm_Crypto.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | setuptools 2 | pyparsing >= 1.5.5 -------------------------------------------------------------------------------- /Charm/Charm_Crypto.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | charm 2 | -------------------------------------------------------------------------------- /Charm/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include VERSION README INSTALL configure.sh Makefile CHANGELOG setup.cfg 2 | graft doc 3 | graft doc/source 4 | recursive-include charm *.h *.c *.py 5 | include distribute_setup.py pytest.ini 6 | -------------------------------------------------------------------------------- /Charm/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.0 2 | Name: Charm-Crypto 3 | Version: 0.42 4 | Summary: Charm is a framework for rapid prototyping of cryptosystems 5 | Home-page: http://charm-crypto.com/ 6 | Author: J. Ayo Akinyele 7 | Author-email: ayo.akinyele@charm-crypto.com 8 | License: LGPL 9 | Description: UNKNOWN 10 | Platform: UNKNOWN 11 | -------------------------------------------------------------------------------- /Charm/README: -------------------------------------------------------------------------------- 1 | Charm 2 | ----- 3 | 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. 4 | 5 | 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. 6 | 7 | Features of Charm include: 8 | □ Support for various mathematical settings, including integer rings/fields, bilinear and non-bilinear Elliptic Curve groups 9 | □ Base crypto library, including symmetric encryption schemes, hash functions, PRNGs 10 | □ Standard APIs for constructions such as digital signature, encryption, commitments 11 | □ A “protocol engine” to simplify the process of implementing multi-party protocols 12 | □ An integrated compiler for interactive and non-interactive ZK proofs 13 | □ Integrated benchmarking capability 14 | 15 | Charm Documentation 16 | ------------------- 17 | For complete install docs see http://jhuisi.github.com/charm/install_source.html 18 | 19 | Schemes 20 | ------- 21 | We have provided several cryptographic scheme examples to get you going. See http://jhuisi.github.com/charm/schemes.html 22 | -------------------------------------------------------------------------------- /Charm/VERSION: -------------------------------------------------------------------------------- 1 | 0.42 -------------------------------------------------------------------------------- /Charm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/__init__.py: -------------------------------------------------------------------------------- 1 | # This fixes an issue where certain python interpeters/operating systems 2 | # fail to properly load shared modules that c extensions depend on. 3 | # In this case, the benchmark module is not handeled properly on osx 4 | # as such we import it preimptively to force its symbols to be loaded. 5 | import charm.core.benchmark 6 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/adapters/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/adapters/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/adapters/abenc_adapt_hybrid.py: -------------------------------------------------------------------------------- 1 | 2 | from charm.toolbox.ABEnc import ABEnc 3 | from charm.schemes.abenc.abenc_bsw07 import CPabe_BSW07 4 | from charm.toolbox.pairinggroup import PairingGroup,GT 5 | from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction 6 | from charm.core.math.pairing import hashPair as sha1 7 | from math import ceil 8 | 9 | debug = False 10 | class HybridABEnc(ABEnc): 11 | """ 12 | >>> group = PairingGroup("SS512") 13 | >>> cpabe = CPabe_BSW07(group) 14 | >>> hyb_abe = HybridABEnc(cpabe, group) 15 | >>> access_policy = '((four or three) and (two or one))' 16 | >>> msg = "hello world this is an important message." 17 | >>> (master_public_key, master_key) = hyb_abe.setup() 18 | >>> secret_key = hyb_abe.keygen(master_public_key, master_key, ['ONE', 'TWO', 'THREE']) 19 | >>> cipher_text = hyb_abe.encrypt(master_public_key, msg, access_policy) 20 | >>> hyb_abe.decrypt(master_public_key, secret_key, cipher_text) 21 | 'hello world this is an important message.' 22 | """ 23 | def __init__(self, scheme, groupObj): 24 | ABEnc.__init__(self) 25 | global abenc 26 | # check properties (TODO) 27 | abenc = scheme 28 | self.group = groupObj 29 | 30 | def setup(self): 31 | return abenc.setup() 32 | 33 | def keygen(self, pk, mk, object): 34 | return abenc.keygen(pk, mk, object) 35 | 36 | def encrypt(self, pk, M, object): 37 | key = self.group.random(GT) 38 | c1 = abenc.encrypt(pk, key, object) 39 | # instantiate a symmetric enc scheme from this key 40 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 41 | c2 = cipher.encrypt(M) 42 | return { 'c1':c1, 'c2':c2 } 43 | 44 | def decrypt(self, pk, sk, ct): 45 | c1, c2 = ct['c1'], ct['c2'] 46 | key = abenc.decrypt(pk, sk, c1) 47 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 48 | return cipher.decrypt(c2) 49 | 50 | def main(): 51 | groupObj = PairingGroup('SS512') 52 | cpabe = CPabe_BSW07(groupObj) 53 | hyb_abe = HybridABEnc(cpabe, groupObj) 54 | access_policy = '((four or three) and (two or one))' 55 | message = b"hello world this is an important message." 56 | (pk, mk) = hyb_abe.setup() 57 | if debug: print("pk => ", pk) 58 | if debug: print("mk => ", mk) 59 | sk = hyb_abe.keygen(pk, mk, ['ONE', 'TWO', 'THREE']) 60 | if debug: print("sk => ", sk) 61 | ct = hyb_abe.encrypt(pk, message, access_policy) 62 | mdec = hyb_abe.decrypt(pk, sk, ct) 63 | assert mdec == message, "Failed Decryption!!!" 64 | if debug: print("Successful Decryption!!!") 65 | 66 | if __name__ == "__main__": 67 | debug = True 68 | main() 69 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/adapters/ibenc_adapt_hybrid.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction 2 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair 3 | from charm.core.math.pairing import hashPair as sha1 4 | from charm.adapters.ibenc_adapt_identityhash import HashIDAdapter 5 | from charm.toolbox.IBEnc import IBEnc 6 | from charm.core.crypto.cryptobase import * 7 | 8 | debug = False 9 | class HybridIBEnc(IBEnc): 10 | """ 11 | >>> from charm.schemes.ibenc.ibenc_bb03 import IBE_BB04 12 | >>> group = PairingGroup('SS512') 13 | >>> ibe = IBE_BB04(group) 14 | >>> hashID = HashIDAdapter(ibe, group) 15 | >>> hyb_ibe = HybridIBEnc(hashID, group) 16 | >>> (master_public_key, master_key) = hyb_ibe.setup() 17 | >>> ID = 'waldoayo@gmail.com' 18 | >>> secret_key = hyb_ibe.extract(master_key, ID) 19 | >>> msg = b"Hello World My name is blah blah!!!! Word!" 20 | >>> cipher_text = hyb_ibe.encrypt(master_public_key, ID, msg) 21 | >>> decrypted_msg = hyb_ibe.decrypt(master_public_key, secret_key, cipher_text) 22 | >>> decrypted_msg == msg 23 | True 24 | 25 | """ 26 | def __init__(self, scheme, groupObj): 27 | global ibenc, group 28 | ibenc = scheme 29 | group = groupObj 30 | 31 | def setup(self): 32 | return ibenc.setup() 33 | 34 | def extract(self, mk, ID): 35 | return ibenc.extract(mk, ID) 36 | 37 | def encrypt(self, pk, ID, M): 38 | # if type(M) != bytes: raise "message not right type!" 39 | if type(M) != str: raise "message not right type!" 40 | key = group.random(GT) 41 | c1 = ibenc.encrypt(pk, ID, key) 42 | # instantiate a symmetric enc scheme from this key 43 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 44 | c2 = cipher.encrypt(M) 45 | return { 'c1':c1, 'c2':c2 } 46 | 47 | def decrypt(self, pk, ID, ct): 48 | c1, c2 = ct['c1'], ct['c2'] 49 | key = ibenc.decrypt(pk, ID, c1) 50 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 51 | return cipher.decrypt(c2) 52 | 53 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/adapters/ibenc_adapt_identityhash.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.IBEnc import IBEnc 2 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair 3 | 4 | debug = False 5 | class HashIDAdapter(IBEnc): 6 | """ 7 | >>> from charm.schemes.ibenc.ibenc_bb03 import IBE_BB04 8 | >>> group = PairingGroup('SS512') 9 | >>> ibe = IBE_BB04(group) 10 | >>> hashID = HashIDAdapter(ibe, group) 11 | >>> (master_public_key, master_key) = hashID.setup() 12 | >>> ID = 'waldoayo@email.com' 13 | >>> secret_key = hashID.extract(master_key, ID) 14 | >>> msg = group.random(GT) 15 | >>> cipher_text = hashID.encrypt(master_public_key, ID, msg) 16 | >>> decrypted_msg = hashID.decrypt(master_public_key, secret_key, cipher_text) 17 | >>> msg == decrypted_msg 18 | True 19 | """ 20 | def __init__(self, scheme, group): 21 | IBEnc.__init__(self) 22 | self.group = group 23 | self.ibe_good = False 24 | # validate that we have the appropriate object 25 | 26 | if IBEnc.checkProperty(self, scheme, {'scheme':self.baseSchemeTypes.IBEnc, 27 | 'secdef':self.baseSecDefs.sIND_ID_CPA, 28 | 'id':ZR}): 29 | self.ibenc = scheme 30 | # change our property as well 31 | IBEnc.setProperty(self, secdef='IND_ID_CPA', other={'id':str}, secmodel='ROM') 32 | # check message space? 33 | self.ibe_good = True 34 | 35 | if not self.ibe_good: 36 | assert False, "ibe object does not satisfy requirements." 37 | 38 | def setup(self): 39 | if not self.ibe_good: return IBEnc.setup(self) 40 | return self.ibenc.setup() 41 | 42 | def extract(self, mk, ID): 43 | if not self.ibe_good: return IBEnc.extract(self, mk, ID) 44 | if type(ID) == str: 45 | ID2 = self.group.hash(ID) 46 | return self.ibenc.extract(mk, ID2) 47 | else: 48 | assert False, "invalid type on ID." 49 | 50 | def encrypt(self, pk, ID, msg): 51 | if not self.ibe_good: return IBEnc.encrypt(self, pk, ID, msg) 52 | if type(ID) == str: 53 | ID2 = self.group.hash(ID) 54 | return self.ibenc.encrypt(pk, ID2, msg) 55 | else: 56 | assert False, "invalid type on ID." 57 | 58 | def decrypt(self, pk, sk, ct): 59 | if not self.ibe_good: return IBEnc.decrypt(self, pk, sk, ct) 60 | return self.ibenc.decrypt(pk, sk, ct) 61 | 62 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/adapters/kpabenc_adapt_hybrid.py: -------------------------------------------------------------------------------- 1 | 2 | from charm.toolbox.pairinggroup import PairingGroup,GT 3 | from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction 4 | from charm.core.math.pairing import hashPair as sha1 5 | from charm.toolbox.ABEnc import ABEnc 6 | from charm.schemes.abenc.abenc_lsw08 import KPabe 7 | 8 | debug = False 9 | class HybridABEnc(ABEnc): 10 | """ 11 | >>> from charm.schemes.abenc.abenc_lsw08 import KPabe 12 | >>> group = PairingGroup('SS512') 13 | >>> kpabe = KPabe(group) 14 | >>> hyb_abe = HybridABEnc(kpabe, group) 15 | >>> access_policy = ['ONE', 'TWO', 'THREE'] 16 | >>> access_key = '((FOUR or THREE) and (TWO or ONE))' 17 | >>> msg = "hello world this is an important message." 18 | >>> (master_public_key, master_key) = hyb_abe.setup() 19 | >>> secret_key = hyb_abe.keygen(master_public_key, master_key, access_key) 20 | >>> cipher_text = hyb_abe.encrypt(master_public_key, msg, access_policy) 21 | >>> hyb_abe.decrypt(cipher_text, secret_key) 22 | 'hello world this is an important message.' 23 | """ 24 | 25 | def __init__(self, scheme, groupObj): 26 | ABEnc.__init__(self) 27 | global abenc 28 | # check properties (TODO) 29 | abenc = scheme 30 | self.group = groupObj 31 | 32 | def setup(self): 33 | return abenc.setup() 34 | 35 | def keygen(self, pk, mk, object): 36 | return abenc.keygen(pk, mk, object) 37 | 38 | def encrypt(self, pk, M, object): 39 | key = self.group.random(GT) 40 | c1 = abenc.encrypt(pk, key, object) 41 | # instantiate a symmetric enc scheme from this key 42 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 43 | c2 = cipher.encrypt(M) 44 | return { 'c1':c1, 'c2':c2 } 45 | 46 | def decrypt(self, ct, sk): 47 | c1, c2 = ct['c1'], ct['c2'] 48 | key = abenc.decrypt(c1, sk) 49 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 50 | return cipher.decrypt(c2) 51 | 52 | def main(): 53 | groupObj = PairingGroup('SS512') 54 | kpabe = KPabe(groupObj) 55 | hyb_abe = HybridABEnc(kpabe, groupObj) 56 | access_key = '((ONE or TWO) and THREE)' 57 | access_policy = ['ONE', 'TWO', 'THREE'] 58 | message = b"hello world this is an important message." 59 | (pk, mk) = hyb_abe.setup() 60 | if debug: print("pk => ", pk) 61 | if debug: print("mk => ", mk) 62 | sk = hyb_abe.keygen(pk, mk, access_key) 63 | if debug: print("sk => ", sk) 64 | ct = hyb_abe.encrypt(pk, message, access_policy) 65 | mdec = hyb_abe.decrypt(ct, sk) 66 | assert mdec == message, "Failed Decryption!!!" 67 | if debug: print("Successful Decryption!!!") 68 | 69 | if __name__ == "__main__": 70 | debug = True 71 | main() 72 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/benchmark.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/benchmark.so -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/crypto/AES.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/crypto/AES.so -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/crypto/DES.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/crypto/DES.so -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/crypto/DES3.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/crypto/DES3.so -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/crypto/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/crypto/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/crypto/cryptobase.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/crypto/cryptobase.so -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/engine/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | #from protocol import * 3 | #from util import * 4 | 5 | 6 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/math/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/math/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/math/elliptic_curve.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/math/elliptic_curve.so -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/math/integer.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/math/integer.so -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/core/math/pairing.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/core/math/pairing.so -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/abenc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/abenc/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/chamhash_adm05.py: -------------------------------------------------------------------------------- 1 | ''' Ateneise-Medeiros (Schnorr group-based) 2 | 3 | | From: "Ateneise-Breno de Medeiros On the Key Exposure Problem in Chameleon Hashes", Section 4. 4 | | Published in: SCN 2004 5 | | Available from: 6 | | Notes: 7 | 8 | * type: hash function (chameleon) 9 | * setting: Schnorr groups 10 | * assumption: DL-Hard 11 | 12 | :Authors: J Ayo Akinyele 13 | :Date: 4/2011 14 | ''' 15 | from charm.toolbox.Hash import ChamHash,Hash 16 | from charm.toolbox.integergroup import IntegerGroupQ 17 | 18 | debug = False 19 | class ChamHash_Adm05(ChamHash): 20 | """ 21 | >>> from charm.core.math.integer import integer 22 | >>> p = integer(141660875619984104245410764464185421040193281776686085728248762539241852738181649330509191671665849071206347515263344232662465937366909502530516774705282764748558934610432918614104329009095808618770549804432868118610669336907161081169097403439689930233383598055540343198389409225338204714777812724565461351567) 23 | >>> q = integer(70830437809992052122705382232092710520096640888343042864124381269620926369090824665254595835832924535603173757631672116331232968683454751265258387352641382374279467305216459307052164504547904309385274902216434059305334668453580540584548701719844965116691799027770171599194704612669102357388906362282730675783) 24 | >>> chamHash = ChamHash_Adm05(p, q) 25 | >>> (public_key, secret_key) = chamHash.paramgen() 26 | >>> msg = "hello world this is the message" 27 | >>> c = chamHash.hash(public_key, msg) 28 | >>> c == chamHash.hash(public_key, msg, c[1], c[2]) 29 | True 30 | """ 31 | 32 | def __init__(self, p=0, q=0): 33 | ChamHash.__init__(self) 34 | global group; 35 | group = IntegerGroupQ(0) 36 | # if p and q parameters have already been selected 37 | group.p, group.q, group.r = p, q, 2 38 | self.group = group 39 | 40 | def paramgen(self, secparam=1024): 41 | if group.p == 0 or group.q == 0: 42 | group.paramgen(secparam) 43 | g, x = group.randomGen(), group.random() # g, [1,q-1] 44 | y = g ** x 45 | 46 | if debug: 47 | print("Public params") 48 | print("g =>", g); print("y =>", y) 49 | 50 | pk = { 'g':g, 'y':y } 51 | sk = { 'x':x } 52 | return (pk, sk) 53 | 54 | def hash(self, pk, m, r = 0, s = 0): 55 | p,q = group.p, group.q 56 | if r == 0: r = group.random() 57 | if s == 0: s = group.random() 58 | e = group.hash(m, r) 59 | 60 | C = r - (((pk['y'] ** e) * (pk['g'] ** s)) % p) % q 61 | return (C, r, s) 62 | 63 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/chamhash_rsa_hw09.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hohenberger-Waters Chameleon Hash (RSA-based) 3 | based on the scheme of Ateneise and de Medeiros 4 | 5 | | From: "S. Hohenberger, B. Waters. Realizing Hash-and-Sign Signatures under Standard Assumptions", Appendix A. 6 | | Published in: Eurocrypt 2009 7 | | Available from: http://eprint.iacr.org/2009/028.pdf 8 | | Notes: 9 | 10 | * type: hash function (chameleon) 11 | * setting: RSA 12 | * assumption: RSA 13 | 14 | :Author: J. Ayo Akinyele 15 | :Date: 1/2011 16 | ''' 17 | 18 | from charm.toolbox.Hash import ChamHash,Hash 19 | from charm.toolbox.integergroup import IntegerGroupQ,gcd 20 | from charm.toolbox.conversion import Conversion 21 | 22 | debug=False 23 | class ChamHash_HW09(ChamHash): 24 | """ 25 | >>> from charm.core.math.integer import integer 26 | >>> p = integer(164960892556379843852747960442703555069442262500242170785496141408191025653791149960117681934982863436763270287998062485836533436731979391762052869620652382502450810563192532079839617163226459506619269739544815249458016088505187490329968102214003929285843634017082702266003694786919671197914296386150563930299) 27 | >>> q = integer(82480446278189921926373980221351777534721131250121085392748070704095512826895574980058840967491431718381635143999031242918266718365989695881026434810326191251225405281596266039919808581613229753309634869772407624729008044252593745164984051107001964642921817008541351133001847393459835598957148193075281965149) 28 | >>> chamHash = ChamHash_HW09() 29 | >>> (public_key, secret_key) = chamHash.paramgen(1024, p, q) 30 | >>> msg = "Hello world this is the message!" 31 | >>> (hash1, r) = chamHash.hash(public_key, msg) 32 | >>> (hash2, r) = chamHash.hash(public_key, msg, r) 33 | >>> hash1 == hash2 34 | True 35 | """ 36 | def __init__(self): 37 | global group 38 | group = IntegerGroupQ(0) 39 | 40 | def paramgen(self, secparam, p = 0, q = 0): 41 | # If we're given p, q, compute N = p*q. Otherwise select random p, q 42 | if not (p == 0 or q == 0): 43 | N = p * q 44 | if debug: print("p :=", p) 45 | if debug: print("q :=", q) 46 | else: 47 | group.paramgen(secparam) 48 | p, q = group.p, group.q 49 | N = p * q 50 | 51 | phi_N = (p-1)*(q-1) 52 | J = group.random(N) 53 | e = group.random(phi_N) 54 | while (not gcd(e, phi_N) == 1): 55 | e = group.random(phi_N) 56 | pk = { 'secparam': secparam, 'N': N, 'J': J, 'e': e } 57 | sk = { 'p': p, 'q': q } 58 | return (pk, sk) 59 | 60 | def hash(self, pk, message, r = 0): 61 | N, J, e = pk['N'], pk['J'], pk['e'] 62 | if r == 0: 63 | r = group.random(N) 64 | M = Conversion.bytes2integer(message) 65 | h = ((J ** M) * (r ** e)) % N 66 | return (h, r) 67 | 68 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/commit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/commit/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/commit/commit_gs08.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Groth-Sahai Commitment Scheme 3 | 4 | | From: "J. Groth, A. Sahai. Efficient Non-interactive Proof Systems for Bilinear Groups". 5 | | Published in: Eurocrypt 2008 6 | | Available from: http://www.cs.ucl.ac.uk/staff/J.Groth/WImoduleFull.pdf 7 | | Notes: This implements only the SXDH and DLIN instantiations, in prime-order groups. 8 | 9 | * type: commitment 10 | * setting: bilinear groups 11 | 12 | :Authors: Matthew Green 13 | :Date: 6/2011 14 | ''' 15 | 16 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair 17 | from charm.toolbox.Commit import * 18 | 19 | debug=False 20 | class Commitment_GS08(Commitment): 21 | """ 22 | >>> group = PairingGroup('SS512') 23 | >>> alg = Commitment_GS08(group) 24 | >>> public_key = alg.setup() 25 | >>> msg = group.random(G1) 26 | >>> (commit, decommit) = alg.commit(public_key, msg) 27 | >>> alg.decommit(public_key, commit, decommit, msg) 28 | True 29 | """ 30 | def __init__(self, groupObj, setting='SXDH'): 31 | Commitment.__init__(self) 32 | #Commitment.setProperty(self, secdef='CM_PHCB', assumption=['SXDH','DLIN'], message_space=[G1, 'KEM'], secmodel='SM') 33 | global group 34 | group = groupObj 35 | 36 | # Generates commitment parameters for either G1 or G2 (specified by groupChoice). 37 | # By default this generates the binding commitment parameters. Set commitType to 'hiding' 38 | # in order to generate hiding parameters. 39 | def setup(self, secparam=None, groupChoice=G1, commitType='binding'): 40 | g1, h1 = group.random(groupChoice), group.random(groupChoice) 41 | s, t = group.random(ZR), group.random(ZR) 42 | if (commitType == 'binding'): 43 | g2, h2 = g1 ** s, h1 ** s 44 | else: 45 | g2, h2 = g1 ** s, h1 ** t 46 | 47 | return (g1, g2, h1, h2) 48 | # msg => ZR 49 | def commit(self, params, msg): 50 | # TODO: check that the message is in the same group as the params 51 | (g1, g2, h1, h2) = params 52 | r1, r2 = group.random(ZR), group.random(ZR) 53 | 54 | c1 = (g1 ** r1) * (h1 ** r2) 55 | c2 = msg * (g2 ** r1) * (h2 ** r2) 56 | 57 | return ({ 'c1':c1, 'c2':c2 }, { 'r1':r1, 'r2':r2 }) 58 | 59 | def decommit(self, params, c, d, msg): 60 | # TODO: check that the message is in the same group as the params 61 | (g1, g2, h1, h2) = params 62 | 63 | if (not (c['c1'] == ((g1 ** d['r1']) * (h1 ** d['r2'])))): 64 | return False 65 | 66 | if (not ((c['c2'] / msg) == ((g2 ** d['r1']) * (h2 ** d['r2'])))): 67 | return False 68 | 69 | return True 70 | 71 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/commit/commit_pedersen92.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.ecgroup import ECGroup,ZR,G 2 | from charm.toolbox.Commit import Commitment 3 | 4 | debug = False 5 | class CM_Ped92(Commitment): 6 | """ 7 | >>> group = ECGroup(410) 8 | >>> alg = CM_Ped92(group) 9 | >>> public_key = alg.setup() 10 | >>> msg = group.random(ZR) 11 | >>> (commit, decommit) = alg.commit(public_key, msg) 12 | >>> alg.decommit(public_key, commit, decommit, msg) 13 | True 14 | """ 15 | def __init__(self, groupObj): 16 | Commitment.__init__(self) 17 | global group 18 | group = groupObj 19 | 20 | def setup(self, secparam=None): 21 | return {'g': group.random(G), 'h':group.random(G)} 22 | 23 | def commit(self, pk, msg): 24 | r = group.random(ZR) 25 | c = (pk['g'] ** msg) * (pk['h'] ** r) 26 | d = r 27 | return (c,d) 28 | 29 | def decommit(self, pk, c, d, msg): 30 | return c == (pk['g'] ** msg) * (pk['h'] ** d) 31 | 32 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/encap_bchk05.py: -------------------------------------------------------------------------------- 1 | from charm.core.math.integer import randomBits 2 | import hashlib 3 | 4 | debug = False 5 | class EncapBCHK(): 6 | """ 7 | >>> encap = EncapBCHK() 8 | >>> hout = encap.setup() 9 | >>> (r, com, dec) = encap.S(hout) 10 | >>> rout = encap.R(hout, com, dec) 11 | >>> r == rout 12 | True 13 | """ 14 | def __init__(self): 15 | global H 16 | H = hashlib.sha1() 17 | 18 | def setup(self): 19 | pub = hashlib.md5() 20 | return pub 21 | 22 | def S(self, pub): 23 | x = randomBits(448) 24 | x = str(x).zfill(135) 25 | 26 | r = hashlib.md5(x.encode('utf-8')).digest() 27 | 28 | com = hashlib.sha1(x.encode('utf-8')).digest()[:128] 29 | 30 | dec = x 31 | 32 | return (r, com, dec) 33 | 34 | def R(self, pub, com, dec): 35 | x = hashlib.sha1(str(dec).encode('utf-8')).digest()[:128] 36 | 37 | if(x == com): 38 | m = hashlib.md5(str(dec).encode('utf-8')).digest() 39 | return m 40 | else: 41 | return b'FALSE' 42 | 43 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/grpsig/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/grpsig/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/hibenc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/hibenc/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/ibenc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/ibenc/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pkenc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pkenc/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pksig/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pksig/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pksig/pksig_bls04.py: -------------------------------------------------------------------------------- 1 | ''' 2 | :Boneh-Lynn-Shacham Identity Based Signature 3 | 4 | | From: "D. Boneh, B. Lynn, H. Shacham Short Signatures from the Weil Pairing" 5 | | Published in: Journal of Cryptology 2004 6 | | Available from: http:// 7 | | Notes: This is the IBE (2-level HIBE) implementation of the HIBE scheme BB_2. 8 | 9 | * type: signature (identity-based) 10 | * setting: bilinear groups (asymmetric) 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 1/2011 14 | ''' 15 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,pair 16 | from charm.core.engine.util import objectToBytes 17 | 18 | debug = False 19 | class IBSig(): 20 | """ 21 | >>> from charm.toolbox.pairinggroup import PairingGroup 22 | >>> group = PairingGroup('MNT224') 23 | >>> messages = { 'a':"hello world!!!" , 'b':"test message" } 24 | >>> ib = IBSig(group) 25 | >>> (public_key, secret_key) = ib.keygen() 26 | >>> signature = ib.sign(secret_key['x'], messages) 27 | >>> ib.verify(public_key, signature, messages) 28 | True 29 | """ 30 | def __init__(self, groupObj): 31 | global group 32 | group = groupObj 33 | 34 | def dump(self, obj): 35 | return objectToBytes(obj, group) 36 | 37 | def keygen(self, secparam=None): 38 | g, x = group.random(G2), group.random() 39 | g_x = g ** x 40 | pk = { 'g^x':g_x, 'g':g, 'identity':str(g_x), 'secparam':secparam } 41 | sk = { 'x':x } 42 | return (pk, sk) 43 | 44 | def sign(self, x, message): 45 | M = self.dump(message) 46 | if debug: print("Message => '%s'" % M) 47 | return group.hash(M, G1) ** x 48 | 49 | def verify(self, pk, sig, message): 50 | M = self.dump(message) 51 | h = group.hash(M, G1) 52 | if pair(sig, pk['g']) == pair(h, pk['g^x']): 53 | return True 54 | return False 55 | 56 | def main(): 57 | groupObj = PairingGroup('MNT224') 58 | 59 | m = { 'a':"hello world!!!" , 'b':"test message" } 60 | bls = IBSig(groupObj) 61 | 62 | (pk, sk) = bls.keygen() 63 | 64 | sig = bls.sign(sk['x'], m) 65 | 66 | if debug: print("Message: '%s'" % m) 67 | if debug: print("Signature: '%s'" % sig) 68 | assert bls.verify(pk, sig, m), "Failure!!!" 69 | if debug: print('SUCCESS!!!') 70 | 71 | if __name__ == "__main__": 72 | debug = True 73 | main() 74 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pksig/pksig_chch.py: -------------------------------------------------------------------------------- 1 | """ 2 | Jae Choon Cha and Jung Hee Cheon - Identity-based Signatures 3 | 4 | | From: "J. Cha and J. Choen - An identity-based signature from gap Diffie-Hellman groups." 5 | | Published in: PKC 2003 6 | | Available from: Vol. 2567. LNCS, pages 18-30 7 | | Notes: 8 | 9 | * type: signature (ID-based) 10 | * setting: bilinear groups (asymmetric) 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 11/2011 14 | """ 15 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair 16 | from charm.toolbox.PKSig import PKSig 17 | 18 | debug = False 19 | class CHCH(PKSig): 20 | """ 21 | >>> from charm.toolbox.pairinggroup import PairingGroup 22 | >>> group = PairingGroup('SS512') 23 | >>> chch = CHCH(group) 24 | >>> (master_public_key, master_secret_key) = chch.setup() 25 | >>> ID = "janedoe@email.com" 26 | >>> (public_key, secret_key) = chch.keygen(master_secret_key, ID) 27 | >>> msg = "this is a message!" 28 | >>> signature = chch.sign(public_key, secret_key, msg) 29 | >>> chch.verify(master_public_key, public_key, msg, signature) 30 | True 31 | """ 32 | def __init__(self, groupObj): 33 | global group,H1,H2 34 | group = groupObj 35 | H1 = lambda x: group.hash(x, G1) 36 | H2 = lambda x,y: group.hash((x,y), ZR) 37 | 38 | def setup(self): 39 | g2, alpha = group.random(G2), group.random(ZR) 40 | msk = alpha 41 | P = g2 ** alpha 42 | mpk = {'P':P, 'g2':g2} 43 | return (mpk, msk) 44 | 45 | def keygen(self, msk, ID): 46 | alpha = msk 47 | sk = H1(ID) ** alpha 48 | pk = H1(ID) 49 | return (pk, sk) 50 | 51 | def sign(self, pk, sk, M): 52 | if debug: print("sign...") 53 | s = group.random(ZR) 54 | S1 = pk ** s 55 | a = H2(M, S1) 56 | S2 = sk ** (s + a) 57 | return {'S1':S1, 'S2':S2} 58 | 59 | def verify(self, mpk, pk, M, sig): 60 | if debug: print("verify...") 61 | (S1, S2) = sig['S1'], sig['S2'] 62 | a = H2(M, S1) 63 | if pair(S2, mpk['g2']) == pair(S1 * (pk ** a), mpk['P']): 64 | return True 65 | return False 66 | 67 | def main(): 68 | groupObj = PairingGroup('SS512') 69 | chch = CHCH(groupObj) 70 | (mpk, msk) = chch.setup() 71 | 72 | _id = "janedoe@email.com" 73 | (pk, sk) = chch.keygen(msk, _id) 74 | if debug: 75 | print("Keygen...") 76 | print("pk =>", pk) 77 | print("sk =>", sk) 78 | 79 | M = "this is a message!" 80 | sig = chch.sign(pk, sk, M) 81 | if debug: 82 | print("Signature...") 83 | print("sig =>", sig) 84 | 85 | assert chch.verify(mpk, pk, M, sig), "invalid signature!" 86 | if debug: print("Verification successful!") 87 | 88 | if __name__ == "__main__": 89 | debug = True 90 | main() 91 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pksig/pksig_chp.py: -------------------------------------------------------------------------------- 1 | """ 2 | Camenisch-Hohenberger-Pedersen - Identity-based Signatures 3 | 4 | | From: "Camenisch, S. Hohenberger, M. Pedersen - Batch Verification of short signatures." 5 | | Published in: EUROCRYPT 2007 6 | | Available from: http://epring.iacr.org/2007/172.pdf 7 | | Notes: 8 | 9 | * type: signature (ID-based) 10 | * setting: bilinear groups (asymmetric) 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 11/2011 14 | """ 15 | from charm.toolbox.pairinggroup import G1,G2,ZR,pair 16 | from charm.toolbox.PKSig import PKSig 17 | 18 | debug = False 19 | 20 | class CHP(PKSig): 21 | """ 22 | >>> from charm.toolbox.pairinggroup import PairingGroup 23 | >>> group = PairingGroup('SS512') 24 | >>> chp = CHP(group) 25 | >>> master_public_key = chp.setup() 26 | >>> (public_key, secret_key) = chp.keygen(master_public_key) 27 | >>> msg = { 't1':'time_1', 't2':'time_2', 't3':'time_3', 'str':'this is the message'} 28 | >>> signature = chp.sign(public_key, secret_key, msg) 29 | >>> chp.verify(master_public_key, public_key, msg, signature) 30 | True 31 | """ 32 | def __init__(self, groupObj): 33 | global group, H 34 | group = groupObj 35 | 36 | def setup(self): 37 | global H,H3 38 | H = lambda prefix,x: group.hash((str(prefix), str(x)), G1) 39 | H3 = lambda a,b: group.hash(('3', str(a), str(b)), ZR) 40 | g = group.random(G2) 41 | return { 'g' : g } 42 | 43 | def keygen(self, mpk): 44 | alpha = group.random(ZR) 45 | sk = alpha 46 | pk = mpk['g'] ** alpha 47 | return (pk, sk) 48 | 49 | def sign(self, pk, sk, M): 50 | a = H(1, M['t1']) 51 | h = H(2, M['t2']) 52 | b = H3(M['str'], M['t3']) 53 | sig = (a ** sk) * (h ** (sk * b)) 54 | return sig 55 | 56 | def verify(self, mpk, pk, M, sig): 57 | a = H(1, M['t1']) 58 | h = H(2, M['t2']) 59 | b = H3(M['str'], M['t3']) 60 | if pair(sig, mpk['g']) == (pair(a, pk) * (pair(h, pk) ** b)): 61 | return True 62 | return False 63 | 64 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pksig/pksig_cl04.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Identity Based Signature 3 | 4 | | From: "J. Camenisch, A. Lysyanskaya. Signature Schemes and Anonymous Credentials from Bilinear Maps" 5 | | Published in: 2004 6 | | Available from: http://www.cs.brown.edu/~anna/papers/cl04.pdf 7 | | Notes: Scheme A on page 5 section 3.1. 8 | 9 | * type: signature (identity-based) 10 | * setting: bilinear groups (asymmetric) 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 1/2012 14 | ''' 15 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,pair 16 | from charm.toolbox.PKSig import PKSig 17 | 18 | debug = False 19 | class CL04(PKSig): 20 | """ 21 | >>> from charm.toolbox.pairinggroup import PairingGroup 22 | >>> group = PairingGroup('MNT224') 23 | >>> cl = CL04(group) 24 | >>> master_public_key = cl.setup() 25 | >>> (public_key, secret_key) = cl.keygen(master_public_key) 26 | >>> msg = "Please sign this stupid message!" 27 | >>> signature = cl.sign(public_key, secret_key, msg) 28 | >>> cl.verify(public_key, msg, signature) 29 | True 30 | """ 31 | def __init__(self, groupObj): 32 | global group 33 | group = groupObj 34 | 35 | def setup(self): 36 | g = group.random(G1) 37 | return { 'g': g } 38 | 39 | def keygen(self, mpk): 40 | x, y = group.random(ZR), group.random(ZR) 41 | sk = { 'x':x, 'y':y } 42 | pk = { 'X':mpk['g'] ** x, 'Y': mpk['g'] ** y, 'g':mpk['g'] } 43 | return (pk, sk) 44 | 45 | def sign(self, pk, sk, M): 46 | a = group.random(G2) 47 | m = group.hash(M, ZR) 48 | sig = {'a':a, 'a_y':a ** sk['y'], 'a_xy':a ** (sk['x'] + (m * sk['x'] * sk['y'])) } 49 | return sig 50 | 51 | def verify(self, pk, M, sig): 52 | (a, b, c) = sig['a'], sig['a_y'], sig['a_xy'] 53 | m = group.hash(M, ZR) 54 | if pair(pk['Y'], a) == pair(pk['g'], b) and (pair(pk['X'], a) * (pair(pk['X'], b) ** m)) == pair(pk['g'], c): 55 | return True 56 | return False 57 | 58 | def main(): 59 | grp = PairingGroup('MNT224') 60 | cl = CL04(grp) 61 | 62 | mpk = cl.setup() 63 | 64 | (pk, sk) = cl.keygen(mpk) 65 | if debug: 66 | print("Keygen...") 67 | print("pk :=", pk) 68 | print("sk :=", sk) 69 | 70 | M = "Please sign this stupid message!" 71 | sig = cl.sign(pk, sk, M) 72 | if debug: print("Signature: ", sig) 73 | 74 | result = cl.verify(pk, M, sig) 75 | assert result, "INVALID signature!" 76 | if debug: print("Successful Verification!!!") 77 | 78 | if __name__ == "__main__": 79 | debug = True 80 | main() 81 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pksig/pksig_dsa.py: -------------------------------------------------------------------------------- 1 | """ 2 | Digital Signature Algorithm (DSA) 3 | 4 | | From: "NIST proposed in Aug 1991 for use in DSS." 5 | | Published in: FIPS 186 6 | | Available from: 7 | | Notes: 8 | 9 | * type: signature 10 | * setting: integer groups 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 5/2011 14 | """ 15 | 16 | from charm.toolbox.integergroup import IntegerGroupQ 17 | from charm.toolbox.PKSig import PKSig 18 | 19 | debug = False 20 | class DSA(PKSig): 21 | """ 22 | >>> from charm.core.math.integer import integer 23 | >>> p = integer(156053402631691285300957066846581395905893621007563090607988086498527791650834395958624527746916581251903190331297268907675919283232442999706619659475326192111220545726433895802392432934926242553363253333261282122117343404703514696108330984423475697798156574052962658373571332699002716083130212467463571362679) 24 | >>> q = integer(78026701315845642650478533423290697952946810503781545303994043249263895825417197979312263873458290625951595165648634453837959641616221499853309829737663096055610272863216947901196216467463121276681626666630641061058671702351757348054165492211737848899078287026481329186785666349501358041565106233731785681339) 25 | >>> dsa = DSA(p, q) 26 | >>> (public_key, secret_key) = dsa.keygen(1024) 27 | >>> msg = "hello world test message!!!" 28 | >>> signature = dsa.sign(public_key, secret_key, msg) 29 | >>> dsa.verify(public_key, signature, msg) 30 | True 31 | """ 32 | def __init__(self, p=0, q=0): 33 | global group 34 | group = IntegerGroupQ() 35 | group.p, group.q, group.r = p, q, 2 36 | 37 | def keygen(self, bits): 38 | if group.p == 0 or group.q == 0: 39 | group.paramgen(bits) 40 | global p,q 41 | p,q = group.p, group.q 42 | x = group.random() 43 | g = group.randomGen() 44 | y = (g ** x) % p 45 | return ({'g':g, 'y':y}, x) 46 | 47 | def sign(self, pk, x, M): 48 | while True: 49 | k = group.random() 50 | r = (pk['g'] ** k) % q 51 | s = (k ** -1) * ((group.hash(M) + x*r) % q) 52 | if (r == 0 or s == 0): 53 | print("unlikely error r = %s, s = %s" % (r,s)) 54 | continue 55 | else: 56 | break 57 | return { 'r':r, 's':s } 58 | 59 | def verify(self, pk, sig, M): 60 | w = (sig['s'] ** -1) % q 61 | u1 = (group.hash(M) * w) % q 62 | u2 = (sig['r'] * w) % q 63 | v = ((pk['g'] ** u1) * (pk['y'] ** u2)) % p 64 | v %= q 65 | if v == sig['r']: 66 | return True 67 | else: 68 | return False 69 | 70 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pksig/pksig_ecdsa.py: -------------------------------------------------------------------------------- 1 | """ 2 | Digital Signature Algorithm (DSA) 3 | 4 | | From: "NIST proposed in Aug 1991 for use in DSS." 5 | | Published in: FIPS 186 6 | | Available from: 7 | | Notes: 8 | 9 | * type: signature 10 | * setting: elliptic curve groups 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 5/2011 14 | """ 15 | from charm.toolbox.ecgroup import ECGroup,ZR,G 16 | from charm.toolbox.PKSig import PKSig 17 | 18 | debug = False 19 | class ECDSA(PKSig): 20 | """ 21 | >>> from charm.toolbox.eccurve import prime192v2 22 | >>> group = ECGroup(prime192v2) 23 | >>> ecdsa = ECDSA(group) 24 | >>> (public_key, secret_key) = ecdsa.keygen(0) 25 | >>> msg = "hello world! this is a test message." 26 | >>> signature = ecdsa.sign(public_key, secret_key, msg) 27 | >>> ecdsa.verify(public_key, signature, msg) 28 | True 29 | """ 30 | def __init__(self, groupObj): 31 | PKSig.__init__(self) 32 | global group 33 | group = groupObj 34 | 35 | def keygen(self, bits): 36 | group.paramgen(bits) 37 | x, g = group.random(), group.random(G) 38 | y = (g ** x) 39 | return ({'g':g, 'y':y}, x) 40 | 41 | def sign(self, pk, x, M): 42 | while True: 43 | k = group.random() 44 | r = group.zr(pk['g'] ** k) 45 | e = group.hash(M) 46 | s = (k ** -1) * (e + x * r) 47 | if (r == 0 or s == 0): 48 | print ("unlikely error r = %s, s = %s" % (r,s)) 49 | continue 50 | else: 51 | break 52 | return { 'r':r, 's':s } 53 | 54 | def verify(self, pk, sig, M): 55 | w = sig['s'] ** -1 56 | u1 = group.hash(M) * w 57 | u2 = sig['r'] * w 58 | v = (pk['g'] ** u1) * (pk['y'] ** u2) 59 | 60 | if group.zr(v) == sig['r']: 61 | return True 62 | else: 63 | return False 64 | 65 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pksig/pksig_hess.py: -------------------------------------------------------------------------------- 1 | """ 2 | Hess - Identity-based Signatures 3 | 4 | | From: "Hess - Efficient identity based signature schemes based on pairings." 5 | | Published in: Selected Areas in Cryptography 6 | | Available from: Vol. 2595. LNCS, pages 310-324 7 | | Notes: 8 | 9 | * type: signature (ID-based) 10 | * setting: bilinear groups (asymmetric) 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 11/2011 14 | """ 15 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,pair 16 | from charm.toolbox.PKSig import PKSig 17 | #import gc 18 | #gc.disable() 19 | #gc.set_debug(gc.DEBUG_LEAK) 20 | 21 | debug = False 22 | 23 | class Hess(PKSig): 24 | """ 25 | >>> from charm.toolbox.pairinggroup import PairingGroup 26 | >>> group = PairingGroup('SS512') 27 | >>> hess = Hess(group) 28 | >>> (master_public_key, master_secret_key) = hess.setup() 29 | >>> ID = "janedoe@email.com" 30 | >>> (public_key, secret_key) = hess.keygen(master_secret_key, ID) 31 | >>> msg = "this is a message!" 32 | >>> signature = hess.sign(master_public_key, secret_key, msg) 33 | >>> hess.verify(master_public_key, public_key, msg, signature) 34 | True 35 | """ 36 | def __init__(self, groupObj): 37 | global group,H1,H2 38 | group = groupObj 39 | H1 = lambda x: group.hash(x, G1) 40 | H2 = lambda x,y: group.hash((x,y), ZR) 41 | 42 | def setup(self): 43 | g2, alpha = group.random(G2), group.random(ZR) 44 | msk = alpha 45 | P = g2 ** alpha 46 | mpk = {'P':P, 'g2':g2} 47 | return (mpk, msk) 48 | 49 | def keygen(self, msk, ID): 50 | alpha = msk 51 | sk = H1(ID) ** alpha 52 | pk = H1(ID) 53 | return (pk, sk) 54 | 55 | def sign(self, pk, sk, M): 56 | if debug: print("sign...") 57 | h, s = group.random(G1), group.random(ZR) 58 | S1 = pair(h,pk['g2']) ** s 59 | a = H2(M, S1) 60 | S2 = (sk ** a) * (h ** s) 61 | return {'S1':S1, 'S2':S2} 62 | # return (S1, S2) 63 | 64 | 65 | def verify(self, mpk, pk, M, sig): 66 | if debug: print("verify...") 67 | (S1, S2) = sig['S1'], sig['S2'] 68 | a = H2(M, S1) 69 | if pair(S2, mpk['g2']) == (pair(pk, mpk['P']) ** a) * S1: 70 | return True 71 | return False 72 | 73 | def main(): 74 | 75 | groupObj = PairingGroup('SS512') 76 | chch = Hess(groupObj) 77 | (mpk, msk) = chch.setup() 78 | 79 | _id = "janedoe@email.com" 80 | (pk, sk) = chch.keygen(msk, _id) 81 | if debug: 82 | print("Keygen...") 83 | print("pk =>", pk) 84 | print("sk =>", sk) 85 | 86 | M = "this is a message!" 87 | sig = chch.sign(mpk, sk, M) 88 | if debug: 89 | print("Signature...") 90 | print("sig =>", sig) 91 | 92 | assert chch.verify(mpk, pk, M, sig), "invalid signature!" 93 | if debug: print("Verification successful!") 94 | 95 | if __name__ == "__main__": 96 | debug = True 97 | main() 98 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/pksig/pksig_schnorr91.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.integergroup import IntegerGroupQ 2 | from charm.toolbox.PKSig import PKSig 3 | 4 | debug = False 5 | class SchnorrSig(PKSig): 6 | """ 7 | >>> from charm.core.math.integer import integer 8 | >>> p = integer(156816585111264668689583680968857341596876961491501655859473581156994765485015490912709775771877391134974110808285244016265856659644360836326566918061490651852930016078015163968109160397122004869749553669499102243382571334855815358562585736488447912605222780091120196023676916968821094827532746274593222577067) 9 | >>> q = integer(78408292555632334344791840484428670798438480745750827929736790578497382742507745456354887885938695567487055404142622008132928329822180418163283459030745325926465008039007581984054580198561002434874776834749551121691285667427907679281292868244223956302611390045560098011838458484410547413766373137296611288533) 10 | >>> pksig = SchnorrSig() 11 | >>> pksig.params(p, q) 12 | >>> (public_key, secret_key) = pksig.keygen() 13 | >>> msg = "hello world." 14 | >>> signature = pksig.sign(public_key, secret_key, msg) 15 | >>> pksig.verify(public_key, signature, msg) 16 | True 17 | """ 18 | def __init__(self): 19 | PKSig.__init__(self) 20 | 21 | def params(self, p=0, q=0, bits=1024): 22 | global group 23 | group = IntegerGroupQ(0) 24 | if p == 0 or q == 0: 25 | group.paramgen(bits) 26 | else: 27 | group.p, group.q, group.r = p, q, 2 28 | 29 | def keygen(self): 30 | p = group.p 31 | x, g = group.random(), group.randomGen() 32 | y = (g ** x) 33 | return ({'y':y, 'g':g}, x) 34 | 35 | def sign(self, pk, x, M): 36 | p,q = group.p, group.q 37 | k = group.random() 38 | r = (pk['g'] ** k) % p 39 | e = group.hash(M, r) 40 | s = (k - x*e) % q 41 | 42 | return {'e':e, 's':s } 43 | 44 | def verify(self, pk, sig, M): 45 | p = group.p 46 | r = ((pk['g'] ** sig['s']) * (pk['y'] ** sig['e'])) % p 47 | if debug: print("Verifying...") 48 | e = group.hash(M, r) 49 | if debug: print("e => %s" % e) 50 | if debug: print("r => %s" % r) 51 | if e == sig['e']: 52 | return True 53 | else: 54 | return False 55 | return None 56 | 57 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/schemes/sigma1.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.sigmaprotocol import Sigma 2 | from charm.toolbox.pairinggroup import ZR,G2,pair 3 | 4 | class SigmaProtocol1(Sigma): 5 | def __init__(self, groupObj, common_input=None): 6 | Sigma.__init__(self, groupObj, common_input) 7 | 8 | def prover_state1(self): 9 | (g, h, H) = Sigma.get(self, ['g', 'h', 'H']) 10 | r = self.group.random(G2) 11 | a = pair(g, r) 12 | Sigma.setState(self, 3) 13 | return { 'r':r, 'a':a, 'g':g, 'h':h, 'H':H } 14 | 15 | def prover_state3(self, input): 16 | (r, h, c) = Sigma.get(self, ['r','h','c']) 17 | z = r * (h ** -c) 18 | Sigma.setState(self, 5) 19 | return {'z':z } 20 | 21 | def prover_state5(self, input): 22 | Sigma.setState(self, None) 23 | Sigma.setErrorCode(self, input) 24 | return None 25 | 26 | def verifier_state2(self, input): 27 | c = self.group.random(ZR) 28 | Sigma.setState(self, 4) 29 | return {'c':c } 30 | 31 | def verifier_state4(self, input): 32 | (g, H, a, c, z) = Sigma.get(self, ['g','H','a','c','z']) 33 | if a == (pair(g,z) * (H ** c)): 34 | print("SUCCESS!!!!!!!"); result = 'OK' 35 | else: 36 | print("Failed!!!"); result = 'FAIL' 37 | Sigma.setState(self, 6) 38 | Sigma.setErrorCode(self, result) 39 | return result 40 | 41 | def verifier_state6(self, input): 42 | Sigma.setState(self, None) 43 | return None 44 | 45 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/test/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/test/schemes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/test/schemes/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/test/schemes/commit_test.py: -------------------------------------------------------------------------------- 1 | from charm.schemes.commit.commit_gs08 import Commitment_GS08 2 | from charm.schemes.commit.commit_pedersen92 import CM_Ped92 3 | from charm.toolbox.pairinggroup import PairingGroup, G1 4 | from charm.toolbox.ecgroup import ECGroup, ZR 5 | import unittest 6 | 7 | debug = False 8 | 9 | class Commitment_GS08Test(unittest.TestCase): 10 | def testCommitment_GS08(self): 11 | groupObj = PairingGroup('SS512') 12 | cm = Commitment_GS08(groupObj) 13 | 14 | pk = cm.setup() 15 | if debug: 16 | print("Public parameters...") 17 | print("pk =>", pk) 18 | 19 | m = groupObj.random(G1) 20 | if debug: print("Committing to =>", m) 21 | (c, d) = cm.commit(pk, m) 22 | 23 | assert cm.decommit(pk, c, d, m), "FAILED to decommit" 24 | if debug: print("Successful and Verified decommitment!!!") 25 | 26 | class CM_Ped92Test(unittest.TestCase): 27 | def testCM_Ped92(self): 28 | groupObj = ECGroup(410) 29 | cm = CM_Ped92(groupObj) 30 | 31 | pk = cm.setup() 32 | if debug: 33 | print("Public parameters...") 34 | print("pk =>", pk) 35 | 36 | m = groupObj.random(ZR) 37 | if debug: print("Commiting to =>", m) 38 | (c, d) = cm.commit(pk, m) 39 | 40 | assert cm.decommit(pk, c, d, m), "FAILED to decommit" 41 | if debug: print("Successful and Verified decommitment!!!") 42 | del groupObj 43 | 44 | if __name__ == "__main__": 45 | unittest.main() 46 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/test/schemes/encap_bchk05_test.py: -------------------------------------------------------------------------------- 1 | from charm.schemes.encap_bchk05 import EncapBCHK 2 | import unittest 3 | 4 | debug = False 5 | class EncapBCHKTest(unittest.TestCase): 6 | def testEncapBCHK(self): 7 | encap = EncapBCHK() 8 | 9 | hout = encap.setup() 10 | 11 | (r, com, dec) = encap.S(hout) 12 | 13 | rout = encap.R(hout, com, dec) 14 | 15 | if debug: print("recovered m =>", rout) 16 | 17 | assert r == rout, "Failed Decryption" 18 | if debug: print("Successful Decryption!!!") 19 | 20 | if __name__ == "__main__": 21 | unittest.main() 22 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/test/schemes/grpsig_test.py: -------------------------------------------------------------------------------- 1 | from charm.schemes.grpsig.groupsig_bgls04 import ShortSig as BGLS04 2 | from charm.schemes.grpsig.groupsig_bgls04_var import ShortSig as BGLS04_Var 3 | from charm.toolbox.pairinggroup import PairingGroup 4 | import unittest 5 | 6 | debug = False 7 | 8 | class BGLS04Test(unittest.TestCase): 9 | def testBGLS04(self): 10 | groupObj = PairingGroup('MNT224') 11 | n = 3 # how manu users in the group 12 | user = 1 # which user's key to sign a message with 13 | 14 | sigTest = BGLS04(groupObj) 15 | 16 | (gpk, gmsk, gsk) = sigTest.keygen(n) 17 | 18 | message = 'Hello World this is a message!' 19 | if debug: print("\n\nSign the following M: '%s'" % (message)) 20 | 21 | signature = sigTest.sign(gpk, gsk[user], message) 22 | 23 | result = sigTest.verify(gpk, message, signature) 24 | #if result: 25 | # print("Verify signers identity...") 26 | # index = sigTest.open(gpk, gmsk, message, signature) 27 | # i = 0 28 | # while i < n: 29 | # if gsk[i][0] == index: 30 | # print('Found index of signer: %d' % i) 31 | # print('A = %s' % index) 32 | # i += 1 33 | assert result, "Signature Failed" 34 | if debug: print('Complete!') 35 | 36 | class BGLS04_VarTest(unittest.TestCase): 37 | def testBGLS04_Var(self): 38 | groupObj = PairingGroup('MNT224') 39 | n = 3 # how manu users in the group 40 | user = 1 # which user's key to sign a message with 41 | 42 | sigTest = BGLS04_Var(groupObj) 43 | 44 | (gpk, gmsk, gsk) = sigTest.keygen(n) 45 | 46 | message = 'Hello World this is a message!' 47 | if debug: print("\n\nSign the following M: '%s'" % (message)) 48 | 49 | signature = sigTest.sign(gpk, gsk[user], message) 50 | 51 | result = sigTest.verify(gpk, message, signature) 52 | #if result: 53 | # print("Verify signers identity...") 54 | # index = sigTest.open(gpk, gmsk, message, signature) 55 | # i = 0 56 | # while i < n: 57 | # if gsk[i][0] == index: 58 | # print('Found index of signer: %d' % i) 59 | # print('A = %s' % index) 60 | # i += 1 61 | assert result, "Signature Failed" 62 | if debug: print('Successful Verification!') 63 | 64 | if __name__ == "__main__": 65 | unittest.main() 66 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/test/schemes/hibenc_test.py: -------------------------------------------------------------------------------- 1 | from charm.schemes.hibenc.hibenc_bb04 import HIBE_BB04 2 | from charm.toolbox.pairinggroup import PairingGroup, GT 3 | import unittest 4 | 5 | debug = False 6 | 7 | class HIBE_BB04Test(unittest.TestCase): 8 | def testHIBE_BB04(self): 9 | groupObj = PairingGroup('SS512') 10 | hibe = HIBE_BB04(groupObj) 11 | (mpk, mk) = hibe.setup() 12 | 13 | # represents public identity 14 | ID = "bob@mail.com" 15 | (pk, sk) = hibe.extract(3, mpk, mk, ID) 16 | # dID => pk, sk 17 | if debug: print("ID:%s , sk:%s" % (pk, sk)) 18 | 19 | M = groupObj.random(GT) 20 | if debug: print("M :=", M) 21 | ct = hibe.encrypt(mpk, pk, M) 22 | 23 | orig_M = hibe.decrypt(pk, sk, ct) 24 | assert orig_M == M, "invalid decryption!!!!" 25 | if debug: print("Successful DECRYPTION!!!") 26 | 27 | if __name__ == "__main__": 28 | unittest.main() 29 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/test/schemes/pk_vrf_test.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.pairinggroup import PairingGroup 2 | from charm.schemes.pk_vrf import VRF10 3 | import unittest 4 | 5 | debug = False 6 | class VRF10Test(unittest.TestCase): 7 | def testVRF10(self): 8 | grp = PairingGroup('MNT224') 9 | 10 | # bits 11 | x1 = [0, 1, 1, 0, 1, 0, 1, 0] 12 | # x2 = [1, 1, 1, 0, 1, 0, 1, 0] 13 | # block of bits 14 | n = 8 15 | 16 | vrf = VRF10(grp) 17 | 18 | # setup the VRF to accept input blocks of 8-bits 19 | (pk, sk) = vrf.setup(n) 20 | 21 | # generate proof over block x (using sk) 22 | st = vrf.prove(sk, x1) 23 | 24 | # verify bits using pk and proof 25 | assert vrf.verify(pk, x1, st), "VRF failed verification" 26 | # assert vrf.verify(pk, x2, st), "VRF should FAIL verification!!!" 27 | 28 | if __name__ == "__main__": 29 | unittest.main() 30 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/test/toolbox/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/test/toolbox/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/test/toolbox/conversion_test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Created on Jul 5, 2011 3 | 4 | :authors: Gary belvin 5 | ''' 6 | from charm.toolbox.conversion import Conversion 7 | import unittest 8 | 9 | 10 | class ConversionTest(unittest.TestCase): 11 | 12 | 13 | def testOS2IP(self): 14 | #9,202,000 = (0x)8c 69 50. 15 | i = Conversion.OS2IP(b'\x8c\x69\x50') 16 | self.assertEqual(i, 9202000) 17 | 18 | def testIP2OS(self): 19 | #9,202,000 = (0x)8c 69 50. 20 | os = Conversion.IP2OS(9202000) 21 | self.assertEqual(os, b'\x8c\x69\x50') 22 | 23 | def testIP2OSLen(self): 24 | i = 9202000 25 | os = Conversion.IP2OS(i, 200) 26 | i2 = Conversion.OS2IP(os) 27 | self.assertEqual(i, i2) 28 | 29 | if __name__ == "__main__": 30 | #import sys;sys.argv = ['', 'Test.testOS2IP'] 31 | unittest.main() 32 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/test/toolbox/secretshare_test.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.secretshare import SecretShare 2 | from charm.toolbox.pairinggroup import PairingGroup,ZR 3 | import unittest 4 | 5 | debug=False 6 | 7 | class SecretShareTest(unittest.TestCase): 8 | def testSecretShare(self): 9 | # Testing Secret sharing python API 10 | k = 3 11 | n = 4 12 | group = PairingGroup('SS512') 13 | 14 | s = SecretShare(group, False) 15 | sec = group.random(ZR) 16 | shares = s.genShares(sec, k, n) 17 | 18 | K = shares[0] 19 | if debug: print('\nOriginal secret: %s' % K) 20 | y = {group.init(ZR, long(1)):shares[1], group.init(ZR, long(2)):shares[2], group.init(ZR, long(3)):shares[3]} 21 | 22 | secret = s.recoverSecret(y) 23 | 24 | assert K == secret, "Could not recover the secret!" 25 | if debug: print("Successfully recovered secret: ", secret) 26 | 27 | if __name__ == "__main__": 28 | unittest.main() 29 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/ABEnc.py: -------------------------------------------------------------------------------- 1 | ''' Base class for attribute-based encryption 2 | 3 | Notes: This class implements an interface for a standard attribute-based encryption scheme. 4 | 5 | A public key attribute-based encryption scheme consists of four algorithms: 6 | (setup, keygen, encrypt, decrypt). 7 | ''' 8 | from charm.toolbox.schemebase import * 9 | 10 | class ABEnc(SchemeBase): 11 | def __init__(self): 12 | SchemeBase.__init__(self) 13 | SchemeBase.setProperty(self, scheme='ABEnc') 14 | self.baseSecDefs = Enum('IND_AB_CPA', 'IND_AB_CCA', 'sIND_AB_CPA', 'sIND_AB_CCA') 15 | 16 | def setup(self): 17 | raise NotImplementedError 18 | 19 | def keygen(self, pk, mk, object): 20 | raise NotImplementedError 21 | 22 | def encrypt(self, pk, M, object): 23 | raise NotImplementedError 24 | 25 | def decrypt(self, pk, sk, ct): 26 | raise NotImplementedError 27 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/ABEncMultiAuth.py: -------------------------------------------------------------------------------- 1 | ''' Base class for attribute-based encryption multi-authority 2 | 3 | Notes: This class implements an interface for a standard attribute-based encryption scheme. 4 | 5 | A public key attribute-based encryption scheme consists of four algorithms: 6 | (setup, authsetup, keygen, encrypt, decrypt). 7 | ''' 8 | from charm.toolbox.schemebase import * 9 | 10 | class ABEncMultiAuth(SchemeBase): 11 | def __init__(self): 12 | SchemeBase.__init__(self) 13 | SchemeBase.setProperty(self, scheme='ABEncMultiAuth') 14 | self.baseSecDefs = None 15 | 16 | def setup(self): 17 | raise NotImplementedError 18 | 19 | def authsetup(self, gp, object): 20 | raise NotImplementedError 21 | 22 | def keygen(self, gp, sk, gid): 23 | raise NotImplementedError 24 | 25 | def encrypt(self, pk, gp, M, object): 26 | raise NotImplementedError 27 | 28 | def decrypt(self, gp, sk, ct): 29 | raise NotImplementedError 30 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/Commit.py: -------------------------------------------------------------------------------- 1 | ''' Base class for commitment schemes 2 | 3 | Notes: This class implements an interface for a standard commitment scheme. 4 | A commitment scheme consists of three algorithms: (setup, commit, decommit). 5 | 6 | Allows one to commit to a value while keeping it hidden, with the ability 7 | to reveal the committed value later (wiki). 8 | ''' 9 | from charm.toolbox.schemebase import * 10 | 11 | class Commitment(SchemeBase): 12 | def __init__(self): 13 | SchemeBase.__init__(self) 14 | SchemeBase.setProperty(self, scheme='Commitment') 15 | self.baseSecDefs = None 16 | 17 | def setup(self, securityparam): 18 | raise NotImplementedError 19 | 20 | def commit(self, *args): 21 | raise NotImplementedError 22 | 23 | def decommit(self, *args): 24 | raise NotImplementedError 25 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/Hash.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.schemebase import * 2 | 3 | class Hash(SchemeBase): 4 | ''' Base class for Hash functions 5 | 6 | Notes: This class implements an interface for a standard hash function scheme. 7 | A hash function consists of two algorithms: (paramgen or keygen and hash). 8 | ''' 9 | 10 | def __init__(self): 11 | SchemeBase.__init__(self) 12 | SchemeBase.setProperty(self, scheme='Hash') 13 | self.baseSecDefs = None # Enum('EU_CMA') 14 | # base methods? 15 | def paramgen(self, *args): 16 | raise NotImplementedError 17 | 18 | def hash(self, *args): 19 | raise NotImplementedError 20 | 21 | 22 | class ChamHash(Hash): 23 | ''' 24 | Notes: This class implements an interface for a chameleon hash function. 25 | A standard charmeleon hash scheme has two algorithms paramgen and hash. 26 | paramgen accepts a security parameter and the length of p and q. Hash accepts 27 | public key, label, a message and a random element. 28 | ''' 29 | 30 | def __init__(self): 31 | Hash.__init__(self) 32 | Hash.setProperty(self, scheme='ChamHash') 33 | self.baseSecDefs = None # Enum('EU_CMA') 34 | 35 | def paramgen(self, secparam, p=None, q=None): 36 | raise NotImplementedError 37 | 38 | def hash(self, pk, prefix, message, r): 39 | raise NotImplementedError -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/IBEnc.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Base class for identity-based encryption 3 | 4 | Notes: This class implements an interface for a standard identity-based encryption scheme. 5 | Identity-based encryption consists of three algorithms: (setup, extract, encrypt, and decrypt). 6 | ''' 7 | from charm.toolbox.schemebase import * 8 | 9 | class IBEnc(SchemeBase): 10 | def __init__(self): 11 | SchemeBase.__init__(self) 12 | SchemeBase.setProperty(self, scheme='IBEnc') 13 | self.baseSecDefs = Enum('IND_ID_CPA','sIND_ID_CPA','IND_ID_CCA','sIND_ID_CCA') 14 | 15 | def setup(self): 16 | raise NotImplementedError 17 | 18 | def extract(self, mk, ID): 19 | raise NotImplementedError 20 | 21 | def encrypt(self, pk, ID, message): 22 | raise NotImplementedError 23 | 24 | def decrypt(self, pk, sk, ct): 25 | raise NotImplementedError 26 | 27 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/PKEnc.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Base class for public-key encryption 3 | 4 | Notes: This class implements an interface for a standard public-key encryption scheme. 5 | A public key encryption consists of four algorithms: (paramgen, keygen, encrypt, decrypt). 6 | ''' 7 | from charm.toolbox.schemebase import * 8 | 9 | class PKEnc(SchemeBase): 10 | def __init__(self): 11 | SchemeBase.__init__(self) 12 | SchemeBase.setProperty(self, scheme="PKEnc") 13 | self.baseSecDefs = Enum('OW_CPA','OW_CCA1','OW_CCA','IND_CPA','IND_CCA1','IND_CCA', 14 | 'NM_CPA','NM_CCA1','NM_CCA','KA_CPA','KA_CCA1','KA_CCA') 15 | 16 | def paramgen(self, param1=None, param2=None): 17 | return NotImplemented 18 | 19 | def keygen(self, securityparam): 20 | return NotImplemented 21 | 22 | def encrypt(self, pk, M): 23 | return NotImplemented 24 | 25 | def decrypt(self, pk, sk, c): 26 | return NotImplemented 27 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/PKSig.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Base class for public-key signatures 3 | 4 | Notes: This class implements an interface for a standard public-key signature scheme. 5 | A public key signature consists of three algorithms: (keygen, sign, verify). 6 | ''' 7 | from charm.toolbox.schemebase import * 8 | 9 | class PKSig(SchemeBase): 10 | def __init__(self): 11 | SchemeBase.__init__(self) 12 | SchemeBase.setProperty(self, scheme='PKSig') 13 | self.baseSecDefs = Enum('EU_CMA', 'wEU_CMA', 'sEU_CMA') 14 | 15 | def keygen(self, securityparam): 16 | raise NotImplementedError 17 | 18 | def sign(self, pk, sk, message): 19 | raise NotImplementedError 20 | 21 | def verify(self, pk, message, sig): 22 | raise NotImplementedError 23 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/bitstring.py: -------------------------------------------------------------------------------- 1 | ''' 2 | ``bistring.Bytes`` is a replacement for Python's ``byte``. 3 | ''' 4 | 5 | import string 6 | import sys 7 | 8 | py3 = False 9 | if sys.hexversion >= int(0x03000000): 10 | py3 = True 11 | 12 | 13 | class Bytes(bytes): 14 | def __init__(self, value, enc=None): 15 | if enc != None: 16 | if py3: bytes.__init__(value, enc) 17 | else: bytes.__init__(value) 18 | else: 19 | bytes.__init__(value) 20 | 21 | def __xor__(self, other): 22 | '''Overload the ``^`` operator to provide xor ''' 23 | assert len(self) == len(other), "xor: operands differ in length." 24 | res = bytearray() 25 | for i in range(0,len(self)): 26 | if py3: res.append(self[i] ^ other[i]) 27 | else: res.append(chr(ord(self[i]) ^ ord(other[i]))) 28 | #print("res[%s] = %s" % (i, res[i])) 29 | return Bytes(res) 30 | 31 | def __add__(self, other): 32 | return Bytes(bytes.__add__(self, other)) 33 | 34 | @classmethod 35 | def fill(self, prefix, length): 36 | '''Provides an easy way to create a byte array of a specified length and content''' 37 | bits = b'' 38 | for i in range(0, int(length)): 39 | bits += prefix 40 | return Bytes(bits) 41 | 42 | 43 | # TODO: add left and right bit shifting 44 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/enum.py: -------------------------------------------------------------------------------- 1 | # code adapted from active state code recipes for enumeration 2 | def Enum(*names): 3 | class EnumClass(object): 4 | __slots__ = names 5 | def __iter__(self): return iter(constants) 6 | def __len__(self): return len(constants) 7 | def __getitem__(self, i): 8 | if type(i) == int: return constants[i] 9 | elif type(i) == str: 10 | index = lookup.get(i) 11 | if index != None: return constants[index] 12 | else: return None 13 | else: assert False, "Invalid input type." 14 | def __repr__(self): return 'Enum' + str(names) 15 | def __str__(self): return 'enum ' + str(constants) 16 | 17 | class EnumValue(object): 18 | __slots__ = ('__value') 19 | def __init__(self, value): self.__value = value 20 | Value = property(lambda self: self.__value) 21 | EnumType = property(lambda self: EnumType) 22 | def __hash__(self): return hash(self.__value) 23 | def __lt__(self, other): 24 | return (self.__value < other.__value) 25 | def __gt__(self, other): 26 | return (self.__value > other.__value) 27 | def __le__(self, other): 28 | return (self.__value <= other.__value) 29 | def __ge__(self, other): 30 | return (self.__value >= other.__value) 31 | def __eq__(self, other): 32 | if type(self) == int: lhs = self 33 | else: lhs = self.__value 34 | if type(other) == int: rhs = other 35 | else: rhs = other.__value 36 | return (lhs == rhs) 37 | def __ne__(self, other): 38 | if type(self) == int: lhs = self 39 | else: lhs = self.__value 40 | if type(other) == int: rhs = other 41 | else: rhs = other.__value 42 | return (lhs != rhs) 43 | def __invert__(self): return constants[maximum - self.__value] 44 | def __nonzero__(self): return bool(self.__value) 45 | def __repr__(self): return str(names[self.__value]) 46 | 47 | maximum = len(names) - 1 48 | constants = [None] * len(names) 49 | lookup = {} 50 | for i, each in enumerate(names): 51 | val = EnumValue(i) 52 | setattr(EnumClass, each, val) 53 | # create list of int => 'str' 54 | constants[i] = val 55 | # create reverse lookup 56 | lookup[str(val)] = i 57 | constants = tuple(constants) 58 | EnumType = EnumClass() 59 | return EnumType 60 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/iterate.py: -------------------------------------------------------------------------------- 1 | 2 | # simple example 3 | #>>> a = [1,2,3,4,5] 4 | #>>> dotprod(1, 1, len(a), lambda i,b: (b[i] ** 2), a) 5 | # TODO: support caching of values at each stage of product? 6 | 7 | def dotprod(init, skip, n, func, *args): 8 | prod = init 9 | i = 0 10 | for j in range(i, n): 11 | if j != skip: 12 | result = func(j, *args) 13 | # cache if necessary 14 | prod *= result 15 | #print("product =>", prod) 16 | return prod 17 | 18 | def dotprod2(iterator, func, *args): 19 | prod = 1 20 | for j in iterator: 21 | prod *= func(j, *args) 22 | return prod 23 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/redundancyschemes.py: -------------------------------------------------------------------------------- 1 | '''A collection of redundancy schemes''' 2 | from charm.toolbox.bitstring import Bytes,py3 3 | from charm.toolbox.securerandom import SecureRandomFactory 4 | import charm.core.crypto.cryptobase 5 | import hashlib 6 | import math 7 | import struct 8 | import sys 9 | 10 | debug = False 11 | 12 | 13 | class InMessageRedundancy: 14 | ''' 15 | :Authors: Christina Garman 16 | ''' 17 | def __init__(self): 18 | pass 19 | 20 | def encode(self, message): 21 | str_message = message.decode("utf-8") 22 | str_message += str_message[-8:] 23 | 24 | return str_message.encode("utf-8") 25 | 26 | def decode(self, encMessage): 27 | byte_message = bytearray(encMessage) 28 | 29 | if(byte_message[-8:] == byte_message[-16:-8]): 30 | return (True,bytes(byte_message[:-8])) 31 | else: 32 | return (False,bytes(byte_message[:-8])) 33 | 34 | class ExtraBitsRedundancy: 35 | ''' 36 | :Authors: Christina Garman 37 | 38 | TODO 39 | ''' 40 | def __init__(self): 41 | pass 42 | 43 | def encode(self, message): 44 | 45 | return Bytes(b'\x00') + maskedSeed + maskedDB 46 | 47 | def decode(self, encMessage, label=""): 48 | 49 | return M 50 | class WilliamsRedundancy: 51 | ''' 52 | :Authors: Christina Garman 53 | 54 | TODO 55 | ''' 56 | def __init__(self): 57 | pass 58 | 59 | def encode(self, message): 60 | 61 | return Bytes(b'\x00') + maskedSeed + maskedDB 62 | 63 | def decode(self, encMessage, label=""): 64 | 65 | return M 66 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/securerandom.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Base class for cryptographic secure random number generation 3 | :authors: Gary Belvin 4 | ''' 5 | from charm.toolbox.bitstring import Bytes 6 | from charm.toolbox.conversion import Conversion 7 | from charm.core.math.integer import randomBits 8 | import datetime 9 | import math 10 | import random 11 | 12 | class SecureRandom(): 13 | def __init__(self): 14 | pass 15 | def getRandomBytes(self, length): 16 | '''Returns a random bit string of length bytes''' 17 | raise NotImplementedError 18 | def addSeed(self, seed): 19 | ''' 20 | Add randomness to the generator. 21 | Always increases entropy 22 | ''' 23 | raise NotImplementedError 24 | 25 | class SecureRandomFactory(): 26 | ''' 27 | This class provides a central place to swap out the randomness engine 28 | used by the charm framework. 29 | Classes should call ``rand = SecureRandomFactory.getInstance()`` 30 | to acquire a randomnesss generator 31 | ''' 32 | @classmethod 33 | def getInstance(self): 34 | return OpenSSLRand() 35 | 36 | 37 | class OpenSSLRand(SecureRandom): 38 | '''Uses the OpenSSL PRNG for random bits''' 39 | def __init__(self): 40 | SecureRandom.__init__(self) 41 | #seed with a little bit of random data. This is not the only source 42 | #of randomness. Internally, OpenSSL samples additional physical randomness. 43 | 44 | def getRandomBytes(self, length): 45 | bits = length * 8; 46 | val = randomBits(bits) 47 | return Conversion.IP2OS(val, length) 48 | 49 | def getRandomBits(self, length): 50 | i = randomBits(length) 51 | len = math.ceil(length / 8) 52 | return Conversion.IP2OS(i, len) 53 | 54 | 55 | class WeakRandom(SecureRandom): 56 | def __init__(self): 57 | SecureRandom.__init__(self) 58 | def getRandomBytes(self, length): 59 | return self.myrandom(length, False) 60 | def addSeed(self, seed): 61 | raise NotImplementedError() 62 | @classmethod 63 | def myrandom(self, length, printable=False): 64 | ''' 65 | This method does **NOT** provide cryptographically secure random numbers. 66 | This should **NOT** be used for production code 67 | ''' 68 | if(printable): 69 | #Nice printable characters for testing purposes 70 | return Bytes(random.randrange(0x20, 0x7E) for i in range(length)) 71 | else: 72 | return Bytes(random.randrange(0, 256) for i in range(length)) 73 | 74 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/sigmaprotocol.py: -------------------------------------------------------------------------------- 1 | 2 | from charm.core.engine.protocol import Protocol 3 | from charm.core.engine.util import * 4 | from charm.toolbox.enum import Enum 5 | 6 | #party = Enum('Prover', 'Verifier') 7 | 8 | class Sigma(Protocol): 9 | def __init__(self, groupObj, common_input=None): 10 | Protocol.__init__(self, None) # think of something for handling errors 11 | self.verifier_states = { 2:self.verifier_state2, 4:self.verifier_state4, 6:self.verifier_state6 } 12 | self.prover_states = { 1:self.prover_state1, 3:self.prover_state3, 5:self.prover_state5 } 13 | self.PROVER, self.VERIFIER = 1, 2 # PROVER = 1, VERIFIER = 2 14 | 15 | self.verifier_trans = { 2:4, 4:6 } 16 | self.prover_trans = { 1:3, 3:5 } 17 | # describe the parties involved and the valid transitions 18 | Protocol.addPartyType(self, self.VERIFIER, self.verifier_states, self.verifier_trans) 19 | Protocol.addPartyType(self, self.PROVER, self.prover_states, self.prover_trans, True) 20 | 21 | self.group = groupObj 22 | # proof parameter generation 23 | if common_input == None: # generate common parameters to P and V 24 | db = {} 25 | else: # can be used as a sub-protocol if common_input is specified by caller 26 | db = common_input 27 | Protocol.setSubclassVars(self, self.group, db) 28 | 29 | # must be implemented by sub class... 30 | def prover_state1(self): 31 | pass 32 | 33 | def prover_state3(self, input): 34 | pass 35 | 36 | def prover_state5(self, input): 37 | pass 38 | 39 | def verifier_state2(self, input): 40 | pass 41 | 42 | def verifier_state4(self, input): 43 | pass 44 | 45 | def verifier_state6(self, input): 46 | pass 47 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/specialprimes.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Generates a Blum-Williams integer, which is the product of two distinct primes 3 | each congruent to 3 mod 4 4 | ''' 5 | 6 | from charm.core.math.integer import integer,isPrime,randomPrime 7 | 8 | class BlumWilliamsInteger: 9 | def __init__(self): 10 | pass 11 | 12 | def generatePrimes(self, n): 13 | while True: 14 | p = randomPrime(n) 15 | if(isPrime(p) and (((p-3)%4) == 0)): 16 | break 17 | 18 | while True: 19 | q = randomPrime(n) 20 | if(isPrime(q) and (((q-3)%4) == 0) and not(q == p)): 21 | break 22 | 23 | return (p, q) 24 | 25 | def generateBlumWilliamsInteger(self, n, p=0, q=0): 26 | if((p == 0) or (q == 0)): 27 | (p,q) = self.generatePrimes(n) 28 | N = p * q 29 | return (p, q, N) 30 | else: 31 | N = p * q 32 | return N 33 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/toolbox/zknode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import string 4 | 5 | class BinNode: 6 | def __init__(self, value, left=None, right=None): 7 | #types of node 8 | self.OR = 1 9 | self.AND = 2 10 | self.EXP = 3 # '^' or exponent 11 | self.EQ = 4 # == 12 | self.ATTR = 0 13 | 14 | #OF = '' # anything above 1 and 2 15 | if(isinstance(value, str)): 16 | self.type = self.ATTR 17 | self.attribute = string.upper(value) 18 | 19 | elif(isinstance(value, int)): 20 | if value > 0 and value <= self.EQ: 21 | self.type = value 22 | self.attribute = '' 23 | 24 | self.left = left 25 | self.right = right 26 | 27 | def __str__(self): 28 | if(self.type == self.ATTR): 29 | return self.attribute 30 | else: 31 | left = str(self.left) 32 | right = str(self.right) 33 | 34 | if(self.type == self.OR): 35 | return ('('+ left + ') or (' + right + ')') 36 | elif(self.type == self.AND): 37 | return ('(' + left + ') and (' + right + ')') 38 | elif(self.type == self.EXP): 39 | return (left + '^' + right) 40 | elif(self.type == self.EQ): 41 | return (left + ' = ' + right) 42 | return None 43 | 44 | def getAttribute(self): 45 | if (self.type == self.ATTR): 46 | return self.attribute 47 | else: 48 | return None 49 | 50 | def getLeft(self): 51 | return self.left 52 | 53 | def getRight(self): 54 | return self.right 55 | 56 | def addSubNode(self, left, right): 57 | # set subNodes appropriately 58 | self.left = left if left != None else None 59 | self.right = right if left != None else None 60 | 61 | # only applies function on leaf nodes 62 | def traverse(self, function): 63 | # visit node then traverse left and right 64 | function(self.type, self) 65 | if(self.left == None): 66 | return None 67 | self.left.traverse(function) 68 | if(self.right == None): 69 | return None 70 | self.right.traverse(function) 71 | return None 72 | 73 | 74 | -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/zkp_compiler/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/lib.macosx-10.6-intel-2.7/charm/zkp_compiler/__init__.py -------------------------------------------------------------------------------- /Charm/build/lib.macosx-10.6-intel-2.7/charm/zkp_compiler/zk_demo.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair 2 | from charm.zkp_compiler.zkp_generator import * 3 | from socket import * 4 | import sys 5 | def main(argv): 6 | HOST, PORT = "", 8090 7 | party_info = {} 8 | if argv[1] == '-p': 9 | print("Operating as prover...") 10 | prover_sock = socket(AF_INET, SOCK_STREAM) 11 | prover_sock.connect((HOST, PORT)) 12 | prover_sock.settimeout(15) 13 | user = 'prover' 14 | party_info['socket'] = prover_sock 15 | elif argv[1] == '-v': 16 | print("Operating as verifier...") 17 | svr = socket(AF_INET, SOCK_STREAM) 18 | svr.bind((HOST, PORT)) 19 | svr.listen(1) 20 | verifier_sock, addr = svr.accept() 21 | print("Connected by ", addr) 22 | user = 'verifier' 23 | party_info['socket'] = verifier_sock 24 | else: 25 | print("ERROR!") 26 | exit(-1) 27 | 28 | group = PairingGroup('a.param') 29 | party_info['party'] = user 30 | party_info['setting'] = group 31 | # statement: '(h = g^x) and (j = g^y)' 32 | 33 | if(user == 'prover'): 34 | g = group.random(G1) 35 | x,y = group.random(ZR), group.random(ZR) 36 | pk = {'h':g ** x, 'g':g, 'j':g**y} 37 | sk = {'x':x, 'y':y} 38 | # pk = {'h':g**x, 'g':g} 39 | # sk = {'x':x, 'y':y} 40 | result = executeIntZKProof(pk, sk, '(h = g^x) and (j = g^y)', party_info) 41 | print("Results for PROVER =>", result) 42 | 43 | elif(user == 'verifier'): 44 | # verifier shouldn't have this information 45 | # pk = {'h':1, 'g':1, 'j':1} 46 | # sk = {'x':1, 'y':1} 47 | pk = {'h':1, 'g':1, 'j':1} 48 | sk = {'x':1} 49 | result = executeIntZKProof(pk, sk, '(h = g^x) and (j = g^y)', party_info) 50 | print("Results for VERIFIER =>", result) 51 | if __name__ == "__main__": 52 | main(sys.argv) 53 | -------------------------------------------------------------------------------- /Charm/build/temp.macosx-10.6-intel-2.7/charm/core/benchmark/benchmarkmodule.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/temp.macosx-10.6-intel-2.7/charm/core/benchmark/benchmarkmodule.o -------------------------------------------------------------------------------- /Charm/build/temp.macosx-10.6-intel-2.7/charm/core/crypto/AES/AES.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/temp.macosx-10.6-intel-2.7/charm/core/crypto/AES/AES.o -------------------------------------------------------------------------------- /Charm/build/temp.macosx-10.6-intel-2.7/charm/core/crypto/DES/DES.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/temp.macosx-10.6-intel-2.7/charm/core/crypto/DES/DES.o -------------------------------------------------------------------------------- /Charm/build/temp.macosx-10.6-intel-2.7/charm/core/crypto/DES3/DES3.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/temp.macosx-10.6-intel-2.7/charm/core/crypto/DES3/DES3.o -------------------------------------------------------------------------------- /Charm/build/temp.macosx-10.6-intel-2.7/charm/core/crypto/cryptobase/cryptobasemodule.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/temp.macosx-10.6-intel-2.7/charm/core/crypto/cryptobase/cryptobasemodule.o -------------------------------------------------------------------------------- /Charm/build/temp.macosx-10.6-intel-2.7/charm/core/math/elliptic_curve/ecmodule.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/temp.macosx-10.6-intel-2.7/charm/core/math/elliptic_curve/ecmodule.o -------------------------------------------------------------------------------- /Charm/build/temp.macosx-10.6-intel-2.7/charm/core/math/integer/integermodule.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/temp.macosx-10.6-intel-2.7/charm/core/math/integer/integermodule.o -------------------------------------------------------------------------------- /Charm/build/temp.macosx-10.6-intel-2.7/charm/core/math/pairing/pairingmodule.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/temp.macosx-10.6-intel-2.7/charm/core/math/pairing/pairingmodule.o -------------------------------------------------------------------------------- /Charm/build/temp.macosx-10.6-intel-2.7/charm/core/utilities/base64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/temp.macosx-10.6-intel-2.7/charm/core/utilities/base64.o -------------------------------------------------------------------------------- /Charm/build/temp.macosx-10.6-intel-2.7/charm/core/utilities/sha1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/build/temp.macosx-10.6-intel-2.7/charm/core/utilities/sha1.o -------------------------------------------------------------------------------- /Charm/charm/__init__.py: -------------------------------------------------------------------------------- 1 | # This fixes an issue where certain python interpeters/operating systems 2 | # fail to properly load shared modules that c extensions depend on. 3 | # In this case, the benchmark module is not handeled properly on osx 4 | # as such we import it preimptively to force its symbols to be loaded. 5 | import charm.core.benchmark 6 | -------------------------------------------------------------------------------- /Charm/charm/adapters/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/adapters/__init__.py -------------------------------------------------------------------------------- /Charm/charm/adapters/abenc_adapt_hybrid.py: -------------------------------------------------------------------------------- 1 | 2 | from charm.toolbox.ABEnc import ABEnc 3 | from charm.schemes.abenc.abenc_bsw07 import CPabe_BSW07 4 | from charm.toolbox.pairinggroup import PairingGroup,GT 5 | from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction 6 | from charm.core.math.pairing import hashPair as sha1 7 | from math import ceil 8 | 9 | debug = False 10 | class HybridABEnc(ABEnc): 11 | """ 12 | >>> group = PairingGroup("SS512") 13 | >>> cpabe = CPabe_BSW07(group) 14 | >>> hyb_abe = HybridABEnc(cpabe, group) 15 | >>> access_policy = '((four or three) and (two or one))' 16 | >>> msg = "hello world this is an important message." 17 | >>> (master_public_key, master_key) = hyb_abe.setup() 18 | >>> secret_key = hyb_abe.keygen(master_public_key, master_key, ['ONE', 'TWO', 'THREE']) 19 | >>> cipher_text = hyb_abe.encrypt(master_public_key, msg, access_policy) 20 | >>> hyb_abe.decrypt(master_public_key, secret_key, cipher_text) 21 | 'hello world this is an important message.' 22 | """ 23 | def __init__(self, scheme, groupObj): 24 | ABEnc.__init__(self) 25 | global abenc 26 | # check properties (TODO) 27 | abenc = scheme 28 | self.group = groupObj 29 | 30 | def setup(self): 31 | return abenc.setup() 32 | 33 | def keygen(self, pk, mk, object): 34 | return abenc.keygen(pk, mk, object) 35 | 36 | def encrypt(self, pk, M, object): 37 | key = self.group.random(GT) 38 | c1 = abenc.encrypt(pk, key, object) 39 | # instantiate a symmetric enc scheme from this key 40 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 41 | c2 = cipher.encrypt(M) 42 | return { 'c1':c1, 'c2':c2 } 43 | 44 | def decrypt(self, pk, sk, ct): 45 | c1, c2 = ct['c1'], ct['c2'] 46 | key = abenc.decrypt(pk, sk, c1) 47 | print type(key), key 48 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 49 | print cipher 50 | return cipher.decrypt(c2) 51 | 52 | def main(): 53 | groupObj = PairingGroup('SS512') 54 | cpabe = CPabe_BSW07(groupObj) 55 | hyb_abe = HybridABEnc(cpabe, groupObj) 56 | #access_policy = "((ADS or PVB or ME) and (720 or 168 or 24 or 1) and (SITE) and (KEEP) and (TRACK) and (LOCATE))" 57 | access_policy = "(ADS or PVB or ME) and (720 or 168 or 24 or 1) and SITE" 58 | message = "hello world this is an important message." 59 | (pk, mk) = hyb_abe.setup() 60 | if debug: print("pk => ", pk) 61 | if debug: print("mk => ", mk) 62 | sk = hyb_abe.keygen(pk, mk, ['ADS', '720', 'KEEP', 'TARGET', 'TRACK', 'NOLOCATE']) 63 | if debug: print("sk => ", sk) 64 | ct = hyb_abe.encrypt(pk, message, access_policy) 65 | mdec = hyb_abe.decrypt(pk, sk, ct) 66 | assert mdec == message, "Failed Decryption!!!" 67 | if debug: print("Successful Decryption!!!") 68 | 69 | if __name__ == "__main__": 70 | debug = True 71 | main() 72 | -------------------------------------------------------------------------------- /Charm/charm/adapters/ibenc_adapt_hybrid.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction 2 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair 3 | from charm.core.math.pairing import hashPair as sha1 4 | from charm.adapters.ibenc_adapt_identityhash import HashIDAdapter 5 | from charm.toolbox.IBEnc import IBEnc 6 | from charm.core.crypto.cryptobase import * 7 | 8 | debug = False 9 | class HybridIBEnc(IBEnc): 10 | """ 11 | >>> from charm.schemes.ibenc.ibenc_bb03 import IBE_BB04 12 | >>> group = PairingGroup('SS512') 13 | >>> ibe = IBE_BB04(group) 14 | >>> hashID = HashIDAdapter(ibe, group) 15 | >>> hyb_ibe = HybridIBEnc(hashID, group) 16 | >>> (master_public_key, master_key) = hyb_ibe.setup() 17 | >>> ID = 'waldoayo@gmail.com' 18 | >>> secret_key = hyb_ibe.extract(master_key, ID) 19 | >>> msg = b"Hello World My name is blah blah!!!! Word!" 20 | >>> cipher_text = hyb_ibe.encrypt(master_public_key, ID, msg) 21 | >>> decrypted_msg = hyb_ibe.decrypt(master_public_key, secret_key, cipher_text) 22 | >>> decrypted_msg == msg 23 | True 24 | 25 | """ 26 | def __init__(self, scheme, groupObj): 27 | global ibenc, group 28 | ibenc = scheme 29 | group = groupObj 30 | 31 | def setup(self): 32 | return ibenc.setup() 33 | 34 | def extract(self, mk, ID): 35 | return ibenc.extract(mk, ID) 36 | 37 | def encrypt(self, pk, ID, M): 38 | # if type(M) != bytes: raise "message not right type!" 39 | if type(M) != str: raise "message not right type!" 40 | key = group.random(GT) 41 | c1 = ibenc.encrypt(pk, ID, key) 42 | # instantiate a symmetric enc scheme from this key 43 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 44 | c2 = cipher.encrypt(M) 45 | return { 'c1':c1, 'c2':c2 } 46 | 47 | def decrypt(self, pk, ID, ct): 48 | c1, c2 = ct['c1'], ct['c2'] 49 | key = ibenc.decrypt(pk, ID, c1) 50 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 51 | return cipher.decrypt(c2) 52 | 53 | -------------------------------------------------------------------------------- /Charm/charm/adapters/ibenc_adapt_identityhash.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.IBEnc import IBEnc 2 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair 3 | 4 | debug = False 5 | class HashIDAdapter(IBEnc): 6 | """ 7 | >>> from charm.schemes.ibenc.ibenc_bb03 import IBE_BB04 8 | >>> group = PairingGroup('SS512') 9 | >>> ibe = IBE_BB04(group) 10 | >>> hashID = HashIDAdapter(ibe, group) 11 | >>> (master_public_key, master_key) = hashID.setup() 12 | >>> ID = 'waldoayo@email.com' 13 | >>> secret_key = hashID.extract(master_key, ID) 14 | >>> msg = group.random(GT) 15 | >>> cipher_text = hashID.encrypt(master_public_key, ID, msg) 16 | >>> decrypted_msg = hashID.decrypt(master_public_key, secret_key, cipher_text) 17 | >>> msg == decrypted_msg 18 | True 19 | """ 20 | def __init__(self, scheme, group): 21 | IBEnc.__init__(self) 22 | self.group = group 23 | self.ibe_good = False 24 | # validate that we have the appropriate object 25 | 26 | if IBEnc.checkProperty(self, scheme, {'scheme':self.baseSchemeTypes.IBEnc, 27 | 'secdef':self.baseSecDefs.sIND_ID_CPA, 28 | 'id':ZR}): 29 | self.ibenc = scheme 30 | # change our property as well 31 | IBEnc.setProperty(self, secdef='IND_ID_CPA', other={'id':str}, secmodel='ROM') 32 | # check message space? 33 | self.ibe_good = True 34 | 35 | if not self.ibe_good: 36 | assert False, "ibe object does not satisfy requirements." 37 | 38 | def setup(self): 39 | if not self.ibe_good: return IBEnc.setup(self) 40 | return self.ibenc.setup() 41 | 42 | def extract(self, mk, ID): 43 | if not self.ibe_good: return IBEnc.extract(self, mk, ID) 44 | if type(ID) == str: 45 | ID2 = self.group.hash(ID) 46 | return self.ibenc.extract(mk, ID2) 47 | else: 48 | assert False, "invalid type on ID." 49 | 50 | def encrypt(self, pk, ID, msg): 51 | if not self.ibe_good: return IBEnc.encrypt(self, pk, ID, msg) 52 | if type(ID) == str: 53 | ID2 = self.group.hash(ID) 54 | return self.ibenc.encrypt(pk, ID2, msg) 55 | else: 56 | assert False, "invalid type on ID." 57 | 58 | def decrypt(self, pk, sk, ct): 59 | if not self.ibe_good: return IBEnc.decrypt(self, pk, sk, ct) 60 | return self.ibenc.decrypt(pk, sk, ct) 61 | 62 | -------------------------------------------------------------------------------- /Charm/charm/adapters/kpabenc_adapt_hybrid.py: -------------------------------------------------------------------------------- 1 | 2 | from charm.toolbox.pairinggroup import PairingGroup,GT 3 | from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction 4 | from charm.core.math.pairing import hashPair as sha1 5 | from charm.toolbox.ABEnc import ABEnc 6 | from charm.schemes.abenc.abenc_lsw08 import KPabe 7 | 8 | debug = False 9 | class HybridABEnc(ABEnc): 10 | """ 11 | >>> from charm.schemes.abenc.abenc_lsw08 import KPabe 12 | >>> group = PairingGroup('SS512') 13 | >>> kpabe = KPabe(group) 14 | >>> hyb_abe = HybridABEnc(kpabe, group) 15 | >>> access_policy = ['ONE', 'TWO', 'THREE'] 16 | >>> access_key = '((FOUR or THREE) and (TWO or ONE))' 17 | >>> msg = "hello world this is an important message." 18 | >>> (master_public_key, master_key) = hyb_abe.setup() 19 | >>> secret_key = hyb_abe.keygen(master_public_key, master_key, access_key) 20 | >>> cipher_text = hyb_abe.encrypt(master_public_key, msg, access_policy) 21 | >>> hyb_abe.decrypt(cipher_text, secret_key) 22 | 'hello world this is an important message.' 23 | """ 24 | 25 | def __init__(self, scheme, groupObj): 26 | ABEnc.__init__(self) 27 | global abenc 28 | # check properties (TODO) 29 | abenc = scheme 30 | self.group = groupObj 31 | 32 | def setup(self): 33 | return abenc.setup() 34 | 35 | def keygen(self, pk, mk, object): 36 | return abenc.keygen(pk, mk, object) 37 | 38 | def encrypt(self, pk, M, object): 39 | key = self.group.random(GT) 40 | c1 = abenc.encrypt(pk, key, object) 41 | # instantiate a symmetric enc scheme from this key 42 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 43 | c2 = cipher.encrypt(M) 44 | return { 'c1':c1, 'c2':c2 } 45 | 46 | def decrypt(self, ct, sk): 47 | c1, c2 = ct['c1'], ct['c2'] 48 | key = abenc.decrypt(c1, sk) 49 | cipher = AuthenticatedCryptoAbstraction(sha1(key)) 50 | return cipher.decrypt(c2) 51 | 52 | def main(): 53 | groupObj = PairingGroup('SS512') 54 | kpabe = KPabe(groupObj) 55 | hyb_abe = HybridABEnc(kpabe, groupObj) 56 | access_key = '((ONE or TWO) and THREE)' 57 | access_policy = ['ONE', 'TWO', 'THREE'] 58 | message = b"hello world this is an important message." 59 | (pk, mk) = hyb_abe.setup() 60 | if debug: print("pk => ", pk) 61 | if debug: print("mk => ", mk) 62 | sk = hyb_abe.keygen(pk, mk, access_key) 63 | if debug: print("sk => ", sk) 64 | ct = hyb_abe.encrypt(pk, message, access_policy) 65 | mdec = hyb_abe.decrypt(ct, sk) 66 | assert mdec == message, "Failed Decryption!!!" 67 | if debug: print("Successful Decryption!!!") 68 | 69 | if __name__ == "__main__": 70 | debug = True 71 | main() 72 | -------------------------------------------------------------------------------- /Charm/charm/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/__init__.py -------------------------------------------------------------------------------- /Charm/charm/core/benchmark.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/benchmark.so -------------------------------------------------------------------------------- /Charm/charm/core/crypto/AES.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/crypto/AES.so -------------------------------------------------------------------------------- /Charm/charm/core/crypto/DES.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/crypto/DES.so -------------------------------------------------------------------------------- /Charm/charm/core/crypto/DES3.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/crypto/DES3.so -------------------------------------------------------------------------------- /Charm/charm/core/crypto/DES3/DES3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * DES3.c: 3DES support for PyCrypto using LibTomCrypt 3 | * 4 | * Written in 2009 by Dwayne C. Litzenberger 5 | * 6 | * =================================================================== 7 | * The contents of this file are dedicated to the public domain. To 8 | * the extent that dedication to the public domain is not available, 9 | * everyone is granted a worldwide, perpetual, royalty-free, 10 | * non-exclusive license to exercise all rights associated with the 11 | * contents of this file for any purpose whatsoever. 12 | * No rights are reserved. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 18 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 19 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | * =================================================================== 23 | * 24 | */ 25 | #define PCT_DES3_MODULE 26 | #include "DES.c" 27 | -------------------------------------------------------------------------------- /Charm/charm/core/crypto/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/crypto/__init__.py -------------------------------------------------------------------------------- /Charm/charm/core/crypto/cryptobase.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/crypto/cryptobase.so -------------------------------------------------------------------------------- /Charm/charm/core/crypto/cryptobase/XOR.c: -------------------------------------------------------------------------------- 1 | /* 2 | * xor.c : Source for the trivial cipher which XORs the message with the key. 3 | * The key can be up to 32 bytes long. 4 | * 5 | * Part of the Python Cryptography Toolkit 6 | * 7 | * Contributed by Barry Warsaw and others. 8 | * 9 | * ======================================================================= 10 | * The contents of this file are dedicated to the public domain. To the 11 | * extent that dedication to the public domain is not available, everyone 12 | * is granted a worldwide, perpetual, royalty-free, non-exclusive license 13 | * to exercise all rights associated with the contents of this file for 14 | * any purpose whatsoever. No rights are reserved. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | * ======================================================================= 25 | */ 26 | 27 | #include "Python.h" 28 | 29 | #define MODULE_NAME XOR 30 | #define BLOCK_SIZE 1 31 | #define KEY_SIZE 0 32 | 33 | #define MAX_KEY_SIZE 32 34 | 35 | typedef struct 36 | { 37 | unsigned char key[MAX_KEY_SIZE]; 38 | int keylen, last_pos; 39 | } stream_state; 40 | 41 | static void 42 | stream_init(stream_state *self, unsigned char *key, int len) 43 | { 44 | int i; 45 | 46 | if (len > MAX_KEY_SIZE) 47 | { 48 | PyErr_Format(PyExc_ValueError, 49 | "XOR key must be no longer than %d bytes", 50 | MAX_KEY_SIZE); 51 | return; 52 | } 53 | self->keylen = len; 54 | self->last_pos = 0; 55 | 56 | for(i=0; ikey[i] = key[i]; 59 | } 60 | } 61 | 62 | /* Encryption and decryption are symmetric */ 63 | #define stream_decrypt stream_encrypt 64 | 65 | static void stream_encrypt(stream_state *self, unsigned char *block, 66 | int len) 67 | { 68 | int i, j = self->last_pos; 69 | for(i=0; ikeylen) 70 | { 71 | block[i] ^= self->key[j]; 72 | } 73 | self->last_pos = j; 74 | } 75 | 76 | #include "stream_template.c" 77 | -------------------------------------------------------------------------------- /Charm/charm/core/crypto/cryptobase/_counter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * _counter.h: Fast counter for use with CTR-mode ciphers 3 | * 4 | * Written in 2008 by Dwayne C. Litzenberger 5 | * 6 | * =================================================================== 7 | * The contents of this file are dedicated to the public domain. To 8 | * the extent that dedication to the public domain is not available, 9 | * everyone is granted a worldwide, perpetual, royalty-free, 10 | * non-exclusive license to exercise all rights associated with the 11 | * contents of this file for any purpose whatsoever. 12 | * No rights are reserved. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 18 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 19 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | * =================================================================== 23 | */ 24 | #ifndef PCT__COUNTER_H 25 | #define PCT__COUNTER_H 26 | 27 | #include 28 | #include "Python.h" 29 | 30 | typedef struct { 31 | PyObject_HEAD 32 | PyUnicodeObject *prefix; /* Prefix (useful for a nonce) */ 33 | PyUnicodeObject *suffix; /* Suffix (useful for a nonce) */ 34 | uint8_t *val; /* Buffer for our output string */ 35 | uint32_t buf_size; /* Size of the buffer */ 36 | uint8_t *p; /* Pointer to the part of the buffer that we're allowed to update */ 37 | uint16_t nbytes; /* The number of bytes that from .p that are part of the counter */ 38 | void (*inc_func)(void *); /* Pointer to the counter increment function */ 39 | int shortcut_disabled; /* This gets set to a non-zero value when the shortcut mechanism is disabled */ 40 | int carry; /* This gets set by Counter*Object_increment when the counter wraps around */ 41 | int allow_wraparound; /* When this is false, we raise OverflowError on next_value() or __call__() when the counter wraps around */ 42 | } PCT_CounterObject; 43 | 44 | #endif /* PCT__COUNTER_H */ 45 | -------------------------------------------------------------------------------- /Charm/charm/core/crypto/cryptobase/block_template.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef BLOCK_TEMPLATE_H 4 | #define BLOCK_TEMPLATE_H 5 | 6 | #ifdef HAVE_CONFIG_H 7 | #include "config.h" 8 | #endif 9 | 10 | #ifdef _HAVE_STDC_HEADERS 11 | #include 12 | #endif 13 | 14 | #include 15 | #include 16 | #include "modsupport.h" 17 | #include "_counter.h" 18 | 19 | #define TRUE 1 20 | #define FALSE 0 21 | 22 | /* Cipher operation modes */ 23 | #define MODE_ECB 1 24 | #define MODE_CBC 2 25 | #define MODE_CFB 3 26 | #define MODE_PGP 4 27 | #define MODE_OFB 5 28 | #define MODE_CTR 6 29 | 30 | #define _STR(x) #x 31 | #define _XSTR(x) _STR(x) 32 | #define _PASTE(x,y) x##y 33 | #define _PASTE2(x,y) _PASTE(x,y) 34 | #define _MODULE_STRING _XSTR(MODULE_NAME) 35 | 36 | #if PY_MAJOR_VERSION >= 3 37 | #define _MODULE_NAME _PASTE2(PyInit_, MODULE_NAME) 38 | #else 39 | #define _MODULE_NAME _PASTE2(init,MODULE_NAME) 40 | #endif 41 | 42 | typedef struct 43 | { 44 | PyObject_HEAD 45 | int mode, count, segment_size, prf_mode; 46 | unsigned char IV[BLOCK_SIZE], oldCipher[BLOCK_SIZE]; 47 | PyObject *counter; 48 | int counter_shortcut; 49 | block_state st; 50 | } ALGobject; 51 | 52 | // staticforward PyTypeObject ALGtype; 53 | static PyTypeObject ALGtype; 54 | 55 | #define is_ALGobject(v) ((v)->ob_type == &ALGtype) 56 | 57 | PyMemberDef ALGmembers[]; 58 | PyMethodDef ALGmethods[]; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /Charm/charm/core/crypto/cryptobase/libtom/tomcrypt.h: -------------------------------------------------------------------------------- 1 | #ifndef TOMCRYPT_H_ 2 | #define TOMCRYPT_H_ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /* use configuration data */ 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | /* version */ 19 | #define CRYPT 0x0116 20 | #define SCRYPT "1.16" 21 | 22 | /* max size of either a cipher/hash block or symmetric key [largest of the two] */ 23 | #define MAXBLOCKSIZE 128 24 | 25 | /* descriptor table size */ 26 | #define TAB_SIZE 32 27 | 28 | /* error codes [will be expanded in future releases] */ 29 | enum { 30 | CRYPT_OK=0, /* Result OK */ 31 | CRYPT_ERROR, /* Generic Error */ 32 | CRYPT_NOP, /* Not a failure but no operation was performed */ 33 | 34 | CRYPT_INVALID_KEYSIZE, /* Invalid key size given */ 35 | CRYPT_INVALID_ROUNDS, /* Invalid number of rounds */ 36 | CRYPT_FAIL_TESTVECTOR, /* Algorithm failed test vectors */ 37 | 38 | CRYPT_BUFFER_OVERFLOW, /* Not enough space for output */ 39 | CRYPT_INVALID_PACKET, /* Invalid input packet given */ 40 | 41 | CRYPT_INVALID_PRNGSIZE, /* Invalid number of bits for a PRNG */ 42 | CRYPT_ERROR_READPRNG, /* Could not read enough from PRNG */ 43 | 44 | CRYPT_INVALID_CIPHER, /* Invalid cipher specified */ 45 | CRYPT_INVALID_HASH, /* Invalid hash specified */ 46 | CRYPT_INVALID_PRNG, /* Invalid PRNG specified */ 47 | 48 | CRYPT_MEM, /* Out of memory */ 49 | 50 | CRYPT_PK_TYPE_MISMATCH, /* Not equivalent types of PK keys */ 51 | CRYPT_PK_NOT_PRIVATE, /* Requires a private PK key */ 52 | 53 | CRYPT_INVALID_ARG, /* Generic invalid argument */ 54 | CRYPT_FILE_NOTFOUND, /* File Not Found */ 55 | 56 | CRYPT_PK_INVALID_TYPE, /* Invalid type of PK key */ 57 | CRYPT_PK_INVALID_SYSTEM,/* Invalid PK system specified */ 58 | CRYPT_PK_DUP, /* Duplicate key already in key ring */ 59 | CRYPT_PK_NOT_FOUND, /* Key not found in keyring */ 60 | CRYPT_PK_INVALID_SIZE, /* Invalid size input for PK parameters */ 61 | 62 | CRYPT_INVALID_PRIME_SIZE,/* Invalid size of prime requested */ 63 | CRYPT_PK_INVALID_PADDING /* Invalid padding on input */ 64 | }; 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | #endif /* TOMCRYPT_H_ */ 83 | 84 | 85 | /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt.h,v $ */ 86 | /* $Revision: 1.20 $ */ 87 | /* $Date: 2006/11/26 01:45:14 $ */ 88 | -------------------------------------------------------------------------------- /Charm/charm/core/crypto/cryptobase/libtom/tomcrypt_argchk.h: -------------------------------------------------------------------------------- 1 | /* Defines the LTC_ARGCHK macro used within the library */ 2 | /* ARGTYPE is defined in mycrypt_cfg.h */ 3 | #if ARGTYPE == 0 4 | 5 | #include 6 | 7 | /* this is the default LibTomCrypt macro */ 8 | void crypt_argchk(char *v, char *s, int d); 9 | #define LTC_ARGCHK(x) if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } 10 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 11 | 12 | #elif ARGTYPE == 1 13 | 14 | /* fatal type of error */ 15 | #define LTC_ARGCHK(x) assert((x)) 16 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 17 | 18 | #elif ARGTYPE == 2 19 | 20 | #define LTC_ARGCHK(x) if (!(x)) { fprintf(stderr, "\nwarning: ARGCHK failed at %s:%d\n", __FILE__, __LINE__); } 21 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 22 | 23 | #elif ARGTYPE == 3 24 | 25 | #define LTC_ARGCHK(x) 26 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 27 | 28 | #elif ARGTYPE == 4 29 | 30 | #define LTC_ARGCHK(x) if (!(x)) return CRYPT_INVALID_ARG; 31 | #define LTC_ARGCHKVD(x) if (!(x)) return; 32 | 33 | #endif 34 | 35 | 36 | /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_argchk.h,v $ */ 37 | /* $Revision: 1.5 $ */ 38 | /* $Date: 2006/08/27 20:50:21 $ */ 39 | -------------------------------------------------------------------------------- /Charm/charm/core/crypto/cryptobase/libtom/tomcrypt_misc.h: -------------------------------------------------------------------------------- 1 | /* ---- BASE64 Routines ---- */ 2 | #ifdef BASE64 3 | int base64_encode(const unsigned char *in, unsigned long len, 4 | unsigned char *out, unsigned long *outlen); 5 | 6 | int base64_decode(const unsigned char *in, unsigned long len, 7 | unsigned char *out, unsigned long *outlen); 8 | #endif 9 | 10 | /* ---- MEM routines ---- */ 11 | void zeromem(void *dst, size_t len); 12 | void burn_stack(unsigned long len); 13 | 14 | const char *error_to_string(int err); 15 | 16 | extern const char *crypt_build_settings; 17 | 18 | /* ---- HMM ---- */ 19 | int crypt_fsa(void *mp, ...); 20 | 21 | /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_misc.h,v $ */ 22 | /* $Revision: 1.4 $ */ 23 | /* $Date: 2006/11/06 03:03:01 $ */ 24 | -------------------------------------------------------------------------------- /Charm/charm/core/engine/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | #from protocol import * 3 | #from util import * 4 | 5 | 6 | -------------------------------------------------------------------------------- /Charm/charm/core/math/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/math/__init__.py -------------------------------------------------------------------------------- /Charm/charm/core/math/elliptic_curve.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/math/elliptic_curve.so -------------------------------------------------------------------------------- /Charm/charm/core/math/integer.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/math/integer.so -------------------------------------------------------------------------------- /Charm/charm/core/math/pairing.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/core/math/pairing.so -------------------------------------------------------------------------------- /Charm/charm/core/utilities/base64.h: -------------------------------------------------------------------------------- 1 | #ifndef __BASE64_H__ 2 | #define __BASE_64_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define TRUE 1 9 | #define FALSE 0 10 | 11 | void *NewBase64Decode(const char *inputBuffer, size_t length, size_t *outputLength); 12 | 13 | char *NewBase64Encode(const void *inputBuffer, size_t length, int separateLines, size_t *outputLength); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /Charm/charm/core/utilities/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sha1.h 3 | * 4 | * Copyright (C) 1998, 2009 5 | * Paul E. Jones 6 | * All Rights Reserved 7 | * 8 | ***************************************************************************** 9 | * $Id: sha1.h 12 2009-06-22 19:34:25Z paulej $ 10 | ***************************************************************************** 11 | * 12 | * Description: 13 | * This class implements the Secure Hashing Standard as defined 14 | * in FIPS PUB 180-1 published April 17, 1995. 15 | * 16 | * Many of the variable names in the SHA1Context, especially the 17 | * single character names, were used because those were the names 18 | * used in the publication. 19 | * 20 | * Please read the file sha1.c for more information. 21 | * 22 | */ 23 | 24 | #ifndef _SHA1_H_ 25 | #define _SHA1_H_ 26 | 27 | /* 28 | * This structure will hold context information for the hashing 29 | * operation 30 | */ 31 | typedef struct SHA1Context 32 | { 33 | unsigned Message_Digest[5]; /* Message Digest (output) */ 34 | 35 | unsigned Length_Low; /* Message length in bits */ 36 | unsigned Length_High; /* Message length in bits */ 37 | 38 | unsigned char Message_Block[64]; /* 512-bit message blocks */ 39 | int Message_Block_Index; /* Index into message block array */ 40 | 41 | int Computed; /* Is the digest computed? */ 42 | int Corrupted; /* Is the message digest corruped? */ 43 | } SHA1Context; 44 | 45 | /* 46 | * Function Prototypes 47 | */ 48 | void SHA1Reset(SHA1Context *); 49 | int SHA1Result(SHA1Context *); 50 | void SHA1Input( SHA1Context *, 51 | const unsigned char *, 52 | unsigned); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /Charm/charm/schemes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/schemes/__init__.py -------------------------------------------------------------------------------- /Charm/charm/schemes/abenc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/schemes/abenc/__init__.py -------------------------------------------------------------------------------- /Charm/charm/schemes/chamhash_adm05.py: -------------------------------------------------------------------------------- 1 | ''' Ateneise-Medeiros (Schnorr group-based) 2 | 3 | | From: "Ateneise-Breno de Medeiros On the Key Exposure Problem in Chameleon Hashes", Section 4. 4 | | Published in: SCN 2004 5 | | Available from: 6 | | Notes: 7 | 8 | * type: hash function (chameleon) 9 | * setting: Schnorr groups 10 | * assumption: DL-Hard 11 | 12 | :Authors: J Ayo Akinyele 13 | :Date: 4/2011 14 | ''' 15 | from charm.toolbox.Hash import ChamHash,Hash 16 | from charm.toolbox.integergroup import IntegerGroupQ 17 | 18 | debug = False 19 | class ChamHash_Adm05(ChamHash): 20 | """ 21 | >>> from charm.core.math.integer import integer 22 | >>> p = integer(141660875619984104245410764464185421040193281776686085728248762539241852738181649330509191671665849071206347515263344232662465937366909502530516774705282764748558934610432918614104329009095808618770549804432868118610669336907161081169097403439689930233383598055540343198389409225338204714777812724565461351567) 23 | >>> q = integer(70830437809992052122705382232092710520096640888343042864124381269620926369090824665254595835832924535603173757631672116331232968683454751265258387352641382374279467305216459307052164504547904309385274902216434059305334668453580540584548701719844965116691799027770171599194704612669102357388906362282730675783) 24 | >>> chamHash = ChamHash_Adm05(p, q) 25 | >>> (public_key, secret_key) = chamHash.paramgen() 26 | >>> msg = "hello world this is the message" 27 | >>> c = chamHash.hash(public_key, msg) 28 | >>> c == chamHash.hash(public_key, msg, c[1], c[2]) 29 | True 30 | """ 31 | 32 | def __init__(self, p=0, q=0): 33 | ChamHash.__init__(self) 34 | global group; 35 | group = IntegerGroupQ(0) 36 | # if p and q parameters have already been selected 37 | group.p, group.q, group.r = p, q, 2 38 | self.group = group 39 | 40 | def paramgen(self, secparam=1024): 41 | if group.p == 0 or group.q == 0: 42 | group.paramgen(secparam) 43 | g, x = group.randomGen(), group.random() # g, [1,q-1] 44 | y = g ** x 45 | 46 | if debug: 47 | print("Public params") 48 | print("g =>", g); print("y =>", y) 49 | 50 | pk = { 'g':g, 'y':y } 51 | sk = { 'x':x } 52 | return (pk, sk) 53 | 54 | def hash(self, pk, m, r = 0, s = 0): 55 | p,q = group.p, group.q 56 | if r == 0: r = group.random() 57 | if s == 0: s = group.random() 58 | e = group.hash(m, r) 59 | 60 | C = r - (((pk['y'] ** e) * (pk['g'] ** s)) % p) % q 61 | return (C, r, s) 62 | 63 | -------------------------------------------------------------------------------- /Charm/charm/schemes/chamhash_rsa_hw09.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Hohenberger-Waters Chameleon Hash (RSA-based) 3 | based on the scheme of Ateneise and de Medeiros 4 | 5 | | From: "S. Hohenberger, B. Waters. Realizing Hash-and-Sign Signatures under Standard Assumptions", Appendix A. 6 | | Published in: Eurocrypt 2009 7 | | Available from: http://eprint.iacr.org/2009/028.pdf 8 | | Notes: 9 | 10 | * type: hash function (chameleon) 11 | * setting: RSA 12 | * assumption: RSA 13 | 14 | :Author: J. Ayo Akinyele 15 | :Date: 1/2011 16 | ''' 17 | 18 | from charm.toolbox.Hash import ChamHash,Hash 19 | from charm.toolbox.integergroup import IntegerGroupQ,gcd 20 | from charm.toolbox.conversion import Conversion 21 | 22 | debug=False 23 | class ChamHash_HW09(ChamHash): 24 | """ 25 | >>> from charm.core.math.integer import integer 26 | >>> p = integer(164960892556379843852747960442703555069442262500242170785496141408191025653791149960117681934982863436763270287998062485836533436731979391762052869620652382502450810563192532079839617163226459506619269739544815249458016088505187490329968102214003929285843634017082702266003694786919671197914296386150563930299) 27 | >>> q = integer(82480446278189921926373980221351777534721131250121085392748070704095512826895574980058840967491431718381635143999031242918266718365989695881026434810326191251225405281596266039919808581613229753309634869772407624729008044252593745164984051107001964642921817008541351133001847393459835598957148193075281965149) 28 | >>> chamHash = ChamHash_HW09() 29 | >>> (public_key, secret_key) = chamHash.paramgen(1024, p, q) 30 | >>> msg = "Hello world this is the message!" 31 | >>> (hash1, r) = chamHash.hash(public_key, msg) 32 | >>> (hash2, r) = chamHash.hash(public_key, msg, r) 33 | >>> hash1 == hash2 34 | True 35 | """ 36 | def __init__(self): 37 | global group 38 | group = IntegerGroupQ(0) 39 | 40 | def paramgen(self, secparam, p = 0, q = 0): 41 | # If we're given p, q, compute N = p*q. Otherwise select random p, q 42 | if not (p == 0 or q == 0): 43 | N = p * q 44 | if debug: print("p :=", p) 45 | if debug: print("q :=", q) 46 | else: 47 | group.paramgen(secparam) 48 | p, q = group.p, group.q 49 | N = p * q 50 | 51 | phi_N = (p-1)*(q-1) 52 | J = group.random(N) 53 | e = group.random(phi_N) 54 | while (not gcd(e, phi_N) == 1): 55 | e = group.random(phi_N) 56 | pk = { 'secparam': secparam, 'N': N, 'J': J, 'e': e } 57 | sk = { 'p': p, 'q': q } 58 | return (pk, sk) 59 | 60 | def hash(self, pk, message, r = 0): 61 | N, J, e = pk['N'], pk['J'], pk['e'] 62 | if r == 0: 63 | r = group.random(N) 64 | M = Conversion.bytes2integer(message) 65 | h = ((J ** M) * (r ** e)) % N 66 | return (h, r) 67 | 68 | -------------------------------------------------------------------------------- /Charm/charm/schemes/commit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/schemes/commit/__init__.py -------------------------------------------------------------------------------- /Charm/charm/schemes/commit/commit_gs08.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Groth-Sahai Commitment Scheme 3 | 4 | | From: "J. Groth, A. Sahai. Efficient Non-interactive Proof Systems for Bilinear Groups". 5 | | Published in: Eurocrypt 2008 6 | | Available from: http://www.cs.ucl.ac.uk/staff/J.Groth/WImoduleFull.pdf 7 | | Notes: This implements only the SXDH and DLIN instantiations, in prime-order groups. 8 | 9 | * type: commitment 10 | * setting: bilinear groups 11 | 12 | :Authors: Matthew Green 13 | :Date: 6/2011 14 | ''' 15 | 16 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair 17 | from charm.toolbox.Commit import * 18 | 19 | debug=False 20 | class Commitment_GS08(Commitment): 21 | """ 22 | >>> group = PairingGroup('SS512') 23 | >>> alg = Commitment_GS08(group) 24 | >>> public_key = alg.setup() 25 | >>> msg = group.random(G1) 26 | >>> (commit, decommit) = alg.commit(public_key, msg) 27 | >>> alg.decommit(public_key, commit, decommit, msg) 28 | True 29 | """ 30 | def __init__(self, groupObj, setting='SXDH'): 31 | Commitment.__init__(self) 32 | #Commitment.setProperty(self, secdef='CM_PHCB', assumption=['SXDH','DLIN'], message_space=[G1, 'KEM'], secmodel='SM') 33 | global group 34 | group = groupObj 35 | 36 | # Generates commitment parameters for either G1 or G2 (specified by groupChoice). 37 | # By default this generates the binding commitment parameters. Set commitType to 'hiding' 38 | # in order to generate hiding parameters. 39 | def setup(self, secparam=None, groupChoice=G1, commitType='binding'): 40 | g1, h1 = group.random(groupChoice), group.random(groupChoice) 41 | s, t = group.random(ZR), group.random(ZR) 42 | if (commitType == 'binding'): 43 | g2, h2 = g1 ** s, h1 ** s 44 | else: 45 | g2, h2 = g1 ** s, h1 ** t 46 | 47 | return (g1, g2, h1, h2) 48 | # msg => ZR 49 | def commit(self, params, msg): 50 | # TODO: check that the message is in the same group as the params 51 | (g1, g2, h1, h2) = params 52 | r1, r2 = group.random(ZR), group.random(ZR) 53 | 54 | c1 = (g1 ** r1) * (h1 ** r2) 55 | c2 = msg * (g2 ** r1) * (h2 ** r2) 56 | 57 | return ({ 'c1':c1, 'c2':c2 }, { 'r1':r1, 'r2':r2 }) 58 | 59 | def decommit(self, params, c, d, msg): 60 | # TODO: check that the message is in the same group as the params 61 | (g1, g2, h1, h2) = params 62 | 63 | if (not (c['c1'] == ((g1 ** d['r1']) * (h1 ** d['r2'])))): 64 | return False 65 | 66 | if (not ((c['c2'] / msg) == ((g2 ** d['r1']) * (h2 ** d['r2'])))): 67 | return False 68 | 69 | return True 70 | 71 | -------------------------------------------------------------------------------- /Charm/charm/schemes/commit/commit_pedersen92.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.ecgroup import ECGroup,ZR,G 2 | from charm.toolbox.Commit import Commitment 3 | 4 | debug = False 5 | class CM_Ped92(Commitment): 6 | """ 7 | >>> group = ECGroup(410) 8 | >>> alg = CM_Ped92(group) 9 | >>> public_key = alg.setup() 10 | >>> msg = group.random(ZR) 11 | >>> (commit, decommit) = alg.commit(public_key, msg) 12 | >>> alg.decommit(public_key, commit, decommit, msg) 13 | True 14 | """ 15 | def __init__(self, groupObj): 16 | Commitment.__init__(self) 17 | global group 18 | group = groupObj 19 | 20 | def setup(self, secparam=None): 21 | return {'g': group.random(G), 'h':group.random(G)} 22 | 23 | def commit(self, pk, msg): 24 | r = group.random(ZR) 25 | c = (pk['g'] ** msg) * (pk['h'] ** r) 26 | d = r 27 | return (c,d) 28 | 29 | def decommit(self, pk, c, d, msg): 30 | return c == (pk['g'] ** msg) * (pk['h'] ** d) 31 | 32 | -------------------------------------------------------------------------------- /Charm/charm/schemes/encap_bchk05.py: -------------------------------------------------------------------------------- 1 | from charm.core.math.integer import randomBits 2 | import hashlib 3 | 4 | debug = False 5 | class EncapBCHK(): 6 | """ 7 | >>> encap = EncapBCHK() 8 | >>> hout = encap.setup() 9 | >>> (r, com, dec) = encap.S(hout) 10 | >>> rout = encap.R(hout, com, dec) 11 | >>> r == rout 12 | True 13 | """ 14 | def __init__(self): 15 | global H 16 | H = hashlib.sha1() 17 | 18 | def setup(self): 19 | pub = hashlib.md5() 20 | return pub 21 | 22 | def S(self, pub): 23 | x = randomBits(448) 24 | x = str(x).zfill(135) 25 | 26 | r = hashlib.md5(x.encode('utf-8')).digest() 27 | 28 | com = hashlib.sha1(x.encode('utf-8')).digest()[:128] 29 | 30 | dec = x 31 | 32 | return (r, com, dec) 33 | 34 | def R(self, pub, com, dec): 35 | x = hashlib.sha1(str(dec).encode('utf-8')).digest()[:128] 36 | 37 | if(x == com): 38 | m = hashlib.md5(str(dec).encode('utf-8')).digest() 39 | return m 40 | else: 41 | return b'FALSE' 42 | 43 | -------------------------------------------------------------------------------- /Charm/charm/schemes/grpsig/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/schemes/grpsig/__init__.py -------------------------------------------------------------------------------- /Charm/charm/schemes/hibenc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/schemes/hibenc/__init__.py -------------------------------------------------------------------------------- /Charm/charm/schemes/ibenc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/schemes/ibenc/__init__.py -------------------------------------------------------------------------------- /Charm/charm/schemes/pkenc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/schemes/pkenc/__init__.py -------------------------------------------------------------------------------- /Charm/charm/schemes/pksig/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/schemes/pksig/__init__.py -------------------------------------------------------------------------------- /Charm/charm/schemes/pksig/pksig_bls04.py: -------------------------------------------------------------------------------- 1 | ''' 2 | :Boneh-Lynn-Shacham Identity Based Signature 3 | 4 | | From: "D. Boneh, B. Lynn, H. Shacham Short Signatures from the Weil Pairing" 5 | | Published in: Journal of Cryptology 2004 6 | | Available from: http:// 7 | | Notes: This is the IBE (2-level HIBE) implementation of the HIBE scheme BB_2. 8 | 9 | * type: signature (identity-based) 10 | * setting: bilinear groups (asymmetric) 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 1/2011 14 | ''' 15 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,pair 16 | from charm.core.engine.util import objectToBytes 17 | 18 | debug = False 19 | class IBSig(): 20 | """ 21 | >>> from charm.toolbox.pairinggroup import PairingGroup 22 | >>> group = PairingGroup('MNT224') 23 | >>> messages = { 'a':"hello world!!!" , 'b':"test message" } 24 | >>> ib = IBSig(group) 25 | >>> (public_key, secret_key) = ib.keygen() 26 | >>> signature = ib.sign(secret_key['x'], messages) 27 | >>> ib.verify(public_key, signature, messages) 28 | True 29 | """ 30 | def __init__(self, groupObj): 31 | global group 32 | group = groupObj 33 | 34 | def dump(self, obj): 35 | return objectToBytes(obj, group) 36 | 37 | def keygen(self, secparam=None): 38 | g, x = group.random(G2), group.random() 39 | g_x = g ** x 40 | pk = { 'g^x':g_x, 'g':g, 'identity':str(g_x), 'secparam':secparam } 41 | sk = { 'x':x } 42 | return (pk, sk) 43 | 44 | def sign(self, x, message): 45 | M = self.dump(message) 46 | if debug: print("Message => '%s'" % M) 47 | return group.hash(M, G1) ** x 48 | 49 | def verify(self, pk, sig, message): 50 | M = self.dump(message) 51 | h = group.hash(M, G1) 52 | if pair(sig, pk['g']) == pair(h, pk['g^x']): 53 | return True 54 | return False 55 | 56 | def main(): 57 | groupObj = PairingGroup('MNT224') 58 | 59 | m = { 'a':"hello world!!!" , 'b':"test message" } 60 | bls = IBSig(groupObj) 61 | 62 | (pk, sk) = bls.keygen() 63 | 64 | sig = bls.sign(sk['x'], m) 65 | 66 | if debug: print("Message: '%s'" % m) 67 | if debug: print("Signature: '%s'" % sig) 68 | assert bls.verify(pk, sig, m), "Failure!!!" 69 | if debug: print('SUCCESS!!!') 70 | 71 | if __name__ == "__main__": 72 | debug = True 73 | main() 74 | -------------------------------------------------------------------------------- /Charm/charm/schemes/pksig/pksig_chch.py: -------------------------------------------------------------------------------- 1 | """ 2 | Jae Choon Cha and Jung Hee Cheon - Identity-based Signatures 3 | 4 | | From: "J. Cha and J. Choen - An identity-based signature from gap Diffie-Hellman groups." 5 | | Published in: PKC 2003 6 | | Available from: Vol. 2567. LNCS, pages 18-30 7 | | Notes: 8 | 9 | * type: signature (ID-based) 10 | * setting: bilinear groups (asymmetric) 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 11/2011 14 | """ 15 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair 16 | from charm.toolbox.PKSig import PKSig 17 | 18 | debug = False 19 | class CHCH(PKSig): 20 | """ 21 | >>> from charm.toolbox.pairinggroup import PairingGroup 22 | >>> group = PairingGroup('SS512') 23 | >>> chch = CHCH(group) 24 | >>> (master_public_key, master_secret_key) = chch.setup() 25 | >>> ID = "janedoe@email.com" 26 | >>> (public_key, secret_key) = chch.keygen(master_secret_key, ID) 27 | >>> msg = "this is a message!" 28 | >>> signature = chch.sign(public_key, secret_key, msg) 29 | >>> chch.verify(master_public_key, public_key, msg, signature) 30 | True 31 | """ 32 | def __init__(self, groupObj): 33 | global group,H1,H2 34 | group = groupObj 35 | H1 = lambda x: group.hash(x, G1) 36 | H2 = lambda x,y: group.hash((x,y), ZR) 37 | 38 | def setup(self): 39 | g2, alpha = group.random(G2), group.random(ZR) 40 | msk = alpha 41 | P = g2 ** alpha 42 | mpk = {'P':P, 'g2':g2} 43 | return (mpk, msk) 44 | 45 | def keygen(self, msk, ID): 46 | alpha = msk 47 | sk = H1(ID) ** alpha 48 | pk = H1(ID) 49 | return (pk, sk) 50 | 51 | def sign(self, pk, sk, M): 52 | if debug: print("sign...") 53 | s = group.random(ZR) 54 | S1 = pk ** s 55 | a = H2(M, S1) 56 | S2 = sk ** (s + a) 57 | return {'S1':S1, 'S2':S2} 58 | 59 | def verify(self, mpk, pk, M, sig): 60 | if debug: print("verify...") 61 | (S1, S2) = sig['S1'], sig['S2'] 62 | a = H2(M, S1) 63 | if pair(S2, mpk['g2']) == pair(S1 * (pk ** a), mpk['P']): 64 | return True 65 | return False 66 | 67 | def main(): 68 | groupObj = PairingGroup('SS512') 69 | chch = CHCH(groupObj) 70 | (mpk, msk) = chch.setup() 71 | 72 | _id = "janedoe@email.com" 73 | (pk, sk) = chch.keygen(msk, _id) 74 | if debug: 75 | print("Keygen...") 76 | print("pk =>", pk) 77 | print("sk =>", sk) 78 | 79 | M = "this is a message!" 80 | sig = chch.sign(pk, sk, M) 81 | if debug: 82 | print("Signature...") 83 | print("sig =>", sig) 84 | 85 | assert chch.verify(mpk, pk, M, sig), "invalid signature!" 86 | if debug: print("Verification successful!") 87 | 88 | if __name__ == "__main__": 89 | debug = True 90 | main() 91 | -------------------------------------------------------------------------------- /Charm/charm/schemes/pksig/pksig_chp.py: -------------------------------------------------------------------------------- 1 | """ 2 | Camenisch-Hohenberger-Pedersen - Identity-based Signatures 3 | 4 | | From: "Camenisch, S. Hohenberger, M. Pedersen - Batch Verification of short signatures." 5 | | Published in: EUROCRYPT 2007 6 | | Available from: http://epring.iacr.org/2007/172.pdf 7 | | Notes: 8 | 9 | * type: signature (ID-based) 10 | * setting: bilinear groups (asymmetric) 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 11/2011 14 | """ 15 | from charm.toolbox.pairinggroup import G1,G2,ZR,pair 16 | from charm.toolbox.PKSig import PKSig 17 | 18 | debug = False 19 | 20 | class CHP(PKSig): 21 | """ 22 | >>> from charm.toolbox.pairinggroup import PairingGroup 23 | >>> group = PairingGroup('SS512') 24 | >>> chp = CHP(group) 25 | >>> master_public_key = chp.setup() 26 | >>> (public_key, secret_key) = chp.keygen(master_public_key) 27 | >>> msg = { 't1':'time_1', 't2':'time_2', 't3':'time_3', 'str':'this is the message'} 28 | >>> signature = chp.sign(public_key, secret_key, msg) 29 | >>> chp.verify(master_public_key, public_key, msg, signature) 30 | True 31 | """ 32 | def __init__(self, groupObj): 33 | global group, H 34 | group = groupObj 35 | 36 | def setup(self): 37 | global H,H3 38 | H = lambda prefix,x: group.hash((str(prefix), str(x)), G1) 39 | H3 = lambda a,b: group.hash(('3', str(a), str(b)), ZR) 40 | g = group.random(G2) 41 | return { 'g' : g } 42 | 43 | def keygen(self, mpk): 44 | alpha = group.random(ZR) 45 | sk = alpha 46 | pk = mpk['g'] ** alpha 47 | return (pk, sk) 48 | 49 | def sign(self, pk, sk, M): 50 | a = H(1, M['t1']) 51 | h = H(2, M['t2']) 52 | b = H3(M['str'], M['t3']) 53 | sig = (a ** sk) * (h ** (sk * b)) 54 | return sig 55 | 56 | def verify(self, mpk, pk, M, sig): 57 | a = H(1, M['t1']) 58 | h = H(2, M['t2']) 59 | b = H3(M['str'], M['t3']) 60 | if pair(sig, mpk['g']) == (pair(a, pk) * (pair(h, pk) ** b)): 61 | return True 62 | return False 63 | 64 | -------------------------------------------------------------------------------- /Charm/charm/schemes/pksig/pksig_cl04.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Identity Based Signature 3 | 4 | | From: "J. Camenisch, A. Lysyanskaya. Signature Schemes and Anonymous Credentials from Bilinear Maps" 5 | | Published in: 2004 6 | | Available from: http://www.cs.brown.edu/~anna/papers/cl04.pdf 7 | | Notes: Scheme A on page 5 section 3.1. 8 | 9 | * type: signature (identity-based) 10 | * setting: bilinear groups (asymmetric) 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 1/2012 14 | ''' 15 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,pair 16 | from charm.toolbox.PKSig import PKSig 17 | 18 | debug = False 19 | class CL04(PKSig): 20 | """ 21 | >>> from charm.toolbox.pairinggroup import PairingGroup 22 | >>> group = PairingGroup('MNT224') 23 | >>> cl = CL04(group) 24 | >>> master_public_key = cl.setup() 25 | >>> (public_key, secret_key) = cl.keygen(master_public_key) 26 | >>> msg = "Please sign this stupid message!" 27 | >>> signature = cl.sign(public_key, secret_key, msg) 28 | >>> cl.verify(public_key, msg, signature) 29 | True 30 | """ 31 | def __init__(self, groupObj): 32 | global group 33 | group = groupObj 34 | 35 | def setup(self): 36 | g = group.random(G1) 37 | return { 'g': g } 38 | 39 | def keygen(self, mpk): 40 | x, y = group.random(ZR), group.random(ZR) 41 | sk = { 'x':x, 'y':y } 42 | pk = { 'X':mpk['g'] ** x, 'Y': mpk['g'] ** y, 'g':mpk['g'] } 43 | return (pk, sk) 44 | 45 | def sign(self, pk, sk, M): 46 | a = group.random(G2) 47 | m = group.hash(M, ZR) 48 | sig = {'a':a, 'a_y':a ** sk['y'], 'a_xy':a ** (sk['x'] + (m * sk['x'] * sk['y'])) } 49 | return sig 50 | 51 | def verify(self, pk, M, sig): 52 | (a, b, c) = sig['a'], sig['a_y'], sig['a_xy'] 53 | m = group.hash(M, ZR) 54 | if pair(pk['Y'], a) == pair(pk['g'], b) and (pair(pk['X'], a) * (pair(pk['X'], b) ** m)) == pair(pk['g'], c): 55 | return True 56 | return False 57 | 58 | def main(): 59 | grp = PairingGroup('MNT224') 60 | cl = CL04(grp) 61 | 62 | mpk = cl.setup() 63 | 64 | (pk, sk) = cl.keygen(mpk) 65 | if debug: 66 | print("Keygen...") 67 | print("pk :=", pk) 68 | print("sk :=", sk) 69 | 70 | M = "Please sign this stupid message!" 71 | sig = cl.sign(pk, sk, M) 72 | if debug: print("Signature: ", sig) 73 | 74 | result = cl.verify(pk, M, sig) 75 | assert result, "INVALID signature!" 76 | if debug: print("Successful Verification!!!") 77 | 78 | if __name__ == "__main__": 79 | debug = True 80 | main() 81 | -------------------------------------------------------------------------------- /Charm/charm/schemes/pksig/pksig_dsa.py: -------------------------------------------------------------------------------- 1 | """ 2 | Digital Signature Algorithm (DSA) 3 | 4 | | From: "NIST proposed in Aug 1991 for use in DSS." 5 | | Published in: FIPS 186 6 | | Available from: 7 | | Notes: 8 | 9 | * type: signature 10 | * setting: integer groups 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 5/2011 14 | """ 15 | 16 | from charm.toolbox.integergroup import IntegerGroupQ 17 | from charm.toolbox.PKSig import PKSig 18 | 19 | debug = False 20 | class DSA(PKSig): 21 | """ 22 | >>> from charm.core.math.integer import integer 23 | >>> p = integer(156053402631691285300957066846581395905893621007563090607988086498527791650834395958624527746916581251903190331297268907675919283232442999706619659475326192111220545726433895802392432934926242553363253333261282122117343404703514696108330984423475697798156574052962658373571332699002716083130212467463571362679) 24 | >>> q = integer(78026701315845642650478533423290697952946810503781545303994043249263895825417197979312263873458290625951595165648634453837959641616221499853309829737663096055610272863216947901196216467463121276681626666630641061058671702351757348054165492211737848899078287026481329186785666349501358041565106233731785681339) 25 | >>> dsa = DSA(p, q) 26 | >>> (public_key, secret_key) = dsa.keygen(1024) 27 | >>> msg = "hello world test message!!!" 28 | >>> signature = dsa.sign(public_key, secret_key, msg) 29 | >>> dsa.verify(public_key, signature, msg) 30 | True 31 | """ 32 | def __init__(self, p=0, q=0): 33 | global group 34 | group = IntegerGroupQ() 35 | group.p, group.q, group.r = p, q, 2 36 | 37 | def keygen(self, bits): 38 | if group.p == 0 or group.q == 0: 39 | group.paramgen(bits) 40 | global p,q 41 | p,q = group.p, group.q 42 | x = group.random() 43 | g = group.randomGen() 44 | y = (g ** x) % p 45 | return ({'g':g, 'y':y}, x) 46 | 47 | def sign(self, pk, x, M): 48 | while True: 49 | k = group.random() 50 | r = (pk['g'] ** k) % q 51 | s = (k ** -1) * ((group.hash(M) + x*r) % q) 52 | if (r == 0 or s == 0): 53 | print("unlikely error r = %s, s = %s" % (r,s)) 54 | continue 55 | else: 56 | break 57 | return { 'r':r, 's':s } 58 | 59 | def verify(self, pk, sig, M): 60 | w = (sig['s'] ** -1) % q 61 | u1 = (group.hash(M) * w) % q 62 | u2 = (sig['r'] * w) % q 63 | v = ((pk['g'] ** u1) * (pk['y'] ** u2)) % p 64 | v %= q 65 | if v == sig['r']: 66 | return True 67 | else: 68 | return False 69 | 70 | -------------------------------------------------------------------------------- /Charm/charm/schemes/pksig/pksig_ecdsa.py: -------------------------------------------------------------------------------- 1 | """ 2 | Digital Signature Algorithm (DSA) 3 | 4 | | From: "NIST proposed in Aug 1991 for use in DSS." 5 | | Published in: FIPS 186 6 | | Available from: 7 | | Notes: 8 | 9 | * type: signature 10 | * setting: elliptic curve groups 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 5/2011 14 | """ 15 | from charm.toolbox.ecgroup import ECGroup,ZR,G 16 | from charm.toolbox.PKSig import PKSig 17 | 18 | debug = False 19 | class ECDSA(PKSig): 20 | """ 21 | >>> from charm.toolbox.eccurve import prime192v2 22 | >>> group = ECGroup(prime192v2) 23 | >>> ecdsa = ECDSA(group) 24 | >>> (public_key, secret_key) = ecdsa.keygen(0) 25 | >>> msg = "hello world! this is a test message." 26 | >>> signature = ecdsa.sign(public_key, secret_key, msg) 27 | >>> ecdsa.verify(public_key, signature, msg) 28 | True 29 | """ 30 | def __init__(self, groupObj): 31 | PKSig.__init__(self) 32 | global group 33 | group = groupObj 34 | 35 | def keygen(self, bits): 36 | group.paramgen(bits) 37 | x, g = group.random(), group.random(G) 38 | y = (g ** x) 39 | return ({'g':g, 'y':y}, x) 40 | 41 | def sign(self, pk, x, M): 42 | while True: 43 | k = group.random() 44 | r = group.zr(pk['g'] ** k) 45 | e = group.hash(M) 46 | s = (k ** -1) * (e + x * r) 47 | if (r == 0 or s == 0): 48 | print ("unlikely error r = %s, s = %s" % (r,s)) 49 | continue 50 | else: 51 | break 52 | return { 'r':r, 's':s } 53 | 54 | def verify(self, pk, sig, M): 55 | w = sig['s'] ** -1 56 | u1 = group.hash(M) * w 57 | u2 = sig['r'] * w 58 | v = (pk['g'] ** u1) * (pk['y'] ** u2) 59 | 60 | if group.zr(v) == sig['r']: 61 | return True 62 | else: 63 | return False 64 | 65 | -------------------------------------------------------------------------------- /Charm/charm/schemes/pksig/pksig_hess.py: -------------------------------------------------------------------------------- 1 | """ 2 | Hess - Identity-based Signatures 3 | 4 | | From: "Hess - Efficient identity based signature schemes based on pairings." 5 | | Published in: Selected Areas in Cryptography 6 | | Available from: Vol. 2595. LNCS, pages 310-324 7 | | Notes: 8 | 9 | * type: signature (ID-based) 10 | * setting: bilinear groups (asymmetric) 11 | 12 | :Authors: J. Ayo Akinyele 13 | :Date: 11/2011 14 | """ 15 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,pair 16 | from charm.toolbox.PKSig import PKSig 17 | #import gc 18 | #gc.disable() 19 | #gc.set_debug(gc.DEBUG_LEAK) 20 | 21 | debug = False 22 | 23 | class Hess(PKSig): 24 | """ 25 | >>> from charm.toolbox.pairinggroup import PairingGroup 26 | >>> group = PairingGroup('SS512') 27 | >>> hess = Hess(group) 28 | >>> (master_public_key, master_secret_key) = hess.setup() 29 | >>> ID = "janedoe@email.com" 30 | >>> (public_key, secret_key) = hess.keygen(master_secret_key, ID) 31 | >>> msg = "this is a message!" 32 | >>> signature = hess.sign(master_public_key, secret_key, msg) 33 | >>> hess.verify(master_public_key, public_key, msg, signature) 34 | True 35 | """ 36 | def __init__(self, groupObj): 37 | global group,H1,H2 38 | group = groupObj 39 | H1 = lambda x: group.hash(x, G1) 40 | H2 = lambda x,y: group.hash((x,y), ZR) 41 | 42 | def setup(self): 43 | g2, alpha = group.random(G2), group.random(ZR) 44 | msk = alpha 45 | P = g2 ** alpha 46 | mpk = {'P':P, 'g2':g2} 47 | return (mpk, msk) 48 | 49 | def keygen(self, msk, ID): 50 | alpha = msk 51 | sk = H1(ID) ** alpha 52 | pk = H1(ID) 53 | return (pk, sk) 54 | 55 | def sign(self, pk, sk, M): 56 | if debug: print("sign...") 57 | h, s = group.random(G1), group.random(ZR) 58 | S1 = pair(h,pk['g2']) ** s 59 | a = H2(M, S1) 60 | S2 = (sk ** a) * (h ** s) 61 | return {'S1':S1, 'S2':S2} 62 | # return (S1, S2) 63 | 64 | 65 | def verify(self, mpk, pk, M, sig): 66 | if debug: print("verify...") 67 | (S1, S2) = sig['S1'], sig['S2'] 68 | a = H2(M, S1) 69 | if pair(S2, mpk['g2']) == (pair(pk, mpk['P']) ** a) * S1: 70 | return True 71 | return False 72 | 73 | def main(): 74 | 75 | groupObj = PairingGroup('SS512') 76 | chch = Hess(groupObj) 77 | (mpk, msk) = chch.setup() 78 | 79 | _id = "janedoe@email.com" 80 | (pk, sk) = chch.keygen(msk, _id) 81 | if debug: 82 | print("Keygen...") 83 | print("pk =>", pk) 84 | print("sk =>", sk) 85 | 86 | M = "this is a message!" 87 | sig = chch.sign(mpk, sk, M) 88 | if debug: 89 | print("Signature...") 90 | print("sig =>", sig) 91 | 92 | assert chch.verify(mpk, pk, M, sig), "invalid signature!" 93 | if debug: print("Verification successful!") 94 | 95 | if __name__ == "__main__": 96 | debug = True 97 | main() 98 | -------------------------------------------------------------------------------- /Charm/charm/schemes/pksig/pksig_schnorr91.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.integergroup import IntegerGroupQ 2 | from charm.toolbox.PKSig import PKSig 3 | 4 | debug = False 5 | class SchnorrSig(PKSig): 6 | """ 7 | >>> from charm.core.math.integer import integer 8 | >>> p = integer(156816585111264668689583680968857341596876961491501655859473581156994765485015490912709775771877391134974110808285244016265856659644360836326566918061490651852930016078015163968109160397122004869749553669499102243382571334855815358562585736488447912605222780091120196023676916968821094827532746274593222577067) 9 | >>> q = integer(78408292555632334344791840484428670798438480745750827929736790578497382742507745456354887885938695567487055404142622008132928329822180418163283459030745325926465008039007581984054580198561002434874776834749551121691285667427907679281292868244223956302611390045560098011838458484410547413766373137296611288533) 10 | >>> pksig = SchnorrSig() 11 | >>> pksig.params(p, q) 12 | >>> (public_key, secret_key) = pksig.keygen() 13 | >>> msg = "hello world." 14 | >>> signature = pksig.sign(public_key, secret_key, msg) 15 | >>> pksig.verify(public_key, signature, msg) 16 | True 17 | """ 18 | def __init__(self): 19 | PKSig.__init__(self) 20 | 21 | def params(self, p=0, q=0, bits=1024): 22 | global group 23 | group = IntegerGroupQ(0) 24 | if p == 0 or q == 0: 25 | group.paramgen(bits) 26 | else: 27 | group.p, group.q, group.r = p, q, 2 28 | 29 | def keygen(self): 30 | p = group.p 31 | x, g = group.random(), group.randomGen() 32 | y = (g ** x) 33 | return ({'y':y, 'g':g}, x) 34 | 35 | def sign(self, pk, x, M): 36 | p,q = group.p, group.q 37 | k = group.random() 38 | r = (pk['g'] ** k) % p 39 | e = group.hash(M, r) 40 | s = (k - x*e) % q 41 | 42 | return {'e':e, 's':s } 43 | 44 | def verify(self, pk, sig, M): 45 | p = group.p 46 | r = ((pk['g'] ** sig['s']) * (pk['y'] ** sig['e'])) % p 47 | if debug: print("Verifying...") 48 | e = group.hash(M, r) 49 | if debug: print("e => %s" % e) 50 | if debug: print("r => %s" % r) 51 | if e == sig['e']: 52 | return True 53 | else: 54 | return False 55 | return None 56 | 57 | -------------------------------------------------------------------------------- /Charm/charm/schemes/sigma1.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.sigmaprotocol import Sigma 2 | from charm.toolbox.pairinggroup import ZR,G2,pair 3 | 4 | class SigmaProtocol1(Sigma): 5 | def __init__(self, groupObj, common_input=None): 6 | Sigma.__init__(self, groupObj, common_input) 7 | 8 | def prover_state1(self): 9 | (g, h, H) = Sigma.get(self, ['g', 'h', 'H']) 10 | r = self.group.random(G2) 11 | a = pair(g, r) 12 | Sigma.setState(self, 3) 13 | return { 'r':r, 'a':a, 'g':g, 'h':h, 'H':H } 14 | 15 | def prover_state3(self, input): 16 | (r, h, c) = Sigma.get(self, ['r','h','c']) 17 | z = r * (h ** -c) 18 | Sigma.setState(self, 5) 19 | return {'z':z } 20 | 21 | def prover_state5(self, input): 22 | Sigma.setState(self, None) 23 | Sigma.setErrorCode(self, input) 24 | return None 25 | 26 | def verifier_state2(self, input): 27 | c = self.group.random(ZR) 28 | Sigma.setState(self, 4) 29 | return {'c':c } 30 | 31 | def verifier_state4(self, input): 32 | (g, H, a, c, z) = Sigma.get(self, ['g','H','a','c','z']) 33 | if a == (pair(g,z) * (H ** c)): 34 | print("SUCCESS!!!!!!!"); result = 'OK' 35 | else: 36 | print("Failed!!!"); result = 'FAIL' 37 | Sigma.setState(self, 6) 38 | Sigma.setErrorCode(self, result) 39 | return result 40 | 41 | def verifier_state6(self, input): 42 | Sigma.setState(self, None) 43 | return None 44 | 45 | -------------------------------------------------------------------------------- /Charm/charm/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/test/__init__.py -------------------------------------------------------------------------------- /Charm/charm/test/schemes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/test/schemes/__init__.py -------------------------------------------------------------------------------- /Charm/charm/test/schemes/chamhash_test.py: -------------------------------------------------------------------------------- 1 | from charm.schemes.chamhash_adm05 import ChamHash_Adm05 2 | from charm.schemes.chamhash_rsa_hw09 import ChamHash_HW09 3 | from charm.toolbox.integergroup import integer 4 | import unittest 5 | 6 | debug = False 7 | 8 | class ChamHash_Adm05Test(unittest.TestCase): 9 | def testChamHash_Adm05(self): 10 | # fixed params for unit tests 11 | p = integer(141660875619984104245410764464185421040193281776686085728248762539241852738181649330509191671665849071206347515263344232662465937366909502530516774705282764748558934610432918614104329009095808618770549804432868118610669336907161081169097403439689930233383598055540343198389409225338204714777812724565461351567) 12 | q = integer(70830437809992052122705382232092710520096640888343042864124381269620926369090824665254595835832924535603173757631672116331232968683454751265258387352641382374279467305216459307052164504547904309385274902216434059305334668453580540584548701719844965116691799027770171599194704612669102357388906362282730675783) 13 | chamHash = ChamHash_Adm05(p, q) 14 | #TODO: how long is paramgen supposed to take? 15 | (pk, sk) = chamHash.paramgen() 16 | if debug: print("pk => ", pk) 17 | if debug: print("sk => ", sk) 18 | 19 | msg = "Hello world this is the message!" 20 | (h, r, s) = chamHash.hash(pk, msg) 21 | if debug: print("Hash...") 22 | if debug: print("sig =>", h) 23 | 24 | (h1, r1, s1) = chamHash.hash(pk, msg, r, s) 25 | if debug: print("sig 2 =>", h1) 26 | 27 | assert h == h1, "Signature failed!!!" 28 | if debug: print("Signature generated correctly!!!") 29 | 30 | class ChamHash_HW09Test(unittest.TestCase): 31 | def testChamHash_HW09(self): 32 | # test p and q primes for unit tests only 33 | p = integer(164960892556379843852747960442703555069442262500242170785496141408191025653791149960117681934982863436763270287998062485836533436731979391762052869620652382502450810563192532079839617163226459506619269739544815249458016088505187490329968102214003929285843634017082702266003694786919671197914296386150563930299) 34 | q = integer(82480446278189921926373980221351777534721131250121085392748070704095512826895574980058840967491431718381635143999031242918266718365989695881026434810326191251225405281596266039919808581613229753309634869772407624729008044252593745164984051107001964642921817008541351133001847393459835598957148193075281965149) 35 | 36 | chamHash = ChamHash_HW09() 37 | (pk, sk) = chamHash.paramgen(1024, p, q) 38 | 39 | msg = "Hello world this is the message!" 40 | (h, r) = chamHash.hash(pk, msg) 41 | if debug: print("Hash...") 42 | if debug: print("sig =>", h) 43 | 44 | (h1, r1) = chamHash.hash(pk, msg, r) 45 | if debug: print("sig 2 =>", h1) 46 | 47 | assert h == h1, "Signature failed!!!" 48 | if debug: print("Signature generated correctly!!!") 49 | 50 | if __name__ == "__main__": 51 | unittest.main() 52 | -------------------------------------------------------------------------------- /Charm/charm/test/schemes/commit_test.py: -------------------------------------------------------------------------------- 1 | from charm.schemes.commit.commit_gs08 import Commitment_GS08 2 | from charm.schemes.commit.commit_pedersen92 import CM_Ped92 3 | from charm.toolbox.pairinggroup import PairingGroup, G1 4 | from charm.toolbox.ecgroup import ECGroup, ZR 5 | import unittest 6 | 7 | debug = False 8 | 9 | class Commitment_GS08Test(unittest.TestCase): 10 | def testCommitment_GS08(self): 11 | groupObj = PairingGroup('SS512') 12 | cm = Commitment_GS08(groupObj) 13 | 14 | pk = cm.setup() 15 | if debug: 16 | print("Public parameters...") 17 | print("pk =>", pk) 18 | 19 | m = groupObj.random(G1) 20 | if debug: print("Committing to =>", m) 21 | (c, d) = cm.commit(pk, m) 22 | 23 | assert cm.decommit(pk, c, d, m), "FAILED to decommit" 24 | if debug: print("Successful and Verified decommitment!!!") 25 | 26 | class CM_Ped92Test(unittest.TestCase): 27 | def testCM_Ped92(self): 28 | groupObj = ECGroup(410) 29 | cm = CM_Ped92(groupObj) 30 | 31 | pk = cm.setup() 32 | if debug: 33 | print("Public parameters...") 34 | print("pk =>", pk) 35 | 36 | m = groupObj.random(ZR) 37 | if debug: print("Commiting to =>", m) 38 | (c, d) = cm.commit(pk, m) 39 | 40 | assert cm.decommit(pk, c, d, m), "FAILED to decommit" 41 | if debug: print("Successful and Verified decommitment!!!") 42 | del groupObj 43 | 44 | if __name__ == "__main__": 45 | unittest.main() 46 | -------------------------------------------------------------------------------- /Charm/charm/test/schemes/encap_bchk05_test.py: -------------------------------------------------------------------------------- 1 | from charm.schemes.encap_bchk05 import EncapBCHK 2 | import unittest 3 | 4 | debug = False 5 | class EncapBCHKTest(unittest.TestCase): 6 | def testEncapBCHK(self): 7 | encap = EncapBCHK() 8 | 9 | hout = encap.setup() 10 | 11 | (r, com, dec) = encap.S(hout) 12 | 13 | rout = encap.R(hout, com, dec) 14 | 15 | if debug: print("recovered m =>", rout) 16 | 17 | assert r == rout, "Failed Decryption" 18 | if debug: print("Successful Decryption!!!") 19 | 20 | if __name__ == "__main__": 21 | unittest.main() 22 | -------------------------------------------------------------------------------- /Charm/charm/test/schemes/grpsig_test.py: -------------------------------------------------------------------------------- 1 | from charm.schemes.grpsig.groupsig_bgls04 import ShortSig as BGLS04 2 | from charm.schemes.grpsig.groupsig_bgls04_var import ShortSig as BGLS04_Var 3 | from charm.toolbox.pairinggroup import PairingGroup 4 | import unittest 5 | 6 | debug = False 7 | 8 | class BGLS04Test(unittest.TestCase): 9 | def testBGLS04(self): 10 | groupObj = PairingGroup('MNT224') 11 | n = 3 # how manu users in the group 12 | user = 1 # which user's key to sign a message with 13 | 14 | sigTest = BGLS04(groupObj) 15 | 16 | (gpk, gmsk, gsk) = sigTest.keygen(n) 17 | 18 | message = 'Hello World this is a message!' 19 | if debug: print("\n\nSign the following M: '%s'" % (message)) 20 | 21 | signature = sigTest.sign(gpk, gsk[user], message) 22 | 23 | result = sigTest.verify(gpk, message, signature) 24 | #if result: 25 | # print("Verify signers identity...") 26 | # index = sigTest.open(gpk, gmsk, message, signature) 27 | # i = 0 28 | # while i < n: 29 | # if gsk[i][0] == index: 30 | # print('Found index of signer: %d' % i) 31 | # print('A = %s' % index) 32 | # i += 1 33 | assert result, "Signature Failed" 34 | if debug: print('Complete!') 35 | 36 | class BGLS04_VarTest(unittest.TestCase): 37 | def testBGLS04_Var(self): 38 | groupObj = PairingGroup('MNT224') 39 | n = 3 # how manu users in the group 40 | user = 1 # which user's key to sign a message with 41 | 42 | sigTest = BGLS04_Var(groupObj) 43 | 44 | (gpk, gmsk, gsk) = sigTest.keygen(n) 45 | 46 | message = 'Hello World this is a message!' 47 | if debug: print("\n\nSign the following M: '%s'" % (message)) 48 | 49 | signature = sigTest.sign(gpk, gsk[user], message) 50 | 51 | result = sigTest.verify(gpk, message, signature) 52 | #if result: 53 | # print("Verify signers identity...") 54 | # index = sigTest.open(gpk, gmsk, message, signature) 55 | # i = 0 56 | # while i < n: 57 | # if gsk[i][0] == index: 58 | # print('Found index of signer: %d' % i) 59 | # print('A = %s' % index) 60 | # i += 1 61 | assert result, "Signature Failed" 62 | if debug: print('Successful Verification!') 63 | 64 | if __name__ == "__main__": 65 | unittest.main() 66 | -------------------------------------------------------------------------------- /Charm/charm/test/schemes/hibenc_test.py: -------------------------------------------------------------------------------- 1 | from charm.schemes.hibenc.hibenc_bb04 import HIBE_BB04 2 | from charm.toolbox.pairinggroup import PairingGroup, GT 3 | import unittest 4 | 5 | debug = False 6 | 7 | class HIBE_BB04Test(unittest.TestCase): 8 | def testHIBE_BB04(self): 9 | groupObj = PairingGroup('SS512') 10 | hibe = HIBE_BB04(groupObj) 11 | (mpk, mk) = hibe.setup() 12 | 13 | # represents public identity 14 | ID = "bob@mail.com" 15 | (pk, sk) = hibe.extract(3, mpk, mk, ID) 16 | # dID => pk, sk 17 | if debug: print("ID:%s , sk:%s" % (pk, sk)) 18 | 19 | M = groupObj.random(GT) 20 | if debug: print("M :=", M) 21 | ct = hibe.encrypt(mpk, pk, M) 22 | 23 | orig_M = hibe.decrypt(pk, sk, ct) 24 | assert orig_M == M, "invalid decryption!!!!" 25 | if debug: print("Successful DECRYPTION!!!") 26 | 27 | if __name__ == "__main__": 28 | unittest.main() 29 | -------------------------------------------------------------------------------- /Charm/charm/test/schemes/pk_vrf_test.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.pairinggroup import PairingGroup 2 | from charm.schemes.pk_vrf import VRF10 3 | import unittest 4 | 5 | debug = False 6 | class VRF10Test(unittest.TestCase): 7 | def testVRF10(self): 8 | grp = PairingGroup('MNT224') 9 | 10 | # bits 11 | x1 = [0, 1, 1, 0, 1, 0, 1, 0] 12 | # x2 = [1, 1, 1, 0, 1, 0, 1, 0] 13 | # block of bits 14 | n = 8 15 | 16 | vrf = VRF10(grp) 17 | 18 | # setup the VRF to accept input blocks of 8-bits 19 | (pk, sk) = vrf.setup(n) 20 | 21 | # generate proof over block x (using sk) 22 | st = vrf.prove(sk, x1) 23 | 24 | # verify bits using pk and proof 25 | assert vrf.verify(pk, x1, st), "VRF failed verification" 26 | # assert vrf.verify(pk, x2, st), "VRF should FAIL verification!!!" 27 | 28 | if __name__ == "__main__": 29 | unittest.main() 30 | -------------------------------------------------------------------------------- /Charm/charm/test/toolbox/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/test/toolbox/__init__.py -------------------------------------------------------------------------------- /Charm/charm/test/toolbox/conversion_test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Created on Jul 5, 2011 3 | 4 | :authors: Gary belvin 5 | ''' 6 | from charm.toolbox.conversion import Conversion 7 | import unittest 8 | 9 | 10 | class ConversionTest(unittest.TestCase): 11 | 12 | 13 | def testOS2IP(self): 14 | #9,202,000 = (0x)8c 69 50. 15 | i = Conversion.OS2IP(b'\x8c\x69\x50') 16 | self.assertEqual(i, 9202000) 17 | 18 | def testIP2OS(self): 19 | #9,202,000 = (0x)8c 69 50. 20 | os = Conversion.IP2OS(9202000) 21 | self.assertEqual(os, b'\x8c\x69\x50') 22 | 23 | def testIP2OSLen(self): 24 | i = 9202000 25 | os = Conversion.IP2OS(i, 200) 26 | i2 = Conversion.OS2IP(os) 27 | self.assertEqual(i, i2) 28 | 29 | if __name__ == "__main__": 30 | #import sys;sys.argv = ['', 'Test.testOS2IP'] 31 | unittest.main() 32 | -------------------------------------------------------------------------------- /Charm/charm/test/toolbox/secretshare_test.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.secretshare import SecretShare 2 | from charm.toolbox.pairinggroup import PairingGroup,ZR 3 | import unittest 4 | 5 | debug=False 6 | 7 | class SecretShareTest(unittest.TestCase): 8 | def testSecretShare(self): 9 | # Testing Secret sharing python API 10 | k = 3 11 | n = 4 12 | group = PairingGroup('SS512') 13 | 14 | s = SecretShare(group, False) 15 | sec = group.random(ZR) 16 | shares = s.genShares(sec, k, n) 17 | 18 | K = shares[0] 19 | if debug: print('\nOriginal secret: %s' % K) 20 | y = {group.init(ZR, long(1)):shares[1], group.init(ZR, long(2)):shares[2], group.init(ZR, long(3)):shares[3]} 21 | 22 | secret = s.recoverSecret(y) 23 | 24 | assert K == secret, "Could not recover the secret!" 25 | if debug: print("Successfully recovered secret: ", secret) 26 | 27 | if __name__ == "__main__": 28 | unittest.main() 29 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/ABEnc.py: -------------------------------------------------------------------------------- 1 | ''' Base class for attribute-based encryption 2 | 3 | Notes: This class implements an interface for a standard attribute-based encryption scheme. 4 | 5 | A public key attribute-based encryption scheme consists of four algorithms: 6 | (setup, keygen, encrypt, decrypt). 7 | ''' 8 | from charm.toolbox.schemebase import * 9 | 10 | class ABEnc(SchemeBase): 11 | def __init__(self): 12 | SchemeBase.__init__(self) 13 | SchemeBase.setProperty(self, scheme='ABEnc') 14 | self.baseSecDefs = Enum('IND_AB_CPA', 'IND_AB_CCA', 'sIND_AB_CPA', 'sIND_AB_CCA') 15 | 16 | def setup(self): 17 | raise NotImplementedError 18 | 19 | def keygen(self, pk, mk, object): 20 | raise NotImplementedError 21 | 22 | def encrypt(self, pk, M, object): 23 | raise NotImplementedError 24 | 25 | def decrypt(self, pk, sk, ct): 26 | raise NotImplementedError 27 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/ABEncMultiAuth.py: -------------------------------------------------------------------------------- 1 | ''' Base class for attribute-based encryption multi-authority 2 | 3 | Notes: This class implements an interface for a standard attribute-based encryption scheme. 4 | 5 | A public key attribute-based encryption scheme consists of four algorithms: 6 | (setup, authsetup, keygen, encrypt, decrypt). 7 | ''' 8 | from charm.toolbox.schemebase import * 9 | 10 | class ABEncMultiAuth(SchemeBase): 11 | def __init__(self): 12 | SchemeBase.__init__(self) 13 | SchemeBase.setProperty(self, scheme='ABEncMultiAuth') 14 | self.baseSecDefs = None 15 | 16 | def setup(self): 17 | raise NotImplementedError 18 | 19 | def authsetup(self, gp, object): 20 | raise NotImplementedError 21 | 22 | def keygen(self, gp, sk, gid): 23 | raise NotImplementedError 24 | 25 | def encrypt(self, pk, gp, M, object): 26 | raise NotImplementedError 27 | 28 | def decrypt(self, gp, sk, ct): 29 | raise NotImplementedError 30 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/Commit.py: -------------------------------------------------------------------------------- 1 | ''' Base class for commitment schemes 2 | 3 | Notes: This class implements an interface for a standard commitment scheme. 4 | A commitment scheme consists of three algorithms: (setup, commit, decommit). 5 | 6 | Allows one to commit to a value while keeping it hidden, with the ability 7 | to reveal the committed value later (wiki). 8 | ''' 9 | from charm.toolbox.schemebase import * 10 | 11 | class Commitment(SchemeBase): 12 | def __init__(self): 13 | SchemeBase.__init__(self) 14 | SchemeBase.setProperty(self, scheme='Commitment') 15 | self.baseSecDefs = None 16 | 17 | def setup(self, securityparam): 18 | raise NotImplementedError 19 | 20 | def commit(self, *args): 21 | raise NotImplementedError 22 | 23 | def decommit(self, *args): 24 | raise NotImplementedError 25 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/Hash.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.schemebase import * 2 | 3 | class Hash(SchemeBase): 4 | ''' Base class for Hash functions 5 | 6 | Notes: This class implements an interface for a standard hash function scheme. 7 | A hash function consists of two algorithms: (paramgen or keygen and hash). 8 | ''' 9 | 10 | def __init__(self): 11 | SchemeBase.__init__(self) 12 | SchemeBase.setProperty(self, scheme='Hash') 13 | self.baseSecDefs = None # Enum('EU_CMA') 14 | # base methods? 15 | def paramgen(self, *args): 16 | raise NotImplementedError 17 | 18 | def hash(self, *args): 19 | raise NotImplementedError 20 | 21 | 22 | class ChamHash(Hash): 23 | ''' 24 | Notes: This class implements an interface for a chameleon hash function. 25 | A standard charmeleon hash scheme has two algorithms paramgen and hash. 26 | paramgen accepts a security parameter and the length of p and q. Hash accepts 27 | public key, label, a message and a random element. 28 | ''' 29 | 30 | def __init__(self): 31 | Hash.__init__(self) 32 | Hash.setProperty(self, scheme='ChamHash') 33 | self.baseSecDefs = None # Enum('EU_CMA') 34 | 35 | def paramgen(self, secparam, p=None, q=None): 36 | raise NotImplementedError 37 | 38 | def hash(self, pk, prefix, message, r): 39 | raise NotImplementedError -------------------------------------------------------------------------------- /Charm/charm/toolbox/IBEnc.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Base class for identity-based encryption 3 | 4 | Notes: This class implements an interface for a standard identity-based encryption scheme. 5 | Identity-based encryption consists of three algorithms: (setup, extract, encrypt, and decrypt). 6 | ''' 7 | from charm.toolbox.schemebase import * 8 | 9 | class IBEnc(SchemeBase): 10 | def __init__(self): 11 | SchemeBase.__init__(self) 12 | SchemeBase.setProperty(self, scheme='IBEnc') 13 | self.baseSecDefs = Enum('IND_ID_CPA','sIND_ID_CPA','IND_ID_CCA','sIND_ID_CCA') 14 | 15 | def setup(self): 16 | raise NotImplementedError 17 | 18 | def extract(self, mk, ID): 19 | raise NotImplementedError 20 | 21 | def encrypt(self, pk, ID, message): 22 | raise NotImplementedError 23 | 24 | def decrypt(self, pk, sk, ct): 25 | raise NotImplementedError 26 | 27 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/PKEnc.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Base class for public-key encryption 3 | 4 | Notes: This class implements an interface for a standard public-key encryption scheme. 5 | A public key encryption consists of four algorithms: (paramgen, keygen, encrypt, decrypt). 6 | ''' 7 | from charm.toolbox.schemebase import * 8 | 9 | class PKEnc(SchemeBase): 10 | def __init__(self): 11 | SchemeBase.__init__(self) 12 | SchemeBase.setProperty(self, scheme="PKEnc") 13 | self.baseSecDefs = Enum('OW_CPA','OW_CCA1','OW_CCA','IND_CPA','IND_CCA1','IND_CCA', 14 | 'NM_CPA','NM_CCA1','NM_CCA','KA_CPA','KA_CCA1','KA_CCA') 15 | 16 | def paramgen(self, param1=None, param2=None): 17 | return NotImplemented 18 | 19 | def keygen(self, securityparam): 20 | return NotImplemented 21 | 22 | def encrypt(self, pk, M): 23 | return NotImplemented 24 | 25 | def decrypt(self, pk, sk, c): 26 | return NotImplemented 27 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/PKSig.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Base class for public-key signatures 3 | 4 | Notes: This class implements an interface for a standard public-key signature scheme. 5 | A public key signature consists of three algorithms: (keygen, sign, verify). 6 | ''' 7 | from charm.toolbox.schemebase import * 8 | 9 | class PKSig(SchemeBase): 10 | def __init__(self): 11 | SchemeBase.__init__(self) 12 | SchemeBase.setProperty(self, scheme='PKSig') 13 | self.baseSecDefs = Enum('EU_CMA', 'wEU_CMA', 'sEU_CMA') 14 | 15 | def keygen(self, securityparam): 16 | raise NotImplementedError 17 | 18 | def sign(self, pk, sk, message): 19 | raise NotImplementedError 20 | 21 | def verify(self, pk, message, sig): 22 | raise NotImplementedError 23 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/toolbox/__init__.py -------------------------------------------------------------------------------- /Charm/charm/toolbox/bitstring.py: -------------------------------------------------------------------------------- 1 | ''' 2 | ``bistring.Bytes`` is a replacement for Python's ``byte``. 3 | ''' 4 | 5 | import string 6 | import sys 7 | 8 | py3 = False 9 | if sys.hexversion >= int(0x03000000): 10 | py3 = True 11 | 12 | 13 | class Bytes(bytes): 14 | def __init__(self, value, enc=None): 15 | if enc != None: 16 | if py3: bytes.__init__(value, enc) 17 | else: bytes.__init__(value) 18 | else: 19 | bytes.__init__(value) 20 | 21 | def __xor__(self, other): 22 | '''Overload the ``^`` operator to provide xor ''' 23 | assert len(self) == len(other), "xor: operands differ in length." 24 | res = bytearray() 25 | for i in range(0,len(self)): 26 | if py3: res.append(self[i] ^ other[i]) 27 | else: res.append(chr(ord(self[i]) ^ ord(other[i]))) 28 | #print("res[%s] = %s" % (i, res[i])) 29 | return Bytes(res) 30 | 31 | def __add__(self, other): 32 | return Bytes(bytes.__add__(self, other)) 33 | 34 | @classmethod 35 | def fill(self, prefix, length): 36 | '''Provides an easy way to create a byte array of a specified length and content''' 37 | bits = b'' 38 | for i in range(0, int(length)): 39 | bits += prefix 40 | return Bytes(bits) 41 | 42 | 43 | # TODO: add left and right bit shifting 44 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/enum.py: -------------------------------------------------------------------------------- 1 | # code adapted from active state code recipes for enumeration 2 | def Enum(*names): 3 | class EnumClass(object): 4 | __slots__ = names 5 | def __iter__(self): return iter(constants) 6 | def __len__(self): return len(constants) 7 | def __getitem__(self, i): 8 | if type(i) == int: return constants[i] 9 | elif type(i) == str: 10 | index = lookup.get(i) 11 | if index != None: return constants[index] 12 | else: return None 13 | else: assert False, "Invalid input type." 14 | def __repr__(self): return 'Enum' + str(names) 15 | def __str__(self): return 'enum ' + str(constants) 16 | 17 | class EnumValue(object): 18 | __slots__ = ('__value') 19 | def __init__(self, value): self.__value = value 20 | Value = property(lambda self: self.__value) 21 | EnumType = property(lambda self: EnumType) 22 | def __hash__(self): return hash(self.__value) 23 | def __lt__(self, other): 24 | return (self.__value < other.__value) 25 | def __gt__(self, other): 26 | return (self.__value > other.__value) 27 | def __le__(self, other): 28 | return (self.__value <= other.__value) 29 | def __ge__(self, other): 30 | return (self.__value >= other.__value) 31 | def __eq__(self, other): 32 | if type(self) == int: lhs = self 33 | else: lhs = self.__value 34 | if type(other) == int: rhs = other 35 | else: rhs = other.__value 36 | return (lhs == rhs) 37 | def __ne__(self, other): 38 | if type(self) == int: lhs = self 39 | else: lhs = self.__value 40 | if type(other) == int: rhs = other 41 | else: rhs = other.__value 42 | return (lhs != rhs) 43 | def __invert__(self): return constants[maximum - self.__value] 44 | def __nonzero__(self): return bool(self.__value) 45 | def __repr__(self): return str(names[self.__value]) 46 | 47 | maximum = len(names) - 1 48 | constants = [None] * len(names) 49 | lookup = {} 50 | for i, each in enumerate(names): 51 | val = EnumValue(i) 52 | setattr(EnumClass, each, val) 53 | # create list of int => 'str' 54 | constants[i] = val 55 | # create reverse lookup 56 | lookup[str(val)] = i 57 | constants = tuple(constants) 58 | EnumType = EnumClass() 59 | return EnumType 60 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/iterate.py: -------------------------------------------------------------------------------- 1 | 2 | # simple example 3 | #>>> a = [1,2,3,4,5] 4 | #>>> dotprod(1, 1, len(a), lambda i,b: (b[i] ** 2), a) 5 | # TODO: support caching of values at each stage of product? 6 | 7 | def dotprod(init, skip, n, func, *args): 8 | prod = init 9 | i = 0 10 | for j in range(i, n): 11 | if j != skip: 12 | result = func(j, *args) 13 | # cache if necessary 14 | prod *= result 15 | #print("product =>", prod) 16 | return prod 17 | 18 | def dotprod2(iterator, func, *args): 19 | prod = 1 20 | for j in iterator: 21 | prod *= func(j, *args) 22 | return prod 23 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/redundancyschemes.py: -------------------------------------------------------------------------------- 1 | '''A collection of redundancy schemes''' 2 | from charm.toolbox.bitstring import Bytes,py3 3 | from charm.toolbox.securerandom import SecureRandomFactory 4 | import charm.core.crypto.cryptobase 5 | import hashlib 6 | import math 7 | import struct 8 | import sys 9 | 10 | debug = False 11 | 12 | 13 | class InMessageRedundancy: 14 | ''' 15 | :Authors: Christina Garman 16 | ''' 17 | def __init__(self): 18 | pass 19 | 20 | def encode(self, message): 21 | str_message = message.decode("utf-8") 22 | str_message += str_message[-8:] 23 | 24 | return str_message.encode("utf-8") 25 | 26 | def decode(self, encMessage): 27 | byte_message = bytearray(encMessage) 28 | 29 | if(byte_message[-8:] == byte_message[-16:-8]): 30 | return (True,bytes(byte_message[:-8])) 31 | else: 32 | return (False,bytes(byte_message[:-8])) 33 | 34 | class ExtraBitsRedundancy: 35 | ''' 36 | :Authors: Christina Garman 37 | 38 | TODO 39 | ''' 40 | def __init__(self): 41 | pass 42 | 43 | def encode(self, message): 44 | 45 | return Bytes(b'\x00') + maskedSeed + maskedDB 46 | 47 | def decode(self, encMessage, label=""): 48 | 49 | return M 50 | class WilliamsRedundancy: 51 | ''' 52 | :Authors: Christina Garman 53 | 54 | TODO 55 | ''' 56 | def __init__(self): 57 | pass 58 | 59 | def encode(self, message): 60 | 61 | return Bytes(b'\x00') + maskedSeed + maskedDB 62 | 63 | def decode(self, encMessage, label=""): 64 | 65 | return M 66 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/securerandom.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Base class for cryptographic secure random number generation 3 | :authors: Gary Belvin 4 | ''' 5 | from charm.toolbox.bitstring import Bytes 6 | from charm.toolbox.conversion import Conversion 7 | from charm.core.math.integer import randomBits 8 | import datetime 9 | import math 10 | import random 11 | 12 | class SecureRandom(): 13 | def __init__(self): 14 | pass 15 | def getRandomBytes(self, length): 16 | '''Returns a random bit string of length bytes''' 17 | raise NotImplementedError 18 | def addSeed(self, seed): 19 | ''' 20 | Add randomness to the generator. 21 | Always increases entropy 22 | ''' 23 | raise NotImplementedError 24 | 25 | class SecureRandomFactory(): 26 | ''' 27 | This class provides a central place to swap out the randomness engine 28 | used by the charm framework. 29 | Classes should call ``rand = SecureRandomFactory.getInstance()`` 30 | to acquire a randomnesss generator 31 | ''' 32 | @classmethod 33 | def getInstance(self): 34 | return OpenSSLRand() 35 | 36 | 37 | class OpenSSLRand(SecureRandom): 38 | '''Uses the OpenSSL PRNG for random bits''' 39 | def __init__(self): 40 | SecureRandom.__init__(self) 41 | #seed with a little bit of random data. This is not the only source 42 | #of randomness. Internally, OpenSSL samples additional physical randomness. 43 | 44 | def getRandomBytes(self, length): 45 | bits = length * 8; 46 | val = randomBits(bits) 47 | return Conversion.IP2OS(val, length) 48 | 49 | def getRandomBits(self, length): 50 | i = randomBits(length) 51 | len = math.ceil(length / 8) 52 | return Conversion.IP2OS(i, len) 53 | 54 | 55 | class WeakRandom(SecureRandom): 56 | def __init__(self): 57 | SecureRandom.__init__(self) 58 | def getRandomBytes(self, length): 59 | return self.myrandom(length, False) 60 | def addSeed(self, seed): 61 | raise NotImplementedError() 62 | @classmethod 63 | def myrandom(self, length, printable=False): 64 | ''' 65 | This method does **NOT** provide cryptographically secure random numbers. 66 | This should **NOT** be used for production code 67 | ''' 68 | if(printable): 69 | #Nice printable characters for testing purposes 70 | return Bytes(random.randrange(0x20, 0x7E) for i in range(length)) 71 | else: 72 | return Bytes(random.randrange(0, 256) for i in range(length)) 73 | 74 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/sigmaprotocol.py: -------------------------------------------------------------------------------- 1 | 2 | from charm.core.engine.protocol import Protocol 3 | from charm.core.engine.util import * 4 | from charm.toolbox.enum import Enum 5 | 6 | #party = Enum('Prover', 'Verifier') 7 | 8 | class Sigma(Protocol): 9 | def __init__(self, groupObj, common_input=None): 10 | Protocol.__init__(self, None) # think of something for handling errors 11 | self.verifier_states = { 2:self.verifier_state2, 4:self.verifier_state4, 6:self.verifier_state6 } 12 | self.prover_states = { 1:self.prover_state1, 3:self.prover_state3, 5:self.prover_state5 } 13 | self.PROVER, self.VERIFIER = 1, 2 # PROVER = 1, VERIFIER = 2 14 | 15 | self.verifier_trans = { 2:4, 4:6 } 16 | self.prover_trans = { 1:3, 3:5 } 17 | # describe the parties involved and the valid transitions 18 | Protocol.addPartyType(self, self.VERIFIER, self.verifier_states, self.verifier_trans) 19 | Protocol.addPartyType(self, self.PROVER, self.prover_states, self.prover_trans, True) 20 | 21 | self.group = groupObj 22 | # proof parameter generation 23 | if common_input == None: # generate common parameters to P and V 24 | db = {} 25 | else: # can be used as a sub-protocol if common_input is specified by caller 26 | db = common_input 27 | Protocol.setSubclassVars(self, self.group, db) 28 | 29 | # must be implemented by sub class... 30 | def prover_state1(self): 31 | pass 32 | 33 | def prover_state3(self, input): 34 | pass 35 | 36 | def prover_state5(self, input): 37 | pass 38 | 39 | def verifier_state2(self, input): 40 | pass 41 | 42 | def verifier_state4(self, input): 43 | pass 44 | 45 | def verifier_state6(self, input): 46 | pass 47 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/specialprimes.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Generates a Blum-Williams integer, which is the product of two distinct primes 3 | each congruent to 3 mod 4 4 | ''' 5 | 6 | from charm.core.math.integer import integer,isPrime,randomPrime 7 | 8 | class BlumWilliamsInteger: 9 | def __init__(self): 10 | pass 11 | 12 | def generatePrimes(self, n): 13 | while True: 14 | p = randomPrime(n) 15 | if(isPrime(p) and (((p-3)%4) == 0)): 16 | break 17 | 18 | while True: 19 | q = randomPrime(n) 20 | if(isPrime(q) and (((q-3)%4) == 0) and not(q == p)): 21 | break 22 | 23 | return (p, q) 24 | 25 | def generateBlumWilliamsInteger(self, n, p=0, q=0): 26 | if((p == 0) or (q == 0)): 27 | (p,q) = self.generatePrimes(n) 28 | N = p * q 29 | return (p, q, N) 30 | else: 31 | N = p * q 32 | return N 33 | -------------------------------------------------------------------------------- /Charm/charm/toolbox/zknode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import string 4 | 5 | class BinNode: 6 | def __init__(self, value, left=None, right=None): 7 | #types of node 8 | self.OR = 1 9 | self.AND = 2 10 | self.EXP = 3 # '^' or exponent 11 | self.EQ = 4 # == 12 | self.ATTR = 0 13 | 14 | #OF = '' # anything above 1 and 2 15 | if(isinstance(value, str)): 16 | self.type = self.ATTR 17 | self.attribute = string.upper(value) 18 | 19 | elif(isinstance(value, int)): 20 | if value > 0 and value <= self.EQ: 21 | self.type = value 22 | self.attribute = '' 23 | 24 | self.left = left 25 | self.right = right 26 | 27 | def __str__(self): 28 | if(self.type == self.ATTR): 29 | return self.attribute 30 | else: 31 | left = str(self.left) 32 | right = str(self.right) 33 | 34 | if(self.type == self.OR): 35 | return ('('+ left + ') or (' + right + ')') 36 | elif(self.type == self.AND): 37 | return ('(' + left + ') and (' + right + ')') 38 | elif(self.type == self.EXP): 39 | return (left + '^' + right) 40 | elif(self.type == self.EQ): 41 | return (left + ' = ' + right) 42 | return None 43 | 44 | def getAttribute(self): 45 | if (self.type == self.ATTR): 46 | return self.attribute 47 | else: 48 | return None 49 | 50 | def getLeft(self): 51 | return self.left 52 | 53 | def getRight(self): 54 | return self.right 55 | 56 | def addSubNode(self, left, right): 57 | # set subNodes appropriately 58 | self.left = left if left != None else None 59 | self.right = right if left != None else None 60 | 61 | # only applies function on leaf nodes 62 | def traverse(self, function): 63 | # visit node then traverse left and right 64 | function(self.type, self) 65 | if(self.left == None): 66 | return None 67 | self.left.traverse(function) 68 | if(self.right == None): 69 | return None 70 | self.right.traverse(function) 71 | return None 72 | 73 | 74 | -------------------------------------------------------------------------------- /Charm/charm/zkp_compiler/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/charm/zkp_compiler/__init__.py -------------------------------------------------------------------------------- /Charm/charm/zkp_compiler/zk_demo.py: -------------------------------------------------------------------------------- 1 | from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair 2 | from charm.zkp_compiler.zkp_generator import * 3 | from socket import * 4 | import sys 5 | def main(argv): 6 | HOST, PORT = "", 8090 7 | party_info = {} 8 | if argv[1] == '-p': 9 | print("Operating as prover...") 10 | prover_sock = socket(AF_INET, SOCK_STREAM) 11 | prover_sock.connect((HOST, PORT)) 12 | prover_sock.settimeout(15) 13 | user = 'prover' 14 | party_info['socket'] = prover_sock 15 | elif argv[1] == '-v': 16 | print("Operating as verifier...") 17 | svr = socket(AF_INET, SOCK_STREAM) 18 | svr.bind((HOST, PORT)) 19 | svr.listen(1) 20 | verifier_sock, addr = svr.accept() 21 | print("Connected by ", addr) 22 | user = 'verifier' 23 | party_info['socket'] = verifier_sock 24 | else: 25 | print("ERROR!") 26 | exit(-1) 27 | 28 | group = PairingGroup('a.param') 29 | party_info['party'] = user 30 | party_info['setting'] = group 31 | # statement: '(h = g^x) and (j = g^y)' 32 | 33 | if(user == 'prover'): 34 | g = group.random(G1) 35 | x,y = group.random(ZR), group.random(ZR) 36 | pk = {'h':g ** x, 'g':g, 'j':g**y} 37 | sk = {'x':x, 'y':y} 38 | # pk = {'h':g**x, 'g':g} 39 | # sk = {'x':x, 'y':y} 40 | result = executeIntZKProof(pk, sk, '(h = g^x) and (j = g^y)', party_info) 41 | print("Results for PROVER =>", result) 42 | 43 | elif(user == 'verifier'): 44 | # verifier shouldn't have this information 45 | # pk = {'h':1, 'g':1, 'j':1} 46 | # sk = {'x':1, 'y':1} 47 | pk = {'h':1, 'g':1, 'j':1} 48 | sk = {'x':1} 49 | result = executeIntZKProof(pk, sk, '(h = g^x) and (j = g^y)', party_info) 50 | print("Results for VERIFIER =>", result) 51 | if __name__ == "__main__": 52 | main(sys.argv) 53 | -------------------------------------------------------------------------------- /Charm/config.mk: -------------------------------------------------------------------------------- 1 | # Automatically generated by configure - do not modify 2 | # Configured with: './configure.sh' 3 | all: 4 | prefix=/usr/local 5 | bindir=${prefix}/bin 6 | libdir=${prefix}/lib 7 | mandir=${prefix}/share/man 8 | datadir=${prefix}/share/charm 9 | sysconfdir=${prefix}/etc 10 | docdir=${prefix}/share/doc/charm 11 | confdir=${prefix}/etc/charm 12 | ARCH=x86_64 13 | VERSION=0.42 14 | PKGVERSION= 15 | SRC_PATH=/Users/Milo/Documents/Classes/Thesis/Charm 16 | TARGET_DIRS= 17 | CONFIG_UNAME_RELEASE="" 18 | TOOLS= 19 | MAKE=make 20 | INSTALL=install 21 | INSTALL_DIR=install -d -m0755 -p 22 | INSTALL_DATA=install -m0644 -p 23 | INSTALL_PROG=install -m0755 -p 24 | CC=gcc 25 | CPP=gcc -E 26 | HOST_CC=gcc 27 | AR=ar 28 | LD=ld 29 | LIBTOOL= 30 | CFLAGS=-O2 -g 31 | CHARM_CFLAGS=-m64 -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fstack-protector-all -Wendif-labels -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-definition -Wtype-limits 32 | CHARM_INCLUDES=-I. -I$(SRC_PATH) 33 | HELPER_CFLAGS= 34 | LDFLAGS=-m64 35 | CPPFLAGS= 36 | ARLIBS_BEGIN= 37 | ARLIBS_END= 38 | LIBS+= 39 | LIBS_TOOLS+= 40 | PYTHON=/usr/local/bin/python 41 | INT_MOD=yes 42 | ECC_MOD=yes 43 | PAIR_MOD=yes 44 | USE_PBC=yes 45 | USE_GMP=yes 46 | USE_MIRACL=no 47 | DISABLE_BENCHMARK=no 48 | wget=/usr/local/bin/wget 49 | HAVE_LIBM=yes 50 | HAVE_LIBGMP=yes 51 | HAVE_LIBPBC=yes 52 | HAVE_LIBCRYPTO=yes 53 | PYPARSING= 54 | -------------------------------------------------------------------------------- /Charm/dist/Charm_Crypto-0.42-py2.7-macosx-10.6-intel.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/Charm/dist/Charm_Crypto-0.42-py2.7-macosx-10.6-intel.egg -------------------------------------------------------------------------------- /Charm/doc/config.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | skip_list = ['pk_fre_ccv11'] 4 | charm_path = "../charm" 5 | toolbox_path = charm_path + "/toolbox" 6 | zkp_path = charm_path + "/zkp_compiler" 7 | scheme_path = "charm/schemes" 8 | abenc_path = scheme_path + "/abenc" 9 | dabenc_path = scheme_path + "/dabenc" 10 | pkenc_path = scheme_path + "/pkenc" 11 | pksig_path = scheme_path + "/pksig" 12 | ibenc_path = scheme_path + "/ibenc" 13 | hibenc_path = scheme_path + "/hibenc" 14 | commit_path = scheme_path + "/commit" 15 | grp_path = scheme_path + "/grpsig" 16 | -------------------------------------------------------------------------------- /Charm/doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. Charm-Crypto documentation master file, created by 2 | sphinx-quickstart on Wed Jul 20 14:42:25 2011. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to Charm-Crypto's documentation! 7 | ======================================== 8 | .. sectionauthor:: My Name 9 | 10 | Contents: 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | 15 | install_source 16 | cryptographers 17 | developers 18 | mobile 19 | 20 | Developer Resources 21 | 22 | .. toctree:: 23 | :maxdepth: 1 24 | 25 | schemes 26 | toolbox 27 | todo 28 | 29 | Indices and tables 30 | ================== 31 | 32 | * :ref:`genindex` 33 | * :ref:`modindex` 34 | * :ref:`search` 35 | 36 | -------------------------------------------------------------------------------- /Charm/doc/source/miracl.rst: -------------------------------------------------------------------------------- 1 | .. _charm-with-miracl: 2 | 3 | Building MIRACL for Charm 4 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 5 | 6 | The first step is to obtain the MIRACL library source from http://www.shamus.ie/. Currently, our pairing base module works with version 5.5.4 (released on 02/08/11). If you're interested in using it for academic purposes, then you are not required to purchase a license. Otherwise, you will have to purchase a MIRACL license since it is not under an open source license. With that said, we provide instructions for how to compile MIRACL and the charm pairing module. 7 | 8 | 1. Unzip the miracl.zip into ``charm/charm-src/pairingmath/miracl/`` 9 | ``unzip -j -aa -L miracl.zip`` 10 | 11 | 2. Change directories into the ``miracl`` dir and build the library using the provided compile script. 12 | ``sh compile_miracl.sh`` 13 | 14 | 3. If there are no errors during MIRACL compile, a ``miracl.a`` static library file should appear and you may run configure at the top-level source dir and enable use of MIRACL. 15 | ``./configure.sh --enable-pairing-miracl`` 16 | 17 | 4. You may build and install Charm as usual. These commands may or may not require super-user privileges depending on your environment. 18 | ``make build`` 19 | 20 | ``sudo make install`` 21 | 22 | .. note:: 23 | At the moment, our support for the MIRACL library is rather limited. Primarily, the MIRACL based pairing module only supports the MNT curve parameters shipped with version 5.5.4. We plan to improve the interface significantly in the next few releases and possibly expand to other base modules (standard elliptic curve and integer module). Thank you! 24 | -------------------------------------------------------------------------------- /Charm/doc/source/mobile.rst: -------------------------------------------------------------------------------- 1 | Charm for Android 2 | ========================= 3 | 4 | Here are the simple instructions for deploying Charm: 5 | 6 | 1. Install ``Python3ForAndroid.apk`` found in github repository on your Android device. 7 | 8 | 2. Install the ``SL4A`` package at the following link: https://android-scripting.googlecode.com/files/sl4a_r5.apk 9 | 10 | 3. Charm Advanced Setup: Download ``pkg_resources.py`` and place in the appropriate place using the ADB tool. Configure your device to enable the android debug bridge and connect to your machine via USB. Next, use ``adb`` to push the ``pkg_resources.py`` and ``charm-schemes`` to a specified location on your SD card. Execute the following command: 11 | 12 | - ``adb push pkg_resources /mnt/sdcard/com.googlecode.python3forandroid/extras/python3/lib/python3.2/site-packages`` 13 | 14 | - ``adb push schemes /mnt/sdcard/sl4a/scripts/schemes`` 15 | 16 | See more detailed blog posts on installing Charm on Android: 17 | 18 | 1. http://mhlakhani.com/blog/2012/05/charm-on-android/ 19 | 20 | 2. http://michael-rushanan.blogspot.com/2012/07/charm4a-part-0-why-bother.html 21 | 22 | -------------------------------------------------------------------------------- /Charm/doc/source/sample.rst: -------------------------------------------------------------------------------- 1 | Sample File of reStructuredText 2 | ======================================== 3 | 4 | Latex Equations 5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 | .. math:: 7 | W^{3\beta}_{\delta_1 \rho_1 \sigma_2} \approx U^{3\beta}_{\delta_1 \rho_1} 8 | 9 | Text Formatting 10 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11 | Some text, *italic text*, **bold text** 12 | 13 | * bulleted list. There needs to be a space right after the "*" 14 | * item 2 15 | 16 | .. note:: 17 | This is a note. 18 | 19 | Here's some Python code: 20 | 21 | >>> for i in range(10): 22 | ... print i 23 | 24 | -------------------------------------------------------------------------------- /Charm/doc/source/schemes.rst: -------------------------------------------------------------------------------- 1 | .. _schemes: 2 | 3 | Demonstration Schemes 4 | ----------------------------------------- 5 | 6 | .. begin_auto_scheme_list 7 | .. toctree:: 8 | :maxdepth: 1 9 | 10 | charm/schemes/chamhash_adm05 11 | charm/schemes/chamhash_rsa_hw09 12 | charm/schemes/dabe_aw11 13 | charm/schemes/encap_bchk05 14 | charm/schemes/pk_vrf 15 | charm/schemes/protocol_cns07 16 | charm/schemes/protocol_schnorr91 17 | charm/schemes/sigma1 18 | charm/schemes/sigma2 19 | charm/schemes/sigma3 20 | charm/schemes/pksig/pksig_bls04 21 | charm/schemes/pksig/pksig_boyen 22 | charm/schemes/pksig/pksig_chch 23 | charm/schemes/pksig/pksig_chp 24 | charm/schemes/pksig/pksig_cl03 25 | charm/schemes/pksig/pksig_cl04 26 | charm/schemes/pksig/pksig_cyh 27 | charm/schemes/pksig/pksig_dsa 28 | charm/schemes/pksig/pksig_ecdsa 29 | charm/schemes/pksig/pksig_hess 30 | charm/schemes/pksig/pksig_hw 31 | charm/schemes/pksig/pksig_rsa_hw09 32 | charm/schemes/pksig/pksig_schnorr91 33 | charm/schemes/pksig/pksig_waters 34 | charm/schemes/pksig/pksig_waters05 35 | charm/schemes/pksig/pksig_waters09 36 | charm/schemes/abenc/abenc_bsw07 37 | charm/schemes/abenc/abenc_lsw08 38 | charm/schemes/abenc/abenc_waters09 39 | charm/schemes/pkenc/pkenc_cs98 40 | charm/schemes/pkenc/pkenc_elgamal85 41 | charm/schemes/pkenc/pkenc_paillier99 42 | charm/schemes/pkenc/pkenc_rabin 43 | charm/schemes/pkenc/pkenc_rsa 44 | 45 | .. end_auto_scheme_list 46 | 47 | -------------------------------------------------------------------------------- /Charm/doc/source/todo.rst: -------------------------------------------------------------------------------- 1 | Master Todo List 2 | ==================================== 3 | .. todolist:: 4 | 5 | -------------------------------------------------------------------------------- /Charm/doc/source/toolbox.rst: -------------------------------------------------------------------------------- 1 | .. _toolbox: 2 | 3 | Toolbox Classes 4 | ----------------------------------------- 5 | 6 | .. begin_auto_toolbox_list 7 | .. toctree:: 8 | :maxdepth: 1 9 | 10 | toolbox/ABEnc 11 | toolbox/ABEncMultiAuth 12 | toolbox/bitstring 13 | toolbox/Commit 14 | toolbox/conversion 15 | toolbox/eccurve 16 | toolbox/ecgroup 17 | toolbox/enum 18 | toolbox/Hash 19 | toolbox/hash_module 20 | toolbox/IBEnc 21 | toolbox/integergroup 22 | toolbox/iterate 23 | toolbox/node 24 | toolbox/paddingschemes 25 | toolbox/pairingcurves 26 | toolbox/pairinggroup 27 | toolbox/PKEnc 28 | toolbox/PKSig 29 | toolbox/policytree 30 | toolbox/redundancyschemes 31 | toolbox/schemebase 32 | toolbox/secretshare 33 | toolbox/secretutil 34 | toolbox/securerandom 35 | toolbox/serialize 36 | toolbox/sigmaprotocol 37 | toolbox/specialprimes 38 | toolbox/symcrypto 39 | toolbox/zknode 40 | 41 | .. end_auto_toolbox_list 42 | -------------------------------------------------------------------------------- /Charm/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | addopts = --doctest-modules charm/ 3 | -------------------------------------------------------------------------------- /Charm/setup.cfg: -------------------------------------------------------------------------------- 1 | [build_ext] 2 | inplace = 1 3 | 4 | [egg_info] 5 | tag_build = 6 | tag_date = 0 7 | tag_svn_revision = 0 8 | 9 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn abescheme.wsgi -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | privateBook: Encrypting User Data with Attribute-Based Encryption Using Privacy Policies 2 | 3 | Boston College Computer Science Senior Thesis, 4 | presented to the department April 5, 2014 5 | 6 | The paper can be found [here](https://www.bc.edu/content/dam/files/schools/cas_sites/cs/pdf/academics/honors/14Watanabe.pdf). 7 | 8 | Abstract: 9 | 10 | As the internet and cloud services have pervaded our lives in nearly 11 | every aspect, one of the biggest issues facing the populace today is 12 | finding the best ways to protect our privacy. An important part of 13 | protection for the average user of a service is their privacy policy: 14 | essentially the only way today to let a client define how their data 15 | is used by the server. But often a client is not given a choice, and 16 | sometimes their policy is not even followed. We present here privateBook, 17 | a prototype for encrypting user data such that they first create a privacy 18 | policy, and their data is protected from even the service unless their 19 | privacy requirements are met by the service. 20 | 21 | Attribute-Based Encryption library provided by the [Charm crypto library](http://www.charm-crypto.com/Main.html). 22 | 23 | privateBook web app built in Python with the Django web framework. 24 | -------------------------------------------------------------------------------- /abescheme/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/abescheme/__init__.py -------------------------------------------------------------------------------- /abescheme/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import patterns, include, url 2 | from django.contrib import admin 3 | admin.autodiscover() 4 | 5 | urlpatterns = patterns('', 6 | url(r'^', include('privacy.urls')), 7 | url(r'^admin/', include(admin.site.urls)), 8 | ) 9 | -------------------------------------------------------------------------------- /abescheme/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for abescheme project. 3 | 4 | This module contains the WSGI application used by Django's development server 5 | and any production WSGI deployments. It should expose a module-level variable 6 | named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover 7 | this application via the ``WSGI_APPLICATION`` setting. 8 | 9 | Usually you will have the standard Django WSGI application here, but it also 10 | might make sense to replace the whole Django WSGI application with a custom one 11 | that later delegates to the Django one. For example, you could introduce WSGI 12 | middleware here, or combine a Django application with an application of another 13 | framework. 14 | 15 | """ 16 | import os 17 | 18 | # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks 19 | # if running multiple sites in the same mod_wsgi process. To fix this, use 20 | # mod_wsgi daemon mode with each site in its own daemon process, or use 21 | # os.environ["DJANGO_SETTINGS_MODULE"] = "abescheme.settings" 22 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "abescheme.settings") 23 | 24 | # This application object is used by any WSGI server configured to use this 25 | # file. This includes Django's development server, if the WSGI_APPLICATION 26 | # setting points here. 27 | from django.core.wsgi import get_wsgi_application 28 | from dj_static import Cling 29 | 30 | application = Cling(get_wsgi_application()) 31 | 32 | # Apply WSGI middleware here. 33 | # from helloworld.wsgi import HelloWorldApplication 34 | # application = HelloWorldApplication(application) 35 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "abescheme.settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /privacy.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/privacy.db -------------------------------------------------------------------------------- /privacy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/privacy/__init__.py -------------------------------------------------------------------------------- /privacy/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from privacy.models import Policy, PostedData, Authority 3 | 4 | admin.site.register(Policy) 5 | admin.site.register(PostedData) 6 | admin.site.register(Authority) -------------------------------------------------------------------------------- /privacy/form.py: -------------------------------------------------------------------------------- 1 | from django.forms import ModelForm 2 | from privacy.models import Policy 3 | 4 | class PolicyForm(ModelForm): 5 | class Meta: 6 | model = Policy -------------------------------------------------------------------------------- /privacy/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | class Policy(models.Model): 4 | name = models.CharField(max_length=100) 5 | policy = models.CharField(max_length=200) 6 | def __unicode__(self): 7 | return self.name 8 | 9 | class PostedData(models.Model): 10 | p_id = models.CharField(max_length=10) 11 | status = models.CharField(max_length=5000) 12 | posted = models.DateTimeField(auto_now_add=True) 13 | def __unicode__(self): 14 | return self.status 15 | 16 | class Authority(models.Model): 17 | app_name = models.CharField(max_length=100) 18 | attr_list = models.CharField(max_length=1000) 19 | p_key = models.CharField(max_length=3000) 20 | d_key = models.CharField(max_length=3000) 21 | def __unicode__(self): 22 | return self.app_name 23 | -------------------------------------------------------------------------------- /privacy/templates/authority.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Data Encryption Authority 6 | 7 | 39 | 40 | 41 |

Data Encryption Authority

42 |

Build your app's attribute list here

43 |

44 |

45 |
46 |

47 |
48 |
49 |
50 | 51 |
52 | 53 |
54 | 55 | -------------------------------------------------------------------------------- /privacy/templates/policy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Encrypted Data Sharing - {{ name }} 6 | 11 | 12 | 13 |

Welcome, {{ name }}! Your ID number is {{ id }}. Use this to log in next time.

14 |

You can post your status here. Remember, your data is super safe!

15 |

Back to home

16 |


17 | {% if msg %}

{{ msg }}

{% endif %} 18 |

Post a status update:

19 |
20 | {% csrf_token %} 21 | 22 | 23 |
24 |

25 | {% if statuses %} 26 | {% for status in statuses %} 27 |

{{ status.1 }}

28 |

{{ status.0 }}


29 | {% endfor %} 30 | {% endif %} 31 | 32 | -------------------------------------------------------------------------------- /privacy/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /privacy/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import patterns, include, url 2 | from privacy import views 3 | 4 | urlpatterns = patterns('', 5 | url(r'^$', views.index, name='index'), 6 | url(r'^(?P\d+)/$', views.policy, name='policy'), 7 | url(r'^authority/$', views.authority, name='authority') 8 | ) 9 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Django==1.6.1 2 | dj-database-url==0.2.2 3 | dj-static==0.0.5 4 | django-toolbelt==0.0.1 5 | gunicorn==18.0 6 | psycopg2==2.5.2 7 | pystache==0.5.3 8 | static==1.0.2 9 | wsgiref==0.1.2 10 | -------------------------------------------------------------------------------- /thesisOutline.txt: -------------------------------------------------------------------------------- 1 | 1. Developing options for protecting user privacy 2 | - Example of service where this implementation would be useful 3 | - NYT article 4 | - Jeeves PL, from Jean Yang 5 | 2. Attribute Based Encryption - how it works/how I use it 6 | - ABE paper: mathematics 7 | - ABE paper: example usage 8 | - Implementation: Policy diagram 9 | - Implementation: Authority/Policy/Data posting 10 | - Implementation: Demonstration – success & failure -------------------------------------------------------------------------------- /writeup/authority3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/writeup/authority3.png -------------------------------------------------------------------------------- /writeup/authoritydb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/writeup/authoritydb.png -------------------------------------------------------------------------------- /writeup/finalwriteup.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \citation{lawler} 3 | \citation{bajaj} 4 | \citation{yang} 5 | \@writefile{toc}{\contentsline {section}{\numberline {1}Introduction}{1}} 6 | \@writefile{toc}{\contentsline {section}{\numberline {2}Data Encryption}{2}} 7 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.1}Public-Key Cryptography}{2}} 8 | \citation{charm} 9 | \citation{abe} 10 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.2}Attribute-Based Encryption}{3}} 11 | \@writefile{toc}{\contentsline {paragraph}{Setup}{3}} 12 | \@writefile{toc}{\contentsline {paragraph}{Encryption}{3}} 13 | \@writefile{toc}{\contentsline {paragraph}{Key Generation}{3}} 14 | \@writefile{toc}{\contentsline {paragraph}{Decryption}{3}} 15 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.3}Example Usage}{3}} 16 | \@writefile{toc}{\contentsline {section}{\numberline {3}ABE Privacy Prototype}{4}} 17 | \@writefile{toc}{\contentsline {subsection}{\numberline {3.1}Parties Involved}{5}} 18 | \@writefile{toc}{\contentsline {subsection}{\numberline {3.2}The Full Process}{5}} 19 | \@writefile{toc}{\contentsline {paragraph}{1. Server Registration}{6}} 20 | \@writefile{toc}{\contentsline {paragraph}{2. Key Distribution}{6}} 21 | \@writefile{toc}{\contentsline {paragraph}{3. Client Encryption}{6}} 22 | \@writefile{toc}{\contentsline {paragraph}{4. Server Response}{6}} 23 | \@writefile{toc}{\contentsline {section}{\numberline {4}privateBook}{6}} 24 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.1}privateBook Server Registration}{7}} 25 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.2}Authority Key Storage and Distribution}{8}} 26 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.3}Client Privacy Policy Creation}{9}} 27 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.4}Client Encryption and privateBook Response}{10}} 28 | \@writefile{toc}{\contentsline {section}{\numberline {5}Issues with the Prototype}{11}} 29 | \@writefile{toc}{\contentsline {section}{\numberline {6}Conclusion}{11}} 30 | \bibcite{lawler}{1} 31 | \bibcite{bajaj}{2} 32 | \bibcite{yang}{3} 33 | \bibcite{charm}{4} 34 | \bibcite{abe}{5} 35 | -------------------------------------------------------------------------------- /writeup/finalwriteup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/writeup/finalwriteup.pdf -------------------------------------------------------------------------------- /writeup/finalwriteup.synctex.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/writeup/finalwriteup.synctex.gz -------------------------------------------------------------------------------- /writeup/policy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/writeup/policy.png -------------------------------------------------------------------------------- /writeup/policy2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/writeup/policy2.png -------------------------------------------------------------------------------- /writeup/policycreation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/writeup/policycreation.png -------------------------------------------------------------------------------- /writeup/policydiagram.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/writeup/policydiagram.pdf -------------------------------------------------------------------------------- /writeup/posteddata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmilo/abescheme/7989a111bd84fdd77b054c2cff4fb7f8d1bfd80d/writeup/posteddata.png --------------------------------------------------------------------------------