A pre-quantum cryptographic set of utilities written in Python.
This library exposes a set of cryptographic primitives and algorithms implementations that helps with the setup of cryptographic protocols.
The library exposes a CLI and methods that can be imported in other projects.
In order to run this library you need python3 installed on your machine.
The library is implemented using version 3.11.2
.
-
Create your Python environment;
-
Install the required dependencies with the command:
pip install -r requirements.txt
-
Invoke a method with the following command:
python3 -m crypto <method_name> --param1 <value>
NOTE: on your system the python3
binary name could be different.
The following primitives are available:
primitive | parameters | description | output |
---|---|---|---|
sha3_224 | input : string |
returns a SHA-3 hash of 224 bits length | { "hash": <hexadecimal_string> } |
sha3_256 | input : string |
returns a SHA-3 hash of 256 bits length | { "hash": <hexadecimal_string> } |
sha3_512 | input : string |
returns a SHA-3 hash of 512 bits length | { "hash": <hexadecimal_string> } |
All the functions return the data as JSON.
primitive | parameters | description | output |
---|---|---|---|
generate_key | key_length : number |
returns an hexadecimal string key of 128, 192, 256 bits length, based on the parameter passed |
{ "key": <hexadecimal_string> } |
AESGCM_encrypt | key : a 365-bit length key secret : the secret to encrypt unencrypted_data : optional, unencrypted data to associate to the chiper |
returns the chiper with the associated data (if any) and the nonce used for the encryption | { "chiper": <hexadecimal_string>, "nonce": <hexadecimal_string> } |
AESGCM_decrypt | key : the same key used for the encryption nonce : the nonce returned from the encryption operation chiper : the secret to decrypt unencrypted_data : optional, unencrypted data to associate to the chiper |
returns the decrypted secret as string | { "message": <string> } |
All the functions return the data as JSON.
The following digital signatures utilities implements the Elliptic Curve Signature Algorithm Ed25519:
primitive | parameters | description | output |
---|---|---|---|
generates_key_pair | none | generates a private and public keys pair | { "privateKey": <hexadecimal_string>, "publicKey": <hexadecimal_string> } |
sign | private_key : hexadecimal string message : string |
signs a message with the private key and produce the signature for the message | { "signature": <hexadecimal_string> } |
verify | public_key : hexadecimal_string signature : hexadecimal_string message : hexadecimal_string |
verifies a signature on a particular message | { "result": <"success"|"failure"> } |
All the functions return the data as JSON.
In order to use the homomorphic functions, for the first run the function for the keys generation, specifying an algorithm schema. The following schemas are supported:
"rsa",
"el_gamal",
"exponential_el_gamal",
"paillier",
"damgard_jurik",
"okamoto_uchiyama",
"benaloh",
"naccache_stern",
"goldwasser_micali",
"elliptic_curve_el_gamal"
if no schema is passed, the default schema applied is paillier
. Not all the schemas supports all the operations, please refer to this documentation for
further details.
primitive | parameters | description | output |
---|---|---|---|
he_generate_keys | algorithm : string key_file : string |
generates a file of public/private keys | { "result": <string> } |
he_encrypt | m : number algorithm : string |
encrypt a numeric value key_file : string |
`{ "result": <int |
he_sum | m : int|list|tuple n : int|list|tuple algorithm : string key_file : string |
returns the sum of the encrypted values | { "result": <int|list|tuple> } |
he_decrypt | c : int|list|tuple algorithm : string key_file : string |
returns the value decrypted | { "result": <number> } |
All the functions return the data as JSON.
To run the complete unit test suite run the command:
pytest
This software is released under the terms of the GNU General Public License 3.0