
    7gI                     \	   U d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	  e
ej                  ZdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zer ej         ej        d ej                                        dd         Z ej                    Z ej                     Z ej!                    Z ej"                    Z ej#                    Z ej$                    Z ej%                    Z ej&                    Z ej'                    Z ej(                    Z ej)                    Z ej*                    Z ej+                    Z ej,                    Z ej-                    Z.e/e0d<    ej1                    Z2e/e0d<    ej3                    Z4e/e0d	<    ej5                    Z6e/e0d
<    ej7                    Z8e/e0d<    ej9                    Z:e/e0d<    ej;                    Z<e/e0d<    ej=                    Z>e/e0d<    ej?                    Z@e/e0d<    ej         ej        d ejA                                        dd         ZBeCe0d<    ejD                    ZEe/e0d<    ejF                    ZGe/e0d<    ejH                    ZIe/e0d<    ejJ                    ZKe/e0d<    ejL                    ZMe/e0d<    ejN                    ZOe/e0d<    ejP                    ZQe/e0d<    ejR                    ZSe/e0d<    ejT                    ZUe/e0d<    ejV                    ZWe/e0d<    ej         ej        d ejX                                        dd         ZYeCe0d<    ejZ                    Z[e/e0d<    ej\                    Z]e/e0d<    ej^                    Z_e/e0d<    ej`                    Zae/e0d<    ejb                    Zce/e0d <    ejd                    Zee/e0d!<    ejf                    Zge/e0d"<    ejh                    Zie/e0d#<    ejj                    Zke/e0d$<    ejl                    Zme/e0d%<   eZneZoeZpeZqeZreZsd&Ztd'Zud(Zvd)Zwewfd*e/d+e/d,e/d-e/d.df
d/Zxd0e/d1e/d.ee/e/e/f         fd2Zyd3ewfd4eCd5eCd*e/d+e/d,e/d6e/d-e/d.eCfd7Zzeneofd4eCd0e/d1e/d.eCfd8Z{d9eCd4eCd.e
fd:Z|d0e/d1e/d;e/d.dfd<Z}d=e/d4eCd5eCd0e/d1e/d;e/d.eCfd>Z~d4eCd0e/d1e/d;e/d.eCf
d?Zd9eCd4eCd.e
fd@ZeZdS )A    N)Tuple)ffilib)ensure    char *crypto_pwhash_ALG_ARGON2I13crypto_pwhash_ALG_ARGON2ID13crypto_pwhash_ALG_DEFAULTcrypto_pwhash_SALTBYTEScrypto_pwhash_STRBYTEScrypto_pwhash_PASSWD_MINcrypto_pwhash_PASSWD_MAXcrypto_pwhash_BYTES_MINcrypto_pwhash_BYTES_MAXcrypto_pwhash_argon2i_STRPREFIX"crypto_pwhash_argon2i_MEMLIMIT_MIN"crypto_pwhash_argon2i_MEMLIMIT_MAX"crypto_pwhash_argon2i_OPSLIMIT_MIN"crypto_pwhash_argon2i_OPSLIMIT_MAX*crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVE*crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVE'crypto_pwhash_argon2i_OPSLIMIT_MODERATE'crypto_pwhash_argon2i_MEMLIMIT_MODERATE(crypto_pwhash_argon2i_OPSLIMIT_SENSITIVE(crypto_pwhash_argon2i_MEMLIMIT_SENSITIVE crypto_pwhash_argon2id_STRPREFIX#crypto_pwhash_argon2id_MEMLIMIT_MIN#crypto_pwhash_argon2id_MEMLIMIT_MAX#crypto_pwhash_argon2id_OPSLIMIT_MIN#crypto_pwhash_argon2id_OPSLIMIT_MAX+crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE+crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE(crypto_pwhash_argon2id_OPSLIMIT_MODERATE(crypto_pwhash_argon2id_MEMLIMIT_MODERATE)crypto_pwhash_argon2id_OPSLIMIT_SENSITIVE)crypto_pwhash_argon2id_MEMLIMIT_SENSITIVE??   l    i   nrpmaxmemreturnc                 R   t          |dk    dt          j                   t          |dk    dt          j                   t          | | dz
  z  dk    dt          j                   t          | dk    dt          j                   t          |t          |z  k    d                    t                    t          j                   t          | dd	|z  z  k     t          j                   |d
z  |z  }t
          d
z  }t          | dz   ||z  k    t          j                   d|z  | dz   z  dz  }t          |t
          |z
  k    t          j                   t          |t          j        |z
  k    t          j                   t          ||z   |k    dt          j                   d S )Nr   zInvalid block sizeraisingzInvalid parallelization factor   z Cost factor must be a power of 2zCost factor must be at least 2zp*r is greater than {}                z7Memory limit would be exceeded with the choosen n, r, p)r   exc
ValueErrorSCRYPT_PR_MAXformat
UINT64_MAXsysmaxsize)r*   r+   r,   r-   BleniVlens          U/var/www/html/syslog/venv/lib/python3.11/site-packages/nacl/bindings/crypto_pwhash.py_check_memory_occupationrC      s    16'@@@@
163S^LLLL
	
a!e*    1q52CNKKKK
	]Q ''66    1b1f7777s7Q;DSA
1q5AE>3>22226QUaD
4:$$cn====
43;%%s~>>>>
tvA     r   opslimitmemlimitc                    | dk     rd} d}| |dz  k     r,d}| d|z  z  }t          dd          D ]}d|z  |dz  k    r nnA||dz  z  }t          dd          D ]}d|z  |dz  k    r n| dz  d|z  z  }|d	k    rd	}||z  }|||fS )
z/Python implementation of libsodium's pickparamsi      r6   r2   r7   r)   r5   r4   r(   )range)rD   rE   r+   r,   maxnn_log2maxrps          rB    nacl_bindings_pick_scrypt_paramsrL      s    
 %	A8r>""AE"Arll 	 	FV	** + AG$Arll 	 	FVtqy(( ) QAK0:EQJ1a<r   @   passwdsaltdklenc                 8   t          t          dt          j                   t          t	          |t
                    t                     t          t	          |t
                    t                     t          t	          |t
                    t                     t          t	          | t                    t                     t          t	          |t                    t                     t          ||||           t          j
        d|          }t          j        | t          |           |t          |          |||||	  	        }t          |dk    dt          j                   t          j        t          j        d|          |          dd         S )a  
    Derive a cryptographic key using the ``passwd`` and ``salt``
    given as input.

    The work factor can be tuned by by picking different
    values for the parameters

    :param bytes passwd:
    :param bytes salt:
    :param bytes salt: *must* be *exactly* :py:const:`.SALTBYTES` long
    :param int dklen:
    :param int opslimit:
    :param int n:
    :param int r: block size,
    :param int p: the parallelism factor
    :param int maxmem: the maximum available memory available for scrypt's
                       operations
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    Not available in minimal buildr0   z	uint8_t[]r   $Unexpected failure in key derivationr   N)r   &has_crypto_pwhash_scryptsalsa208sha256r8   UnavailableError
isinstanceint	TypeErrorbytesrC   r   newr   %crypto_pwhash_scryptsalsa208sha256_lllenRuntimeErrorbuffercast)	rN   rO   r*   r+   r,   rP   r-   bufrets	            rB   r[   r[   	  sb   < .($    :ay1111
:ay1111
:ay1111
:fe$$i8888
:dE""I6666Q1f---
'+u
%
%C

3FT3t99aAsE C q.     :chx--u55aaa88r   c                 *   t          t          dt          j                   t	          j        dt                    }t          j        || t          |           ||          }t          |dk    dt          j
                   t	          j        |          S )a  
    Derive a cryptographic key using the ``passwd`` and ``salt``
    given as input, returning a string representation which includes
    the salt and the tuning parameters.

    The returned string can be directly stored as a password hash.

    See :py:func:`.crypto_pwhash_scryptsalsa208sha256` for a short
    discussion about ``opslimit`` and ``memlimit`` values.

    :param bytes passwd:
    :param int opslimit:
    :param int memlimit:
    :return: serialized key hash, including salt and tuning parameters
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    rR   r0   char[]r   z&Unexpected failure in password hashing)r   rT   r8   rU   r   rZ   SCRYPT_STRBYTESr   &crypto_pwhash_scryptsalsa208sha256_strr\   r]   string)rN   rD   rE   r`   ra   s        rB   re   re   E  s    . .($    '(O
,
,C

4VS[[(H C q0     :c??r   passwd_hashc                 8   t          t          dt          j                   t          t	          |           t
          dz
  k    dt          j                   t          j        | |t	          |                    }t          |dk    dt          j	                   dS )a9  
    Verifies the ``passwd`` against the ``passwd_hash`` that was generated.
    Returns True or False depending on the success

    :param passwd_hash: bytes
    :param passwd: bytes
    :rtype: boolean
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    rR   r0   r2   zInvalid password hashr   Wrong passwordT)
r   rT   r8   rU   r\   rd   r9   r   -crypto_pwhash_scryptsalsa208sha256_str_verifyInvalidkeyErrorrg   rN   ra   s      rB   rj   rj   q  s     .($    KOa//    
;VS[[ C 3!8%s/BCCCC4r   algc                    |t           k    r|t          k     r,t          j        d                    t                              |t
          k    r,t          j        d                    t
                              | t          k     r,t          j        d                    t                              | t          k    r,t          j        d                    t                              d S |t          k    r|t          k     r,t          j        d                    t                              |t          k    r,t          j        d                    t                              | t          k     r,t          j        d                    t                              | t          k    r,t          j        d                    t                              d S t          j        d          )Nz"memlimit must be at least {} bytesz!memlimit must be at most {} byteszopslimit must be at least {}zopslimit must be at most {}zUnsupported algorithm)r	   r   r8   r9   r;   r   r   r   r
   r   r   r    r!   rX   )rD   rE   rm   s      rB   _check_argon2_limits_algro     s   
)))888.4;;6   
 :::.3::6   
 888..556   
 :::.-446    ;: 
,	,	,999.4;;7   
 ;;;.3::7   
 999..557   
 ;;;.-447    <; m3444r   outlenc           
      H   t          t          | t                    t          j                   t          t          |t                    t          j                   t          t          |t                    t          j                   t          t          |t                    t          j                   t          t          |t
                    t          j                   t          |          t          k    r,t          j        d	                    t                              | t          k     r,t          j        d	                    t                              | t          k    r,t          j        d	                    t                              t          |||           t          j        d|           }t          j        || |t          |          ||||          }t          |dk    dt          j                   t          j        ||           dd         S )	a  
    Derive a raw cryptographic key using the ``passwd`` and the ``salt``
    given as input to the ``alg`` algorithm.

    :param outlen: the length of the derived key
    :type outlen: int
    :param passwd: The input password
    :type passwd: bytes
    :param salt:
    :type salt: bytes
    :param opslimit: computational cost
    :type opslimit: int
    :param memlimit: memory cost
    :type memlimit: int
    :param alg: algorithm identifier
    :type alg: int
    :return: derived key
    :rtype: bytes
    r0   z"salt must be exactly {} bytes longz*derived key must be at least {} bytes longz)derived key must be at most {} bytes longzunsigned char[]r   rS   N)r   rV   rW   r8   rX   rY   r\   r   r9   r;   r   r   ro   r   rZ   r   crypto_pwhashr]   r^   )rp   rN   rO   rD   rE   rm   outbufra   s           rB   crypto_pwhash_algrt     s   6 :fc""CM::::
:h$$cm<<<<
:h$$cm<<<<
:c37777
:fe$$cm<<<<
4yy+++n077' 
 
 	
 '''n8??' 
 
 	
 
)	)	)n7>>' 
 
 	
 Xx555W&//F

FT8Xs C q.     :ff%%aaa((r   c                    t          t          |t                    t                     t          t          |t                    t                     t          t          | t                    t                     t          |||           t          j        dd          }t          j	        || t          |           |||          }t          |dk    dt          j                   t          j        |          S )a  
    Derive a cryptographic key using the ``passwd`` given as input
    and a random salt, returning a string representation which
    includes the salt, the tuning parameters and the used algorithm.

    :param passwd: The input password
    :type passwd: bytes
    :param opslimit: computational cost
    :type opslimit: int
    :param memlimit: memory cost
    :type memlimit: int
    :param alg: The algorithm to use
    :type alg: int
    :return: serialized derived key and parameters
    :rtype: bytes
    r0   rc   r4   r   rS   )r   rV   rW   rX   rY   ro   r   rZ   r   crypto_pwhash_str_algr\   r8   r]   rf   )rN   rD   rE   rm   rs   ra   s         rB   rv   rv     s    , :h$$i8888
:h$$i8888
:fe$$i8888Xx555WXs##F

#FXx C q.     :fr   c                    t          t          | t                    t                     t          t          |t                    t                     t          t	          |           dk    dt
          j                   t          j        | |t	          |                    }t          |dk    dt
          j	                   dS )a4  
    Verifies the ``passwd`` against a given password hash.

    Returns True on success, raises InvalidkeyError on failure
    :param passwd_hash: saved password hash
    :type passwd_hash: bytes
    :param passwd: password to be checked
    :type passwd: bytes
    :return: success
    :rtype: boolean
    r0      z#Hash must be at most 127 bytes longr   ri   T)
r   rV   rY   rX   r\   r8   r9   r   crypto_pwhash_str_verifyrk   rl   s      rB   ry   ry   =  s     :k5))9====
:fe$$i8888
KC-    
&{FCKK
H
HC
3!8%s/BCCCC4r   )r=   typingr   nacl.exceptions
exceptionsr8   nacl._sodiumr   r   r   bool-PYNACL_HAS_CRYPTO_PWHASH_SCRYPTSALSA208SHA256rT   ,crypto_pwhash_scryptsalsa208sha256_STRPREFIX,crypto_pwhash_scryptsalsa208sha256_SALTBYTES+crypto_pwhash_scryptsalsa208sha256_STRBYTES-crypto_pwhash_scryptsalsa208sha256_PASSWD_MIN-crypto_pwhash_scryptsalsa208sha256_PASSWD_MAX,crypto_pwhash_scryptsalsa208sha256_BYTES_MIN,crypto_pwhash_scryptsalsa208sha256_BYTES_MAX/crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN/crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX/crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN/crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX7crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE7crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE5crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE5crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVErf   r_   ,crypto_pwhash_scryptsalsa208sha256_strprefix,crypto_pwhash_scryptsalsa208sha256_saltbytes+crypto_pwhash_scryptsalsa208sha256_strbytes-crypto_pwhash_scryptsalsa208sha256_passwd_min-crypto_pwhash_scryptsalsa208sha256_passwd_max,crypto_pwhash_scryptsalsa208sha256_bytes_min,crypto_pwhash_scryptsalsa208sha256_bytes_max/crypto_pwhash_scryptsalsa208sha256_memlimit_min/crypto_pwhash_scryptsalsa208sha256_memlimit_max/crypto_pwhash_scryptsalsa208sha256_opslimit_min/crypto_pwhash_scryptsalsa208sha256_opslimit_max7crypto_pwhash_scryptsalsa208sha256_opslimit_interactive7crypto_pwhash_scryptsalsa208sha256_memlimit_interactive5crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive5crypto_pwhash_scryptsalsa208sha256_memlimit_sensitivecrypto_pwhash_alg_argon2i13r	   rW   __annotations__crypto_pwhash_alg_argon2id13r
   crypto_pwhash_alg_defaultr   crypto_pwhash_saltbytesr   crypto_pwhash_strbytesr   crypto_pwhash_passwd_minr   crypto_pwhash_passwd_maxr   crypto_pwhash_bytes_minr   crypto_pwhash_bytes_maxr   crypto_pwhash_argon2i_strprefixr   rY   "crypto_pwhash_argon2i_memlimit_minr   "crypto_pwhash_argon2i_memlimit_maxr   "crypto_pwhash_argon2i_opslimit_minr   "crypto_pwhash_argon2i_opslimit_maxr   *crypto_pwhash_argon2i_opslimit_interactiver   *crypto_pwhash_argon2i_memlimit_interactiver   'crypto_pwhash_argon2i_opslimit_moderater   'crypto_pwhash_argon2i_memlimit_moderater   (crypto_pwhash_argon2i_opslimit_sensitiver   (crypto_pwhash_argon2i_memlimit_sensitiver    crypto_pwhash_argon2id_strprefixr   #crypto_pwhash_argon2id_memlimit_minr   #crypto_pwhash_argon2id_memlimit_maxr   #crypto_pwhash_argon2id_opslimit_minr    #crypto_pwhash_argon2id_opslimit_maxr!   +crypto_pwhash_argon2id_opslimit_interactiver"   +crypto_pwhash_argon2id_memlimit_interactiver#   (crypto_pwhash_argon2id_opslimit_moderater$   (crypto_pwhash_argon2id_memlimit_moderater%   )crypto_pwhash_argon2id_opslimit_sensitiver&   )crypto_pwhash_argon2id_memlimit_sensitiver'   SCRYPT_OPSLIMIT_INTERACTIVESCRYPT_MEMLIMIT_INTERACTIVESCRYPT_OPSLIMIT_SENSITIVESCRYPT_MEMLIMIT_SENSITIVESCRYPT_SALTBYTESrd   r:   LOG2_UINT64_MAXr<   SCRYPT_MAX_MEMrC   rL   r[   re   rj   ro   rt   rv   ry    crypto_pwhash_argon2i_str_verify r   rB   <module>r      s	   



             ! ! ! ! ! ! ! ! " " " " " " *.5* * & 03 ,/0 ,./ +01 -01 -/0 ,/0 ,23 /23 /23 /23 /:; 7:; 789 589 5) -3=3:K3KMMNN4 4aa4	0 	98:: 1 	8799 0 	:9;; 2 	:9;; 2 	98:: 1 	98:: 1 	<;== 4 	<;== 4 	<;== 4 	<;== 4 	DCEE < 	DCEE < 	BACC : 	BACC : $C3#B#D#D S D D D$DC$D$F$F c F F F!>!>!@!@ 3 @ @ @:s:<<  < < <8c8::  : : : < < > > # > > > < < > > # > > >:s:<<  < < <:s:<<  < < <)3CHX:s:<<==* *!!*     +C*,, #C    +C*,, #C    +C*,, #C    +C*,, #C    3C244 +C    3C244 +C    0C/11 (    0C/11 (    1C022 )#    1C022 )#    +5#*CHX;s;==>>+ +!!+  %    ,C+-- $S    ,C+-- $S    ,C+-- $S    ,C+-- $S    4C355 ,S    4C355 ,S    1C022 )#    1C022 )#    2C133 *3    2C133 *3   
 <  <  :  :  @ =
# +9' '
'''$''	' ' ' 'T 
3S=   L  99 9999
99 99 	99
 99 99 99 99 99 99 99| 0/) ))) ) 	) ) ) )X %	   B65s 65c 65 65 65 65 65 65rD)D)D) D) 	D)
 D) 
D) D) D) D) D)N((( ( 
	(
 ( ( ( (V%  4    6 $<      r   