API¶
Warning
The documentations assumes you know the risks of using cryptography. This library is low level with all benefits and dangers.
Here be dragons!
The new constructor¶
-
camellia.
new
(key, mode, IV=None, **kwargs)¶ Create an “CamelliaCipher” object.
Parameters: - key (bytes) – The key for encrytion/decryption. Must be 16/24/32 in length.
- mode (int, one of MODE_* constants) – Mode of operation.
- IV (bytes) – Initialization vector for CBC/CFB/OFB blockcipher modes of operation, must be 16 bytes in length.
- counter (callable) – Counter for CTR blockcipher mode of operation. Each call must return 16 bytes.
Returns: CamelliaCipher
Raises: ValueError, NotImplementedError
Modes of operation¶
-
camellia.
MODE_ECB
= 1¶ ECB mode of operation
-
camellia.
MODE_CBC
= 2¶ CBC mode of operation
-
camellia.
MODE_CFB
= 3¶ CFB mode of operation
-
camellia.
MODE_OFB
= 5¶ OFB mode of operation
-
camellia.
MODE_CTR
= 6¶ CTR mode of operation
The CamelliaCipher class¶
-
class
camellia.
CamelliaCipher
(key, mode, **kwargs)¶ The CamelliaCipher object.
-
encrypt
(string)¶ Encrypt data with the key and the parameters set at initialization.
The cipher object is stateful; encryption of a long block of data can be broken up in two or more calls to encrypt(). That is, the statement:
>>> c.encrypt(a) + c.encrypt(b)
is always equivalent to:
>>> c.encrypt(a+b)
That also means that you cannot reuse an object for encrypting or decrypting other data with the same key.
This function does not perform any padding.
- For MODE_ECB, MODE_CBC string length (in bytes) must be a multiple of block_size.
- For MODE_CFB, string length (in bytes) must be a multiple of segment_size/8.
- For MODE_CTR and MODE_OFB, string can be of any length.
Parameters: string (bytes) – The piece of data to encrypt.
Raises: - ValueError – When a mode of operation has be requested this code cannot handle.
- ValueError – When len(string) has a wrong length, as described above.
- TypeError – When the counter callable in CTR returns data with the wrong length.
Returns: The encrypted data, as a byte string. It is as long as string.
Return type:
-
decrypt
(string)¶ Decrypt data with the key and the parameters set at initialization.
The cipher object is stateful; decryption of a long block of data can be broken up in two or more calls to decrypt(). That is, the statement:
>>> c.decrypt(a) + c.decrypt(b)
is always equivalent to:
>>> c.decrypt(a+b)
That also means that you cannot reuse an object for encrypting or decrypting other data with the same key.
This function does not perform any padding.
- For MODE_ECB, MODE_CBC string length (in bytes) must be a multiple of block_size.
- For MODE_CFB, string length (in bytes) must be a multiple of segment_size/8.
- For MODE_CTR and MODE_OFB, string can be of any length.
Parameters: string (bytes) – The piece of data to decrypt.
Raises: - ValueError – When a mode of operation has be requested this code cannot handle.
- ValueError – When len(string) has a wrong length, as described above.
- TypeError – When the counter in CTR returns data of the wrong length.
Returns: The decrypted data, as a byte string. It is as long as string.
Return type:
-
block_size
= 16¶ block size of the camellia cipher
-
decrypt
(string) Decrypt data with the key and the parameters set at initialization.
The cipher object is stateful; decryption of a long block of data can be broken up in two or more calls to decrypt(). That is, the statement:
>>> c.decrypt(a) + c.decrypt(b)
is always equivalent to:
>>> c.decrypt(a+b)
That also means that you cannot reuse an object for encrypting or decrypting other data with the same key.
This function does not perform any padding.
- For MODE_ECB, MODE_CBC string length (in bytes) must be a multiple of block_size.
- For MODE_CFB, string length (in bytes) must be a multiple of segment_size/8.
- For MODE_CTR and MODE_OFB, string can be of any length.
Parameters: string (bytes) – The piece of data to decrypt.
Raises: - ValueError – When a mode of operation has be requested this code cannot handle.
- ValueError – When len(string) has a wrong length, as described above.
- TypeError – When the counter in CTR returns data of the wrong length.
Returns: The decrypted data, as a byte string. It is as long as string.
Return type:
-
decrypt_block
(key, block, **kwargs)¶ Decrypt a single block with camellia.
-
encrypt
(string) Encrypt data with the key and the parameters set at initialization.
The cipher object is stateful; encryption of a long block of data can be broken up in two or more calls to encrypt(). That is, the statement:
>>> c.encrypt(a) + c.encrypt(b)
is always equivalent to:
>>> c.encrypt(a+b)
That also means that you cannot reuse an object for encrypting or decrypting other data with the same key.
This function does not perform any padding.
- For MODE_ECB, MODE_CBC string length (in bytes) must be a multiple of block_size.
- For MODE_CFB, string length (in bytes) must be a multiple of segment_size/8.
- For MODE_CTR and MODE_OFB, string can be of any length.
Parameters: string (bytes) – The piece of data to encrypt.
Raises: - ValueError – When a mode of operation has be requested this code cannot handle.
- ValueError – When len(string) has a wrong length, as described above.
- TypeError – When the counter callable in CTR returns data with the wrong length.
Returns: The encrypted data, as a byte string. It is as long as string.
Return type:
-
encrypt_block
(key, block, **kwargs)¶ Encrypt a single block with camellia.
-
Low-level camellia functions¶
-
camellia.
Camellia_Ekeygen
(rawKey)¶ Make a keytable from a key.
Parameters: rawKey (bytes) – raw encryption key, 128, 192 or 256 bits long Returns: keytable
-
camellia.
Camellia_Encrypt
(keyLength, keytable, plainText)¶ Encrypt a plaintext block by given arguments.
Parameters: Returns: ciphertext block
-
camellia.
Camellia_Decrypt
(keyLength, keytable, cipherText)¶ Decrypt a plaintext block by given arguments.
Parameters: Returns: plaintext block