-
Notifications
You must be signed in to change notification settings - Fork 4
Documentation
This is the documentation of the encryption part of xtea in python.
|1. Functions | |2. The XTEACipher object| |3. The CBCMAC object | |4. Helper functions | |5. Constants |
New in 0.3.0: Added CFB-mode
New in 0.4.0: Added CBC-MAC
New in 0.4.0: Added bugless and PEP-like CTR
function new(key, **kwargs):
Constructor for an "XTEACipher" object
-
key - a string, must have a length of 8 (128-bits)
-
Optional parameters:
-
MODE - int or long, must be one of the following (default 1):
- 1 (ECB)
- 2 (CBC)
- 3 (CFB)
- 5 (OFB)
- 6 (CTR) - Buggy (you may loose data)
Number 4 is the OpenPGP format, it is not used (see more at PEP 272). If 4 is given to the function, a NotImplementedError will be raised.
-
IV - string, must have a length of one block (8), needed with CBC and CFB, optional with OFB, if not given in CBC/CFB, raises a value error
-
counter - callable function/object, the counter function for CTR, must return a number (int or long) or a string (0.4.0+)
-
endian - one of the strings "@", "=", "<", ">" or "!", look in the [struct documentation] (https://docs.python.org/2/library/struct.html#byte-order-size-and-alignment) for details,
(default is "!", it´s the same as ">" (network/big endian)).
- rounds - int or long, rounds for the cipher; more rounds = more security = more slowness; 2 rounds = 1 cycle
class XTEACipher(object):
The cipher object
- block_size = 8
function init(self, key, **kwargs):
Alternative constructor, same as new
function encrypt(self, data):
Encrpyts data. Modes with initialisation vector will reset, if you recall the function!
- text - string, the text to encrypt. It must have a fixed size (e.g. a multiple of 8 in length)
function decrypt(self, data):
Decrypts data. Modes with initialisation vector will reset, if you recall the function!
- text - string, the text to decrypt. It must have a fixed size (e.g. a multiple of 8 in length)
class CBCMAC(object):
A CBCMAC object (cipher-block-chaining massage-authentication-code), based on xtea
- digest_size = 8
- block_size = 64
- name = "xtea-cbcmac"
function init(self, key, string="", endian="!"):
Constructor of a CBCMAC object, same as CBCMAC.new
staticmethod new(key, string="", endian="!"):
PEP 452 like constructor (fake module),
- key - string, should be 8 bit in length
- string - string, the content to authenticate (default "")
- endian - normally one of the strings "@", "=", "<", ">" or "!", struct documentation for details,
(default is "!", it´s the same as ">" (network/big endian)).
function update(self, string):
Add string to the content wich will be authenticated
- string - string, additional content
function copy(self):
Return a copy (“clone”) of the hash object. This can be used to efficiently compute the digests of data sharing a common initial substring.
function digest(self):
Return the digest of the data passed to the update() method so far. This is a bytes object of size digest_size which may contain bytes in the whole range from 0 to 255.
function hexdigest(self):
Like digest() except the digest is returned as a string object of double length, containing only hexadecimal digits. This may be used to exchange the value safely in email or other non-binary
environments.
function xor_strings(s, t):
Xor to strings together.
- s, t - strings with same length
function stringToLong(s):
Convert a string(with more then an char) into a long.
- s - strings
function longToString(n):
Convert a long into a string.
- n - int or long, not every number works
function _test():
xtea-module self-test. The function prints fails and time (250 runs).
New in 0.3.0: Added PGP-constant
New in 0.4.0: Added CCM-constant
MODE_ECB = 1
MODE_CBC = 2
MODE_CFB = 3
MODE_PGP = 4
MODE_OFB = 5
MODE_CTR = 6
MODE_CCM = 8 # Unofficial
block_size = 64
key_size = 128