pycocks
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:
-
PKG —
CocksPKG: implements the public key generator (PKG) for the scheme's initialisation and extracting secret keys from identity strings. -
Client —
Cocks: used for encrypting and decrypting messages using the secret key and public modulus generated byCocksPKG.
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
- C. Cocks, "An identity based encryption scheme based on quadratic residues", Proceedings of the IMA International Conference on Cryptography and Coding. Springer, 2001.
- D. Boneh and M. Franklin, "Identity-based encryption from the Weil pairing", Annual International Cryptology Conference. Springer, 2001.
Metadata
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)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pycocks-1.1.tar.gz | 8.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|
Security for pycocks 1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.