) d Z ddlZddlmZ ddlmZmZmZ ddlm Z m Z ddlmZ ddl mZ ddlmZ dd lmZmZmZmZmZmZmZmZ ed d Z G d d e Zd ZdS )ah 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 Crypto.Cipher import AES >>> from Crypto.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 :undocumented: __package__ .. _RFC7253: http://www.rfc-editor.org/info/rfc7253 .. _free licenses: http://web.cs.ucdavis.edu/~rogaway/ocb/license.htm N) unhexlify)bord_copy_bytesbchr) long_to_bytes bytes_to_long)strxor)BLAKE2s)get_random_bytes)load_pycryptodome_raw_libVoidPointercreate_string_bufferget_raw_bufferSmartPointerc_size_tc_uint8_ptr is_bufferzCrypto.Cipher._raw_ocba int OCB_start_operation(void *cipher, const uint8_t *offset_0, size_t offset_0_len, void **pState); int OCB_encrypt(void *state, const uint8_t *in, uint8_t *out, size_t data_len); int OCB_decrypt(void *state, const uint8_t *in, uint8_t *out, size_t data_len); int OCB_update(void *state, const uint8_t *in, size_t data_len); int OCB_digest(void *state, uint8_t *tag, size_t tag_len); int OCB_stop_operation(void *state); c j e Zd ZdZd Zd Zd Zd Zd ZddZ dd Z d Zd Zd Z d Zd Zd Zd ZdS )OcbModez=Offset Codebook (OCB) mode. :undocumented: __init__ c ^ |j dk rt d d| _ t d d | | _ t | t dd vrt d t | st d || _ d|cxk rdk sn t d d | _ d| _ d| _ g d | _ t | }| d }| j dz dz }t | j dk r4t |dz d dt | z z z dz | j z }nt |dz dz | j z }t! |d dz }t! |d dz } |j ||j fi |} | t) j d|d d | }|t- |d d |dd z }t/ t1 | d|z z d dd } | | }|rt dt5 | z t7 | _ t: | | tA t | | j ! }|rt d|z tE | j t: j# | _ |$ d S )N zFOCB mode is only available for ciphers that operate on 128 bits blocks z#Nonce must be at most 15 bytes longz,Nonce must be bytes, bytearray or memoryview z+MAC tag must be between 8 and 16 bytes long )updateencryptdecryptdigestverifykey ? 15sB @ zUnknown keywords: z)Error %d while instantiating the OCB mode)% block_size ValueErrorr noncelenranger TypeError_mac_len_mac_tag_cache_A_cache_P_nextdictpopr r newMODE_ECBr structpackr r r _create_base_cipherstrr _state_raw_ocb_libOCB_start_operationgetr address_ofr OCB_stop_operationrelease)selffactoryr. mac_len cipher_paramsparams_without_keyr taglen_mod128bottom_bitstop_bitsktop_cipherktopstretchoffset_0 raw_cipherresults y/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Cipher/_mode_ocb.py__init__zOcbMode.__init__s sz ## @ A A A @ tU33 *u::U1b\\))BCCC LJKKK G!!!!r!!!!JKKK * * * "-00 $$U++*c1 tz??R!+,,rCJJ/0 JEE -1,455JE 59oo,b ??T)!gk#")"28 8$68 8 ""6;v/4SbSz/7$9 $9 : : RaR$qs)444 w!7!7"${"2"4579 99:= 00?? G03}3E3EEFFF!mm11*..2B2B2:2:3x==2I2I26+2H2H2J2JL L 'H%&