Fast module for PyChickenTicket crypto work
Project description
CT_Crypto - PyChickenTicket crypto module
Docs
encrypt(data, password)
Encrypt data (assuming nonce and salt are packed in) with given password, and return decrypted data.
If data is decrypted with non-default length parameters, the encryption must have been done with the same parameters.
Parameters
-----------
data: bytes
The binary data to encrypt.
password: str
The password to encrypt the data with.
Returns
--------
bytes
Bytes object containing the decrypted data.
Raises
-------
TypeError
If argument datatypes are incorrect
ValueError
If argument length is incorrect
RuntimeError
If data decryption authentication fails
MemoryError
If key derivation or decryption fails
decrypt(data, password)
Decrypt data (assuming nonce and salt are packed in) with given password, and return decrypted data.
If data is decrypted with non-default length parameters, the encryption must have been done with the same parameters.
Parameters
-----------
data: bytes
The binary data to encrypt.
password: str
The password to encrypt the data with.
Returns
--------
bytes
Bytes object containing the decrypted data.
Raises
-------
TypeError
If argument datatypes are incorrect
ValueError
If argument length is incorrect
RuntimeError
If data decryption authentication fails
MemoryError
If key derivation or decryption fails
get_def(def_index)
Takes an index and returns the value of the libsodium constant associated with that index.
Index -> Constant table below
0 -> crypto_box_SEEDBYTES
1 -> crypto_pwhash_SALTBYTES
2 -> crypto_pwhash_PASSWD_MIN
3 -> crypto_pwhash_PASSWD_MAX
4 -> crypto_pwhash_BYTES_MIN
5 -> crypto_pwhash_BYTES_MAX
6 -> crypto_pwhash_OPSLIMIT_MIN
7 -> crypto_pwhash_OPSLIMIT_MAX
8 -> crypto_pwhash_MEMLIMIT_MIN
9 -> crypto_pwhash_MEMLIMIT_MAX
10 -> crypto_secretbox_KEYBYTES
11 -> crypto_secretbox_MACBYTES
12 -> crypto_secretbox_NONCEBYTES
13 -> crypto_secretbox_MESSAGEBYTES_MAX
Parameters
-----------
def_index: int
Index of the constant you want to fetch.
Returns
--------
int
Value of the specified constant
Raises
-------
KeyError
If the index has no associated constant
genkey(key_size)
Generates a secure secret key that is key_size
bytes long.
Parameters
-----------
key_size: int
Determines the length of the generated key
Returns
--------
bytes
The generated key
Raises
-------
ValueError
If key size is below 32
random_bytes(buffer_size)
Generates cryptographically-secure random bytes, up to buffer_size
.
Returns None
if buffer_size
is 0.
Parameters
-----------
buffer_size: int
Determines the size of the buffer used to hold the random bytes.
Returns
--------
bytes
Buffer of random bytes
hexdigest(data)
Returns the hexdigest for the given value.
Returns None
if data
is empty.
Parameters
-----------
data: bytes
Bytes object to calculate the hexdigest for.
Returns
--------
str
The hexdigest in string format.
Raises
-------
MemoryError
If memory could not be allocated for the hex buffer
derive_key(password, salt, key_size)
Derives a secret key from a password and hash using the Argon2id algorithm.
Generated key is key_size
bytes long.
Returns None
if any argument is empty.
Parameters
-----------
password: str
Password to use for key derivation.
salt: bytes
Bytes object storing the salt to use for key derivation.
key_size: int
Determines size of the generated key.
Returns
--------
bytes
The secret key.
Raises
-------
MemoryError
If memory could not be allocated for derivation.
encrypt_secret(data, key, nonce)
Encrypts data
with key
and nonce
, using the
XSalsa20 stream cipher for encryption and Poly1305
MAC for authentication.
Returns None
if any argument is empty.
Parameters
-----------
data: bytes
The data to encrypt.
key: bytes
The secret key to use for encryption.
nonce: bytes
The nonce to use for encryption.
Returns
--------
bytes
The encrypted data, signed with the MAC tag.
Raises
-------
MemoryError
If memory could not be allocated for encryption
RuntimeError
If encryption fails
decrypt_secret(data, key, nonce)
Decrypts data
with key
and nonce
, using the
XSalsa20 stream cipher for encryption and Poly1305
MAC for authentication.
Returns None
if any argument is empty.
Parameters
-----------
data: bytes
The data to decrypt.
key: bytes
The secret key to use for decryption.
nonce: bytes
The nonce to use for decryption.
Returns
--------
bytes
The decrypted data.
Raises
-------
MemoryError
If memory could not be allocated for decryption
RuntimeError
If decryption authentication fails
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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size ct_crypto-0.0.62.tar.gz (7.4 kB) | File type Source | Python version None | Upload date | Hashes View |