
    nhI                     

   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j8                   ej:                  d ej<                                     dd Z ej>                         Z ej@                         Z ejB                         Z ejD                         Z ejF                         Z ejH                         Z ejJ                         Z ejL                         Z ejN                         Z ejP                         Z ejR                         Z ejT                         Z ejV                         Z ejX                         Z ejZ                         Z.e/e0d<    ejb                         Z2e/e0d<    ejf                         Z4e/e0d	<    ejj                         Z6e/e0d
<    ejn                         Z8e/e0d<    ejr                         Z:e/e0d<    ejv                         Z<e/e0d<    ejz                         Z>e/e0d<    ej~                         Z@e/e0d<    ej8                   ej:                  d ej                                     dd ZBeCe0d<    ej                         ZEe/e0d<    ej                         ZGe/e0d<    ej                         ZIe/e0d<    ej                         ZKe/e0d<    ej                         ZMe/e0d<    ej                         ZOe/e0d<    ej                         ZQe/e0d<    ej                         ZSe/e0d<    ej                         ZUe/e0d<    ej                         ZWe/e0d<    ej8                   ej:                  d ej                                     dd ZYeCe0d<    ej                         Z[e/e0d<    ej                         Z]e/e0d<    ej                         Z_e/e0d<    ej                         Zae/e0d<    ej                         Zce/e0d <    ej                         Zee/e0d!<    ej                         Zge/e0d"<    ej                         Zie/e0d#<    ej                         Zke/e0d$<    ej                         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@ZeZy)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                 4   t        |dk7  dt        j                         t        |dk7  dt        j                         t        | | dz
  z  dk(  dt        j                         t        | dkD  dt        j                         t        |t        |z  k  dj	                  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                         y )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          m/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/nacl/bindings/crypto_pwhash.py_check_memory_occupationrC      sH    16'@
163S^^L
	
a!e* 1q52CNNK
	]Q ''6 1b1f7s7Q;DSA
1q5AE>3>>26QUaD
4:$$cnn=
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  kD  s n? n=||dz  z  }t        dd      D ]  }d|z  |dz  kD  s n | dz  dz  z  }|d	kD  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"Arl 	FV	*	 AG$Arl 	FVtqy(	 QAK0:EQJ1a<r   @   passwdsaltdklenc                    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[   	  s    < .($$ :ay1
:ay1
:ay1
:fe$i8
:dE"I6Q1f-
''+u
%C

3
3FT3t9aAsEC q.   ::chhx-u5a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  sy    . .($$ ''(O
,C

4
4VS[(HC q0   ::c?r   passwd_hashc                     t        t        dt        j                         t        t	        |       t
        dz
  k(  dt        j                         t        j                  | |t	        |            }t        |dk(  dt        j                         y)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  sz     .($$ KOa// 
;
;VS[C 3!8%s/B/BCr   algc                 d   |t         k(  r|t        k  r(t        j                  dj	                  t                    |t
        kD  r(t        j                  dj	                  t
                    | t        k  r(t        j                  dj	                  t                    | t        kD  r(t        j                  dj	                  t                    y |t        k(  r|t        k  r(t        j                  dj	                  t                    |t        kD  r(t        j                  dj	                  t                    | t        k  r(t        j                  dj	                  t                    | t        kD  r(t        j                  dj	                  t                    y 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..4;;6 
 ::..3::6 
 88...556 
 ::..-446  ; 
,	,99..4;;7 
 ;;..3::7 
 99...557 
 ;;..-447  < mm344r   outlenc           
         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        k7  r(t        j                  dj                  t                    | t        k  r(t        j                  dj                  t                    | t        kD  r(t        j                  dj                  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     so   6 :fc"CMM:
:h$cmm<
:h$cmm<
:c37
:fe$cmm<
4y++nn077'
 	
 ''nn8??'
 	
 
)	)nn7>>'
 	
 Xx5WW&/F


FT8XsC q.   ::ff%a((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
:h$i8
:fe$i8Xx5WWXs#F

#
#FXxC q.   ::fr   c                 N   t        t        | t              t               t        t        |t              t               t        t	        |       dk  dt
        j                         t        j                  | |t	        |            }t        |dk(  dt
        j                         y)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   =  sy     :k5)9=
:fe$i8
KC- 
&
&{FCK
HC
3!8%s/B/BCr   )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      su      ! " *.55* & 03 ,/0 ,./ +01 -01 -/0 ,/0 ,23 /23 /23 /23 /:; 7:; 789 589 5)3=3::K3KKMN44	0 	988: 1 	8779 0 	:99; 2 	:99; 2 	988: 1 	988: 1 	<;;= 4 	<;;= 4 	<;;= 4 	<;;= 4 	DCCE < 	DCCE < 	BAAC : 	BAAC : $C3#B#B#D S D$DC$D$D$F c F!>!>!>!@ 3 @:s::<  <8c88:  : < < < > # > < < < > # >:s::<  <:s::<  <)3CHHX:s::<=**   +C**, #C  +C**, #C  +C**, #C  +C**, #C  3C224 +C  3C224 +C  0C//1 (  0C//1 (  1C002 )#  1C002 )#  +5#**CHHX;s;;=>++  %  ,C++- $S  ,C++- $S  ,C++- $S  ,C++- $S  4C335 ,S  4C335 ,S  1C002 )#  1C002 )#  2C113 *3  2C11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| 0/))) ) 	)X %	B65s 65c 65 65 65rD)D)D) D) 	D)
 D) 
D) D)N((( ( 
	(
 (V%  4 6 $<  r   