Skip to main content

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. PKG — CocksPKG: implements the public key generator (PKG) for the scheme's initialisation and extracting secret keys from identity strings.

  2. Client — Cocks: 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.

Release files for pycocks 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycocks 1.1
File Size Uploaded
pycocks-1.1.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycocks 1.1
File Interpreter ABI Platform
pycocks-1.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / pycocks-1.1.tar.gz

Download URL pycocks-1.1.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
92ac1991d3b1d6e48a1418e916c6b127a76d8dabcc34d7f4aaa727d1543dc19f
BLAKE2b-256 checksum
How to use checksums
b55eb05b85294abb5fdc2b82b132f6940a6e2edd3a6329401b500d910da75f5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release files / pycocks-1.1-py3-none-any.whl

Download URL pycocks-1.1-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d1815f95945cebe76396b958f14f47a78c08b39fa53b2c743977dff5bdb0f1f
BLAKE2b-256 checksum
How to use checksums
40029eee729c0cba5eb8b09fb397a8fcef3e8d92cc2f0ffd4a5c7fddc334537c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

1.1 This release

2 release files

1.0.1

2 release files

1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page