A Python implementation of Cocks' identity-based encryption (IBE) scheme.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pycocks-1.0.tar.gz
.
File metadata
- Download URL: pycocks-1.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 264806802b58d8dc39f63143d974d7a3b83fe6a443e137ab5375d7cc2a44f5f3 |
|
MD5 | ede525295b4089f1b3cb3da8bdfb059d |
|
BLAKE2b-256 | 13d950a4aebb84eeff735f264620e7b29c5fa5437a4db4566580ffe8c30808b0 |
File details
Details for the file pycocks-1.0-py3-none-any.whl
.
File metadata
- Download URL: pycocks-1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4576934cf837c0079d1dbbf5feb0283ff86ad996e1f7e478b1867d3ff07c8915 |
|
MD5 | 6def155d49946d992ba80f3b8af002d8 |
|
BLAKE2b-256 | 7400ff01f1c946160592d29a4ad01159fac2a5b204e77d397e0f0b16e2ed62d5 |