Charm-Crypto

A framework for rapidly prototyping advanced cryptographic schemes

PyPI version Python versions License

Charm is a Python framework for rapidly prototyping cryptographic schemes and protocols. It was designed from the ground up to minimize development time and code complexity while promoting the reuse of components.

Key Features:

  • Pairing-based cryptography — BN254, BLS12-381, MNT curves via PBC library

  • Elliptic curve groups — NIST curves, secp256k1, Curve25519 via OpenSSL

  • Integer groups — RSA, DSA, safe primes for classical schemes

  • 50+ implemented schemes — ABE, IBE, signatures, commitments, and more

  • ZKP compiler — Schnorr proofs, Σ-protocols, AND/OR compositions

  • Serialization — Convert group elements to bytes for storage/transmission

Quick Start

Install from PyPI:

pip install charm-crypto

BLS Signatures (used in Ethereum 2.0):

from charm.toolbox.pairinggroup import PairingGroup, G1
from charm.schemes.pksig.pksig_bls04 import BLS01

group = PairingGroup('BN254')
bls = BLS01(group)

# Generate keys
(public_key, secret_key) = bls.keygen()

# Sign and verify
message = "Hello, Charm!"
signature = bls.sign(secret_key['x'], message)
assert bls.verify(public_key, signature, message)

Attribute-Based Encryption:

from charm.toolbox.pairinggroup import PairingGroup, GT
from charm.schemes.abenc.abenc_bsw07 import CPabe_BSW07

group = PairingGroup('SS512')
cpabe = CPabe_BSW07(group)

# Setup and key generation
(master_public, master_secret) = cpabe.setup()
user_key = cpabe.keygen(master_public, master_secret,
                       ['ADMIN', 'DEPARTMENT-A'])

# Encrypt with policy, decrypt with attributes
message = group.random(GT)
policy = '(ADMIN or MANAGER) and DEPARTMENT-A'
ciphertext = cpabe.encrypt(master_public, message, policy)
decrypted = cpabe.decrypt(master_public, user_key, ciphertext)

Getting Started

User Guide

Schemes & API Reference

Testing

Release Notes

Indices and Tables