o
     `                     @   s  d dl mZmZmZ d dlZd dlZd dlmZ eej	G dd de
Zeej	G dd de
Zeej	G dd	 d	e
Zeej	G d
d de
Zeej	G dd de
Zdd Zdd Zdd ZeeeeG dd de
ZeeeeG dd de
ZeeG dd de
ZeeeeG dd de
ZeeeeG dd de
ZeeeeG dd de
ZeeeeG d d! d!e
ZeeeeeeG d"d# d#e
ZdS )$    )absolute_importdivisionprint_functionN)utilsc                   @   s(   e Zd Zejdd Zejdd ZdS )Modec                 C      dS )z@
        A string naming this mode (e.g. "ECB", "CBC").
        N selfr   r   home/ych/rk3568/buildroot/output/rockchip_rk3568/host/lib/python3.10/site-packages/cryptography/hazmat/primitives/ciphers/modes.pyname       z	Mode.namec                 C   r   )zq
        Checks that all the necessary invariants of this (mode, algorithm)
        combination are met.
        Nr   r
   	algorithmr   r   r   validate_for_algorithm   r   zMode.validate_for_algorithmN)__name__
__module____qualname__abcabstractpropertyr   abstractmethodr   r   r   r   r   r      s
    
r   c                   @      e Zd Zejdd ZdS )ModeWithInitializationVectorc                 C   r   )zP
        The value of the initialization vector for this mode as bytes.
        Nr   r	   r   r   r   initialization_vector    r   z2ModeWithInitializationVector.initialization_vectorN)r   r   r   r   r   r   r   r   r   r   r          r   c                   @   r   )ModeWithTweakc                 C   r   )z@
        The value of the tweak for this mode as bytes.
        Nr   r	   r   r   r   tweak)   r   zModeWithTweak.tweakN)r   r   r   r   r   r   r   r   r   r   r   '   r   r   c                   @   r   )ModeWithNoncec                 C   r   )z@
        The value of the nonce for this mode as bytes.
        Nr   r	   r   r   r   nonce2   r   zModeWithNonce.nonceN)r   r   r   r   r   r   r   r   r   r   r   0   r   r   c                   @   r   )ModeWithAuthenticationTagc                 C   r   )zP
        The value of the tag supplied to the constructor of this mode.
        Nr   r	   r   r   r   tag;   r   zModeWithAuthenticationTag.tagN)r   r   r   r   r   r    r   r   r   r   r   9   r   r   c                 C   s$   |j dkr|jdkrtdd S d S )N   ZAESz=Only 128, 192, and 256 bit keys are allowed for this AES mode)key_sizer   
ValueErrorr   r   r   r   _check_aes_key_lengthB   s
   r$   c                 C   s0   t | jd |jkrtdt | j| jd S )N   zInvalid IV size ({}) for {}.)lenr   
block_sizer#   formatr   r   r   r   r   _check_iv_lengthI   s   r)   c                 C   s   t | | t| | d S N)r$   r)   r   r   r   r   _check_iv_and_key_lengthR   s   
r+   c                   @   &   e Zd Zd Zdd ZedZeZ	dS )CBCc                 C      t d| || _d S Nr   r   _check_byteslike_initialization_vectorr
   r   r   r   r   __init__\      
zCBC.__init__r2   N
r   r   r   r   r4   r   read_only_propertyr   r+   r   r   r   r   r   r-   W   
    
r-   c                   @   *   e Zd Zd Zdd ZedZdd ZdS )XTSc                 C   s*   t d| t|dkrtd|| _d S )Nr      z!tweak must be 128-bits (16 bytes))r   r1   r&   r#   _tweak)r
   r   r   r   r   r4   i   s   
zXTS.__init__r<   c                 C   s   |j dvr	tdd S )N)r!   i   z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)r"   r#   r   r   r   r   r   s   s
   
zXTS.validate_for_algorithmN)	r   r   r   r   r4   r   r7   r   r   r   r   r   r   r:   d   s
    
r:   c                   @   s   e Zd Zd ZeZdS )ECBN)r   r   r   r   r$   r   r   r   r   r   r=   {   s    r=   c                   @   r,   )OFBc                 C   r.   r/   r0   r3   r   r   r   r4      r5   zOFB.__init__r2   Nr6   r   r   r   r   r>      r8   r>   c                   @   r,   )CFBc                 C   r.   r/   r0   r3   r   r   r   r4      r5   zCFB.__init__r2   Nr6   r   r   r   r   r?      r8   r?   c                   @   r,   )CFB8c                 C   r.   r/   r0   r3   r   r   r   r4      r5   zCFB8.__init__r2   Nr6   r   r   r   r   r@      r8   r@   c                   @   r9   )CTRc                 C   r.   )Nr   )r   r1   _nonce)r
   r   r   r   r   r4      r5   zCTR.__init__rB   c                 C   s:   t | | t| jd |jkrtdt| j| jd S )Nr%   zInvalid nonce size ({}) for {}.)r$   r&   r   r'   r#   r(   r   r   r   r   r   r      s   
zCTR.validate_for_algorithmN)	r   r   r   r   r4   r   r7   r   r   r   r   r   r   rA      s
    
rA   c                   @   s>   e Zd Zd ZdZdZdddZedZ	edZ
d	d
 ZdS )GCMl   ? l            Nr;   c                 C   s   t d| t|dk st|dkrtd|| _|d ur8t d| |dk r+tdt||k r8td||| _|| _d S )	Nr   r%      zIinitialization_vector must be between 8 and 128 bytes (64 and 1024 bits).r       zmin_tag_length must be >= 4z.Authentication tag must be {} bytes or longer.)	r   r1   r&   r#   r2   _check_bytesr(   _tagZ_min_tag_length)r
   r   r    Zmin_tag_lengthr   r   r   r4      s$   
zGCM.__init__rG   r2   c                 C   s   t | | d S r*   )r$   r   r   r   r   r      s   zGCM.validate_for_algorithm)Nr;   )r   r   r   r   Z_MAX_ENCRYPTED_BYTESZ_MAX_AAD_BYTESr4   r   r7   r    r   r   r   r   r   r   rC      s    


rC   )
__future__r   r   r   r   Zsixcryptographyr   Zadd_metaclassABCMetaobjectr   r   r   r   r   r$   r)   r+   Zregister_interfacer-   r:   r=   r>   r?   r@   rA   rC   r   r   r   r   <module>   sR   




	