Home | Trees | Indices | Help |
|
---|
|
AES symmetric cipher
AES (Advanced Encryption Standard) is a symmetric block cipher standardized by NIST . It has a fixed data block size of 16 bytes. Its keys can be 128, 192, or 256 bits long.
AES is very fast and secure, and it is the de facto standard for symmetric encryption.
As an example, encryption can be done as follows:
>>> from Cryptodome.Cipher import AES >>> >>> key = b'Sixteen byte key' >>> cipher = AES.new(key, AES.MODE_CFB) >>> msg = cipher.iv + cipher.encrypt(b'Attack at dawn')
A more complicated example is based on CCM, (see MODE_CCM) an AEAD mode that provides both confidentiality and authentication for a message.
The CCM mode optionally allows the header of the message to remain in the clear, whilst still being authenticated. The encryption is done as follows:
>>> from Cryptodome.Cipher import AES >>> >>> hdr = b'To your eyes only' >>> plaintext = b'Attack at dawn' >>> key = b'Sixteen byte key' >>> cipher = AES.new(key, AES.MODE_CCM) >>> cipher.update(hdr) >>> msg = cipher.nonce, hdr, cipher.encrypt(plaintext), cipher.digest()
We assume that the tuple msg is transmitted to the receiver:
>>> from Cryptodome.Cipher import AES >>> >>> nonce, hdr, ciphertext, mac = msg >>> key = b'Sixteen byte key' >>> cipher = AES.new(key, AES.MODE_CCM, nonce) >>> cipher.update(hdr) >>> plaintext = cipher.decrypt(ciphertext) >>> try: >>> cipher.verify(mac) >>> print "The message is authentic: hdr=%s, pt=%s" % (hdr, plaintext) >>> except ValueError: >>> print "Key incorrect or message corrupted"
If no nonce is supplied initially, a 11 bytes random nonce is generated, which is good for a maximum message size of 4G. See CCM.
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_CCM = 8 Counter with CBC-MAC (CCM) Mode. See Cryptodome.Cipher._mode_ccm.CcmMode. |
|
MODE_EAX = 9 EAX Mode. See Cryptodome.Cipher._mode_eax.EaxMode. |
|
MODE_SIV = 10 Syntethic Initialization Vector (SIV). See Cryptodome.Cipher._mode_siv.SivMode. |
|
MODE_GCM = 11 Galois Counter Mode (GCM). See Cryptodome.Cipher._mode_gcm.GcmMode. |
|
MODE_OCB = 12 Offset Code Book (OCB). See Cryptodome.Cipher._mode_ocb.OcbMode. |
|
block_size = 16 Size of a data block (in bytes) |
|
key_size =
Size of a key (in bytes) |
Function Details |
Create a new AES cipher
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Thu Feb 16 14:05:21 2017 | http://epydoc.sourceforge.net |