
    mg                        U d Z ddlmZmZmZmZmZmZ ddlZddl	m
Z
mZmZmZ ddlmZmZ 	 ddlmZmZ dZeeeeeeeef   Zeeeef   Zeeeef   Zd
Zdez   Zg Zee   ed<   g Z ee   ed<   i Z!e
eef   ed<   i Z"e
eef   ed<    G d d      Z# G d de#      Z$ G d de#      Z% G d de#      Z&dedededededededdfd Z'dee   fd!Z(dee   fd"Z)dedefd#Z*ded$ede#fd%Z+d&ddd	e$d'dffZ,eed(f   ed)<   ere,d*ez   d+d,de&efdfd-ez   d+d+de&efdffz  Z,e,d.ez   d/d/de%efdfd0ez   d1d1de%efdfd2ez   d3d3de%efdfd4ez   d+d+de%efd	fd5ez   d/d6de%efd	fd7ez   d1d6de%efd	fd8ez   d3d6de%efd	fd9ez   d+d6de%efd	ffz  Z,ere,d*ez   d+d,d	e&efdfd-ez   d+d+d	e&efdffz  Z,e,d.d/d/d	e%efdfd0d1d1d	e%efdfd2d3d3d	e%efdfd:d/d/d	e%efdfd;d<d<d	e%efdfd=d+d/d	e%efdfd>d?d?d	e%efdfd@d1d1d	e%efdfd4d+d+d	e%efd	fd5d/d6d	e%efd	fd7d1d6d	e%efd	fd8d3d6d	e%efd	fd9d+d6d	e%efd	ffz  Z,e,D ]  \  Z-Z.Z/Z0Z1Z2Z3 e'e-e.e/e0e1e2e3        y# e$ r d	ZY w xY w)Az#SSH message authentication handlers    )md5sha1sha224sha256sha384sha512N)DictCallableListTuple   )UInt32UInt64)umac64umac128TFs   @openssh.coms   -etm	_mac_algs_default_mac_algs_mac_handler_mac_paramsc                   L    e Zd ZdZdedefdZdededefdZdeded	edefd
Z	y)MACz4Parent class for SSH message authentication handlerskey	hash_sizec                      || _         || _        y N)_key
_hash_size)selfr   r   s      ,lib/python3.12/site-packages/asyncssh/mac.py__init__zMAC.__init__5   s    	#    seqpacketreturnc                     t         !Compute a signature for a messageNotImplementedErrorr   r"   r#   s      r   signzMAC.sign9   
     "!r!   sigc                     t         !Verify the signature of a messager(   r   r"   r#   r-   s       r   verifyz
MAC.verify>   r,   r!   N)
__name__
__module____qualname____doc__bytesintr    r+   boolr2    r!   r   r   r   2   sS    >$E $c $" "U "u "
"# "u "5 "T "r!   r   c                   <    e Zd ZdZdededefdZdedededefdZy)	_NullMACz#Null message authentication handlerr"   r#   r$   c                      y)r'   r!   r:   r*   s      r   r+   z_NullMAC.signG   s     r!   r-   c                     |dk(  S )r0   r!   r:   r1   s       r   r2   z_NullMAC.verifyL   s     czr!   N)	r3   r4   r5   r6   r8   r7   r+   r9   r2   r:   r!   r   r<   r<   D   s@    - U u 
# u 5 T r!   r<   c                   \     e Zd ZdZdededef fdZdededefd	Zdeded
ede	fdZ
 xZS )_HMACz)HMAC-based message authentication handlerr   r   hash_algc                 4    t         |   ||       || _        y r   )superr    	_hash_alg)r   r   r   rA   	__class__s       r   r    z_HMAC.__init__U       i(!r!   r"   r#   r$   c                     t        |      |z   }t        j                  | j                  || j                        j                         }|d| j                   S )r'   N)r   hmacnewr   rD   digestr   )r   r"   r#   datar-   s        r   r+   z
_HMAC.signY   sG     c{V#hhtyy$7>>@#DOO$$r!   r-   c                 N    t        j                  | j                  ||      |      S r/   rH   compare_digestr+   r1   s       r   r2   z_HMAC.verify`   "     ""499S&#93??r!   r3   r4   r5   r6   r7   r8   r
   r    r+   r9   r2   __classcell__rE   s   @r   r@   r@   R   s`    3"E "c "X "% %U %u %@# @u @5 @T @r!   r@   c                   \     e Zd ZdZdededef fdZdededefd	Zdeded
ede	fdZ
 xZS )_UMACz)UMAC-based message authentication handlerr   r   umac_algc                 4    t         |   ||       || _        y r   )rC   r    	_umac_alg)r   r   r   rU   rE   s       r   r    z_UMAC.__init__i   rF   r!   r"   r#   r$   c                 j    | j                  | j                  |t        |            j                         S r&   )rW   r   r   rJ   r*   s      r   r+   z
_UMAC.signm   s(     ~~dii=DDFFr!   r-   c                 N    t        j                  | j                  ||      |      S r/   rM   r1   s       r   r2   z_UMAC.verifyr   rO   r!   rP   rR   s   @r   rT   rT   f   sd    3"E "c "X "G GU Gu G
@# @u @5 @T @r!   rT   mac_algkey_sizer   etmhandlerargsdefaultr$   c                     | r,t         j                  |        |rt        j                  |        |||ft        | <   |||ft        | <   y)zRegister a MAC algorithmN)r   appendr   r   r   )rZ   r[   r   r\   r]   r^   r_   s          r   register_mac_algrb   x   sH    
 !$$W-$i6L$i5Kr!   c                      t         S )zReturn supported MAC algorithms)r   r:   r!   r   get_mac_algsrd      s
     r!   c                      t         S )zReturn default MAC algorithms)r   r:   r!   r   get_default_mac_algsrf      s
     r!   c                     t         |    S )zGet parameters of a MAC algorithm

       This function returns the key and hash sizes of a MAC algorithm and
       whether or not to compute the MAC before or after encryption.

    )r   )rZ   s    r   get_mac_paramsrh      s     wr!   r   c                 0    t         |    \  }}} |||g| S )zReturn a MAC handler

       This function returns a MAC object initialized with the specified
       key that can be used for data signing and verification.

    )r   )rZ   r   r]   r   r^   s        r   get_macrj      s'      ,G4GY3	)D))r!   r!   r:   ._mac_algs_lists   umac-64      s   umac-128s   hmac-sha2-256    s   hmac-sha2-512@   s	   hmac-sha1   s   hmac-md5s   hmac-sha2-256-96   s   hmac-sha2-512-96s   hmac-sha1-96s   hmac-md5-96s   hmac-sha256-2@ssh.coms   hmac-sha224@ssh.com   s   hmac-sha256@ssh.coms   hmac-sha384@ssh.com0   s   hmac-sha512@ssh.com)4r6   hashlibr   r   r   r   r   r   rH   typingr	   r
   r   r   r#   r   r   cryptor   r   _umac_availableImportErrorr7   r8   r9   _MACAlgsArgs_MACHandler
_MACParams_OPENSSH_ETMr   __annotations__r   r   r   r   r<   r@   rT   rb   rd   rf   rh   rj   rk   _alg	_key_sizer   _etm_mac_alg_args_defaultr:   r!   r   <module>r      sv  * * = =  . . "'O
 UCdHeTABHc5()3T>"
 	4; !# 4; #)+d5+%& +')T%#$ )" "$s @C @(@C @$6e 6s 6s 66)169>6"6'+6d5k d5k  E  j  	*U 	* 	*3 	* 	!a"dK,lC'(  	d	a6)dK	t	R7*dKM MN R6)dKR6)dKDR4'dK4R3&eL4R6)eL4R6)eLtR4'eLdR3&eLN N 	h	a6)dK	x	R7*dKM MN R6)dKR6)dKR4'dKR6)dKR6)dKR6)dKR6)dKR6)dKR3&eLR6)eLR6)eLR4'eLR3&eLN N  &4"D)Z%T9j$uh0 &4e  Os   
H8 8II