ff)W:ddlZddlZddlmZddlmZmZmZmZm Z m Z m Z ddl m Z mZmZmZmZddlmZddlmZddlmZmZmZddlmZmZmZmZed d Z ed d Z!ddZ"ddZ#Gdde$Z%ddZ&d dZ'dZ(dZ)dZ*d!dZ+dZ,d"dZ-dS)#N)reduce)tobytesbord _copy_bytes iter_rangetostrbchrbstr)SHA1SHA256HMACCMACBLAKE2s)strxor)get_random_bytes)size long_to_bytes bytes_to_long)load_pycryptodome_raw_libcreate_string_bufferget_raw_bufferc_size_tzCrypto.Cipher._Salsa20z int Salsa20_8_core(const uint8_t *x, const uint8_t *y, uint8_t *out); zCrypto.Protocol._scrypta  typedef int (core_t)(const uint8_t [64], const uint8_t [64], uint8_t [64]); int scryptROMix(const uint8_t *data_in, uint8_t *data_out, size_t data_len, unsigned N, core_t *core); c|st}t|}|||z}|j}||krt d|zt |dkrt dt |zt|dz D])}||}*|d|S)aMDerive one key from a password (or passphrase). This function performs key derivation according to an old version of the PKCS#5 standard (v1.5) or `RFC2898 `_. Args: password (string): The secret password to generate the key from. salt (byte string): An 8 byte string to use for better protection from dictionary attacks. This value does not need to be kept secret, but it should be randomly chosen for each derivation. dkLen (integer): The length of the desired key. The default is 16 bytes, suitable for instance for :mod:`Crypto.Cipher.AES`. count (integer): The number of iterations to carry out. The recommendation is 1000 or more. hashAlgo (module): The hash algorithm to use, as a module or an object from the :mod:`Crypto.Hash` package. The digest length must be no shorter than ``dkLen``. The default algorithm is :mod:`Crypto.Hash.SHA1`. Return: A byte string of length ``dkLen`` that can be used as key. z:Selected hash algorithm has a too short digest (%d bytes).z,Salt is not 8 bytes long (%d bytes instead).N) r rnew digest_size TypeErrorlen ValueErrorrdigest)passwordsaltdkLencounthashAlgopHashr"is u/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Protocol/KDF.pyPBKDF1r+7s: x  H LL$ ' 'E  F v~~TW]]^^^ 4yyA~~G#d))STTT a ** %,,..)) <<>>&5& !!c@ tt|}rrtd tstdsfdfd d}d}t ||krp|t jd|zgd z |tt fd t|Dz }|dz }t ||kpnd}d}t ||krtj d}| |t jd|z} ||| |z }|dz }t ||k|d|S) aDerive one or more keys from a password (or passphrase). This function performs key derivation according to the PKCS#5 standard (v2.0). Args: password (string or byte string): The secret password to generate the key from. Strings will be encoded as ISO 8859-1 (also known as Latin-1), which does not allow any characters with codepoints > 255. salt (string or byte string): A (byte) string to use for better protection from dictionary attacks. This value does not need to be kept secret, but it should be randomly chosen for each derivation. It is recommended to use at least 16 bytes. Strings will be encoded as ISO 8859-1 (also known as Latin-1), which does not allow any characters with codepoints > 255. dkLen (integer): The cumulative length of the keys to produce. Due to a flaw in the PBKDF2 design, you should not request more bytes than the ``prf`` can output. For instance, ``dkLen`` should not exceed 20 bytes in combination with ``HMAC-SHA1``. count (integer): The number of iterations to carry out. The higher the value, the slower and the more secure the function becomes. You should find the maximum number of iterations that keeps the key derivation still acceptable on the slowest hardware you must support. Although the default value is 1000, **it is recommended to use at least 1000000 (1 million) iterations**. prf (callable): A pseudorandom function. It must be a function that returns a pseudorandom byte string from two parameters: a secret and a salt. The slower the algorithm, the more secure the derivation function. If not specified, **HMAC-SHA1** is used. hmac_hash_module (module): A module from ``Crypto.Hash`` implementing a Merkle-Damgard cryptographic hash, which PBKDF2 must use in combination with HMAC. This parameter is mutually exclusive with ``prf``. Return: A byte string of length ``dkLen`` that can be used as key material. If you want multiple keys, just break up this string into segments of the desired length. z2'prf' and 'hmac_hash_module' are mutually exlusiveN_pbkdf2_hmac_assistcTtj||SN)r rr")pshmac_hash_modules r*zPBKDF2..s"dhq!-=>>EEGGr,cV|d|dc|d<|d<|dS)Nrr)r3r#prfs r*linkzPBKDF2..links31ss8QqT22JAaD!A$Q4Kr,r,rz>Ic3.K|]}VdSr1r7).0jr9r3s r* zPBKDF2..s+"A"Aq4477"A"A"A"A"A"Ar,)rr!r hasattrr structpackrrranger rcopyupdater"r/) r#r$r%r&r8r4keyr)base first_digestr9r3s ` `` @@r*PBKDF2rHbs`x  H 4==D OOMNNN {'/ '*,ABB ;GGGGC       #hh#hv{4';'; ;<<>BA 6&"A"A"A"A"AE%LL"A"A"ACC CC FA#hh #hhunn8Hc+;<zHKDF..Qs7 : : : #cGm+ , : : :r,) rr!r rr"r@rAappendjoinrlist)masterrwr$hashmodnum_keyscontext output_lenhmacprktntlenkolrvs ` @r*HKDFrsy@8#JS7..//9::: -,, 8D&G 4 4 4D ++--C A A D   xQrUW_v{3/B/BBgVVV  ## Q    XXa[[N1}}hwh'' : : : : : J88 : : :C IXI  r,c dt|dz z|krtd|dkrtd|dd|zzkrtdd }t|||dz|zd| }tj} t j} g} t|D]p} | dz|z} td|z}| || | d|zz|td|z|| }|rtd |z| t|gz } qt|d | |zd| |dkrSfd td|zD}|S)uGDerive one or more keys from a passphrase. Args: password (string): The secret pass phrase to generate the keys from. salt (string): A string to use for better protection from dictionary attacks. This value does not need to be kept secret, but it should be randomly chosen for each derivation. It is recommended to be at least 16 bytes long. key_len (integer): The length in bytes of each derived key. N (integer): CPU/Memory cost parameter. It must be a power of 2 and less than :math:`2^{32}`. r (integer): Block size parameter. p (integer): Parallelization parameter. It must be no greater than :math:`(2^{32}-1)/(4r)`. num_keys (integer): The number of keys to derive. Every key is :data:`key_len` bytes long. By default, only 1 key is generated. The maximum cumulative length of all keys is :math:`(2^{32}-1)*32` (that is, 128TB). A good choice of parameters *(N, r , p)* was suggested by Colin Percival in his `presentation in 2009`__: - *( 2¹⁴, 8, 1 )* for interactive logins (≤100ms) - *( 2²⁰, 8, 1 )* for file encryption (≤5s) Return: A byte string or a tuple of byte strings. .. __: http://www.tarsnap.com/scrypt/scrypt-slides.pdf r:rzN must be a power of 2lz N is too biglr[zp or r are too bigc\tj||tSr1)r rr r")r2r3s r*r5zscrypt..s 48Aq #9#@#@#B#Br,)r8zError %X while running scryptr,c*g|]}||zSr7r7r<rudkrws r*rxzscrypt..s= B B B c#-  B B Br,r) bit_sizer!rH_raw_scrypt_lib scryptROMix_raw_salsa20_libSalsa20_8_corerrrrrz)r#r$rwNrr2r~prf_hmac_sha256stage_1rcoredata_outflowru buffer_outresultrrs ` @r*scryptrWsN Xa[[1_""1222G||((( S1W ----...BBOXtQWq[!IIIG!-K  *DH1 3 3Sj1n)#'22 WS3q=%89'%cAg..! ##  G.% A A A#d3s1u9o A A Ar,rrrr) binrzfillryr rzrBr intr) datar3cbits_cbits6rgrurs @r*_bcrypt_encoders1JA D ""T!WWabb!''** DLL!!!! 88D>>D A A A Aq#d))Q)?)? A A AE F 3B3Z!Qii af b A a))CFF #C MM!C& WWV__F 6??r,c  d}g t|D]V}||}t|ddd} |Wd  t |dz}|dkrtd|dkr dd n|d kr dd  fd td t d D}g}|D]2}|tt|d3d|}|S)Nrr:rrrzIncorrect lengthc*g|]}||dzS)rr7rs r*rxz"_bcrypt_decode..rr,rrr,) rfindrrryrzr r!rBr r) rr3rrurmodulo4bits8rrrs @r*_bcrypt_decodersCJA D 4[[ffQiiC ""1%% E 774==D$ii!mG!||+,,, ACRCy ACRCy A A A Aq#d))Q)?)? A A AE F '' d3q!99oo&&&& XXf  F Mr,c ddlm}t|dkrtdd|cxkrdksntd|||j|||}|}t dD]}||}|S) Nr) _EKSBlowfishHz6The password is too long. It must be 72 bytes at most.rz-bcrypt cost factor must be in the range 4..31@) Crypto.Cipherrr r!rMODE_ECBrBencrypt) r#costr$constantinvertrcipherctext_s r* _bcrypt_hashrs****** 8}}rQRRR OOOOOOOOHIII   h (=tT6 R RF E 2YY&&u%% Lr,c t|d}|tdddkrtdt |dkr|dz }|t d}t |dkrtd t |||d d }d tt| d z}d t|z}t|dd}d|z|z|zS)a>Hash a password into a key, using the OpenBSD bcrypt protocol. Args: password (byte string or string): The secret password or pass phrase. It must be at most 72 bytes long. It must not contain the zero byte. Unicode strings will be encoded as UTF-8. cost (integer): The exponential factor that makes it slower to compute the hash. It must be in the range 4 to 31. A value of at least 12 is recommended. salt (byte string): Optional. Random byte string to thwarts dictionary and rainbow table attacks. It must be 16 bytes long. If not passed, a random value is generated. Return (byte string): The bcrypt hash Raises: ValueError: if password is longer than 72 bytes or if it contains the zero byte zutf-8rrrz#The password contains the zero byterrLNr-z!bcrypt salt must be 16 bytes longsOrpheanBeholderScryDoubtT$r:s$2a) rrr r!r rrr strrr)r#rr$rcost_encsalt_enchash_encs r*bcryptrs4x))H}}T!WWQZ  B&&>??? 8}}rG |## 4yyB<=== 4/JD Q QEd3t99??1--...HnT***HeCRCj))H H x '( 22r,ct|}t|dkrtdt|z|dddkrtdtjd}||}|stdt |d }d|cxkrd ksntd t|d }t|||}td }tj d|| }tj d|| } || krtddS)aVerify if the provided password matches the given bcrypt hash. Args: password (byte string or string): The secret password or pass phrase to test. It must be at most 72 bytes long. It must not contain the zero byte. Unicode strings will be encoded as UTF-8. bcrypt_hash (byte string, bytearray): The reference bcrypt hash the password needs to be checked against. Raises: ValueError: if the password does not match <z;Incorrect length of the bcrypt hash: %d bytes instead of 60Nrs$2a$zUnsupported prefixs@\$2a\$([0-9][0-9])\$([A-Za-z0-9./]{22,22})([A-Za-z0-9./]{31,31})zIncorrect bcrypt hash formatrrzIncorrect costr:r-) digest_bitsrErzIncorrect bcrypt hash)rr r!recompilematchrgrouprrrrrr") r# bcrypt_hashr2rrr$ bcrypt_hash2secretmac1mac2s r* bcrypt_checkrso +&&K ;2VY\]hYiYiijjj2A2'!!-... WXXA  A 97888 qwwqzz??D OOOOOOOO)*** !''!** % %D8T400L b ! !F ;3F E E E L L N ND ;3F F F F M M O OD t||0111|r,r,c" |d}|ddkrtd|ddkrtdt|zdzd}|z}d}d t |krXt|d|zdz|z|z} ||| z |dz }|d krtd t |kX|dkr dS fd t d |D} | S)aJDerive one or more keys from a master secret using a pseudorandom function in Counter Mode, as specified in `NIST SP 800-108r1 `_. Args: master (byte string): The secret value used by the KDF to derive the other keys. It must not be a password. The length on the secret must be consistent with the input expected by the :data:`prf` function. key_len (integer): The length in bytes of each derived key. prf (function): A pseudorandom function that takes two byte strings as parameters: the secret and an input. It returns another byte string. num_keys (integer): The number of keys to derive. Every key is :data:`key_len` bytes long. By default, only 1 key is derived. label (byte string): Optional description of the purpose of the derived keys. It must not contain zero bytes. context (byte string): Optional information pertaining to the protocol that uses the keys, such as the identity of the participants, nonces, session IDs, etc. It must not contain zero bytes. Return: - a byte string (if ``num_keys`` is not specified), or - a tuple of byte strings (if ``num_key`` is specified). NrrLrrzNull byte found in labelzNull byte found in contextrrr,lzOverflow in SP800 108 counterc*g|]}||zSr7r7rs r*rxz%SP800_108_Counter..s7>>>#cGm#$>>>r,r)rr!rr r) r|rwr8r~labelr key_len_encrr)inforrs ` @r*SP800_108_CounterrGs`B zz'b  3444||G""5666( 2Q 6::K8#J A B b''J  Q""U*W4w>L cc&$ Q z>><== = b''J  1}}(7(|>>>>>$Q G<<>>> r,)rN)r-rNN)rN)rr1)Nr,r,).rr@ functoolsrCrypto.Util.py3compatrrrrrr r Crypto.Hashr r r rrCrypto.Util.strxorr Crypto.RandomrCrypto.Util.numberrrrrCrypto.Util._raw_apirrrrrrr+rHobjectrJrrrrrrrrr7r,r*rsg2 666666666666666666:9999999999999%%%%%%******MMMMMMMMMM<<<<<<<<<<<<-,-E ,+,E("("("("VTTTTn]]]]]6]]]@: : : : |MMMM`08    ,3,3,3,3^*2*2*2Z;;;;;;r,