Home | Trees | Indices | Help |
|
---|
|
Triple DES symmetric cipher
Triple DES (or TDES or TDEA or 3DES) is a symmetric block cipher standardized by NIST. It has a fixed data block size of 8 bytes.
TDES consists of the concatenation of 3 simple Single DES ciphers (encryption - decryption - encryption), where each stage uses an indipendent sub-key.
A TDES key is therefore 24 (8+8+8) bytes long. However, like Single DES, only 7 out of 8 bits are actually used: the remaining ones are parity bits (which practically all TDES implementations ignore). Theoreticaly, Triple DES achieves up to 112 bits of effective security.
Triple DES can also operate with a 16 bytes key (Option 2, also termed 2TDES), in which case subkey K1 equals subkey K2. The effective security is as low as 90 bits.
Thi implementation checks and enforces the condition K1 != K2 != K3 (Option 3), as it degrades Triple DES to Single DES.
Use AES, not TDES. This module is provided for legacy purposes only.*
As an example, encryption can be done as follows:
>>> from Cryptodome.Cipher import DES3 >>> from Cryptodome.Random import get_random_bytes >>> >>> # When generating a Triple DES key you must check that >>> # subkey1 != subkey2 and subkey2 != subkey3 >>> while True: >>> try: >>> key = DES3.adjust_key_parity(get_random_bytes(24)) >>> break >>> except ValueError >>> pass >>> >>> cipher = DES3.new(key, DES3.MODE_CFB) >>> plaintext = b'We are no longer the knights who say ni!' >>> msg = cipher.nonce + cipher.encrypt(plaintext)
Functions | |||
|
|||
|
Variables | |
MODE_ECB = 1 Electronic Code Book (ECB). See Cryptodome.Cipher._mode_ecb.EcbMode. |
|
MODE_CBC = 2 Cipher-Block Chaining (CBC). See Cryptodome.Cipher._mode_cbc.CbcMode. |
|
MODE_CFB = 3 Cipher FeedBack (CFB). See Cryptodome.Cipher._mode_cfb.CfbMode. |
|
MODE_OFB = 5 Output FeedBack (OFB). See Cryptodome.Cipher._mode_ofb.OfbMode. |
|
MODE_CTR = 6 CounTer Mode (CTR). See Cryptodome.Cipher._mode_ctr.CtrMode. |
|
MODE_OPENPGP = 7 OpenPGP Mode. See Cryptodome.Cipher._mode_openpgp.OpenPgpMode. |
|
MODE_EAX = 9 EAX Mode. See Cryptodome.Cipher._mode_eax.EaxMode. |
|
block_size = 8 Size of a data block (in bytes) |
|
key_size =
Size of a key (in bytes) |
Function Details |
Create a new TDES cipher
Attention: it is important that all 8 byte subkeys are different, otherwise TDES would degrade to single DES. |
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Thu Feb 16 14:05:21 2017 | http://epydoc.sourceforge.net |