Package Cryptodome :: Package Cipher :: Module _mode_ocb

Module _mode_ocb

Offset Codebook (OCB) mode.

OCB is Authenticated Encryption with Associated Data (AEAD) cipher mode designed by Prof. Phillip Rogaway and specified in RFC7253.

The algorithm provides both authenticity and privacy, it is very efficient, it uses only one key and it can be used in online mode (so that encryption or decryption can start before the end of the message is available).

This module implements the third and last variant of OCB (OCB3) and it only works in combination with a 128-bit block symmetric cipher, like AES.

OCB is patented in US but free licenses exist for software implementations meant for non-military purposes.

Example:
>>> from Cryptodome.Cipher import AES
>>> from Cryptodome.Random import get_random_bytes
>>>
>>> key = get_random_bytes(32)
>>> cipher = AES.new(key, AES.MODE_OCB)
>>> plaintext = b"Attack at dawn"
>>> ciphertext, mac = cipher.encrypt_and_digest(plaintext)
>>> # Deliver cipher.nonce, ciphertext and mac
...
>>> cipher = AES.new(key, AES.MODE_OCB, nonce=nonce)
>>> try:
>>>     plaintext = cipher.decrypt_and_verify(ciphertext, mac)
>>> except ValueError:
>>>     print "Invalid message"
>>> else:
>>>     print plaintext
Classes
  OcbMode
Offset Codebook (OCB) mode.