| Server IP : 217.160.0.135 / Your IP : 216.73.217.85 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /usr/lib/python3/dist-packages/Cryptodome/Cipher/__pycache__/ |
Upload File : |
�
8�tc~M � �� � d Z ddlZddlmZ ddlmZmZ ddlmZm Z ddl
mZ ddlm
Z
ddlmZ dd lmZmZmZmZmZmZmZmZ ed
d� � Z G d� d
e� � Zd� ZdS )ap
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
: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_bytes)�
long_to_bytes�
bytes_to_long)�strxor)�BLAKE2s)�get_random_bytes)�load_pycryptodome_raw_lib�VoidPointer�create_string_buffer�get_raw_buffer�SmartPointer�c_size_t�c_uint8_ptr� is_bufferzCryptodome.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� Zdd�Z 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| _ | j | j
| j | j | j g| _ t% |� � }|� d � � }t) j d
| j dz dz � � d
dt |� � z
z z dz | j z }t- |d � � dz }t- |d � � dz } |j ||j fi |��} | �
t) j d|d d� |� � � � }
|
t3 |
d d� |
dd� � � z }t5 t7 |� � d|z
z d� � dd � }|� |� � }
|rt dt; |� � z � � �t= � � | _ t@ �! |
�"