Skip to main content

A Python implementation of Cocks' identity-based encryption (IBE) scheme.

Project description

pycocks

PyPI PyPI - Python Version PyPI - Downloads PyPI - License pycocks Python build badge

A Python implementation of Cocks' identity-based encryption (IBE) scheme [1]. IBE allows strings to be used directly as public encryption keys.

Cocks' scheme uses the quadratic residuosity hardness problem, rather than bilinear pairings with other IBE schemes, e.g. Boneh-Franklin [2]. As a result, no additional dependencies are required for pairing-based cryptography; only gmpy2 is sufficient.

Usage

Two classes are utilised for server- (PKG) and client-side communication:

  1. PKGCocksPKG: implements the public key generator (PKG) for the scheme's initialisation and extracting secret keys from identity strings.

  2. ClientCocks: used for encrypting and decrypting messages using the secret key and public modulus generated by CocksPKG.

PKG

from pycocks.cocks import CocksPKG

# Instantiate the PKG
#
# Optional parameters: bit size (default = 2048) and hash function (default = SHA512)
cocks_pkg = CocksPKG()   

# Extract private key, r, from an identity string. This is
# "User1" in this instance.
#
# A transformed ID string, a, is also returned that is
# required for encryption and decryption by the client.
r, a = cocks_pkg.extract("User1")

Client

from pycocks.cocks import Cocks

# Instantiate the client
#
# Must use the same modulus, n, as the PKG
cocks = Cocks(cocks_pkg.n)  

# Encryption example
#
# Transformed identity string, a, is provided by the server PKG
c = cocks.encrypt(b"test", a)

# Decryption example
#
# Private key, r, is generated by the server PKG
msg = cocks.decrypt(c, r, a)  # => b"test"

Tests

Use pytest to execute tests in tests/test_pycocks.py

Requirements

  • gmpy2 (tested v2.0.8)

Citation

Please use the following if you use pycocks in a publication:

@software{shepherd:pycocks,
      title={pycocks},
      version={1.0},
      author={Carlton Shepherd},
      year={2022},
      url={https://github.com/cgshep/pycocks}
}

References

  1. C. Cocks, "An identity based encryption scheme based on quadratic residues", Proceedings of the IMA International Conference on Cryptography and Coding. Springer, 2001.
  2. D. Boneh and M. Franklin, "Identity-based encryption from the Weil pairing", Annual International Cryptology Conference. Springer, 2001.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycocks-1.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

pycocks-1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file pycocks-1.1.tar.gz.

File metadata

  • Download URL: pycocks-1.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for pycocks-1.1.tar.gz
Algorithm Hash digest
SHA256 92ac1991d3b1d6e48a1418e916c6b127a76d8dabcc34d7f4aaa727d1543dc19f
MD5 cdafba6068237c602edc22edf988b24b
BLAKE2b-256 b55eb05b85294abb5fdc2b82b132f6940a6e2edd3a6329401b500d910da75f5c

See more details on using hashes here.

File details

Details for the file pycocks-1.1-py3-none-any.whl.

File metadata

  • Download URL: pycocks-1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for pycocks-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d1815f95945cebe76396b958f14f47a78c08b39fa53b2c743977dff5bdb0f1f
MD5 a22d423fe9ee5b59072641ace1cb97b8
BLAKE2b-256 40029eee729c0cba5eb8b09fb397a8fcef3e8d92cc2f0ffd4a5c7fddc334537c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page