ó Û_e[c@`sddlmZmZmZddlZddlmZddljZ ddl m Z m Z ddlm Z e je jde jƒƒƒZe jƒZe jƒZe jƒZe jƒZe jƒZe jƒZe jƒZe j ƒZ!e j"ƒZ#e j$ƒZ%e j&ƒZ'e j(ƒZ)e j*ƒZ+e j,ƒZ-e j.ƒZ/e j0ƒZ1e j2ƒZ3e j4ƒZ5e j6ƒZ7e j8ƒZ9e j:ƒZ;e j<ƒZ=e j>ƒZ?e je jde j@ƒƒƒZAe jBƒZCe jDƒZEe jFƒZGe jHƒZIe jJƒZKe jLƒZMe jNƒZOe jPƒZQe jRƒZSe jTƒZUe je jde jVƒƒƒZWe jXƒZYe jZƒZ[e j\ƒZ]e j^ƒZ_e j`ƒZae jbƒZce jdƒZee jfƒZge jhƒZie jjƒZke'Zle)Zme+Zne-ZoeZpeZqdZrd ZsdZtd dZueud „Zvd„Zwd eud„Zxelemd„Zyd„Zzd„Z{d„Z|d„Z}d„Z~e~ZdS(i(tabsolute_importtdivisiontprint_functionN(t integer_types(tffitlib(tensureschar *iii?i@i icC`srt|dkddtjƒt|dkddtjƒt||d@dkddtjƒt|dkddtjƒt|t|kdjtƒdtjƒt|dd |>kdtjƒ|d |}td }t|d ||kdtjƒd ||d d }t|t|kdtjƒt|tj|kdtjƒt|||kddtjƒdS(NisInvalid block sizetraisingsInvalid parallelization factoris Cost factor must be a power of 2sCost factor must be at least 2sp*r is greater than {0}ii€ii is7Memory limit would be exceeded with the choosen n, r, p(Rtexct ValueErrort SCRYPT_PR_MAXtformatt UINT64_MAXtsystmaxsize(tntrtptmaxmemtBlentitVlen((s=/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_pwhash.pyt_check_memory_occupationŽs2          cC`sò|dkrd}nd}||dkrtd}|d|}x£tddƒD]}d||dkrOPqOqOWnq||d}x/tddƒD]}d||dkr’Pq’q’W|dd|}|d krÛd }n||}|||fS( s/Python implementation of libsodium's pickparamsi€ii iii?ii€iÿÿÿ?(trange(topslimittmemlimitRRtmaxntn_log2tmaxrp((s=/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_pwhash.pyt nacl_bindings_pick_scrypt_params¶s$      c C`stt|tƒdtƒtt|tƒdtƒtt|tƒdtƒtt|tƒdtƒtt|tƒdtƒt||||ƒtjd|ƒ}tj |t |ƒ|t |ƒ|||||ƒ }t|dkddt j ƒtj tjd|ƒ|ƒS(s1 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 Rs uint8_t[]is$Unexpected failure in key derivationschar *(Rt isinstanceRt TypeErrortbytesRRtnewRt%crypto_pwhash_scryptsalsa208sha256_lltlenRt RuntimeErrortbuffertcast( tpasswdtsaltRRRtdklenRtbuftret((s=/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_pwhash.pyR"Ôs&    cC`s\tjdtƒ}tj||t|ƒ||ƒ}t|dkddtjƒtj |ƒS(s 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 schar[]is&Unexpected failure in password hashingR( RR!tSCRYPT_STRBYTESRt&crypto_pwhash_scryptsalsa208sha256_strR#RRR$tstring(R'RRR*R+((s=/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_pwhash.pyR-s    cC`satt|ƒtdkddtjƒtj||t|ƒƒ}t|dkddtjƒtS(sÐ 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 isInvalid password hashRisWrong password( RR#R,RR Rt-crypto_pwhash_scryptsalsa208sha256_str_verifytInvalidkeyErrortTrue(t passwd_hashR'R+((s=/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_pwhash.pyR/$s     cC`si|tkr«|tkr3tjdjtƒƒ‚n'|tkrZtjdjtƒƒ‚n|tkrtjdjtƒƒ‚qe|tkretjdjtƒƒ‚qenº|tkrV|t krÞtjdjt ƒƒ‚n'|t krtjdjt ƒƒ‚n|t kr,tjdjt ƒƒ‚qe|t kretjdjt ƒƒ‚qentj dƒ‚dS(Ns#memlimit must be at least {0} bytess"memlimit must be at most {0} bytessopslimit must be at least {0}sopslimit must be at most {0}sUnsupported algorithm(tcrypto_pwhash_ALG_ARGON2I13t"crypto_pwhash_argon2i_MEMLIMIT_MINRR R t"crypto_pwhash_argon2i_MEMLIMIT_MAXt"crypto_pwhash_argon2i_OPSLIMIT_MINt"crypto_pwhash_argon2i_OPSLIMIT_MAXtcrypto_pwhash_ALG_ARGON2ID13t#crypto_pwhash_argon2id_MEMLIMIT_MINt#crypto_pwhash_argon2id_MEMLIMIT_MAXt#crypto_pwhash_argon2id_OPSLIMIT_MINt#crypto_pwhash_argon2id_OPSLIMIT_MAXR(RRtalg((s=/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_pwhash.pyt_check_argon2_limits_alg;s6                  c C`s€tt|tƒdtjƒtt|tƒdtjƒtt|tƒdtjƒtt|tƒdtjƒtt|tƒdtjƒt|ƒtkr¹tjdj tƒƒ‚n|t kràtjdj t ƒƒ‚n'|t krtjdj t ƒƒ‚nt |||ƒt jd|ƒ}tj|||t|ƒ||||ƒ}t|dkddtjƒt j||ƒS(sÝ 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 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 Rs#salt must be exactly {0} bytes longs+derived key must be at least {0} bytes longs*derived key must be at most {0} bytes longsunsigned char[]is$Unexpected failure in key derivation(RRRRRR R#tcrypto_pwhash_SALTBYTESR R tcrypto_pwhash_BYTES_MINtcrypto_pwhash_BYTES_MAXR>RR!Rt crypto_pwhashR$R%(toutlenR'R(RRR=toutbufR+((s=/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_pwhash.pytcrypto_pwhash_alg\s8         cC`sºtt|tƒdtƒtt|tƒdtƒtt|tƒdtƒt|||ƒtjddƒ}tj ||t |ƒ|||ƒ}t|dkddt j ƒtj |ƒS(s 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 Rschar[]i€is$Unexpected failure in key derivation(RRRRR R>RR!Rtcrypto_pwhash_str_algR#RR$R.(R'RRR=RDR+((s=/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_pwhash.pyRF”s cC`stt|tƒdtƒtt|tƒdtƒtt|ƒdkddtjƒtj||t|ƒƒ}t|dkddtj ƒt S(sæ int crypto_pwhash_str_verify(const char str[128], const char * const passwd, unsigned long long passwdlen); 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 Ris#Hash must be at most 127 bytes longisWrong password( RRR RR#RR Rtcrypto_pwhash_str_verifyR0R1(R2R'R+((s=/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_pwhash.pyRG¹s   i@iÿÿÿ?llÿÿÿÿi(€t __future__RRRR tsixRtnacl.exceptionst exceptionsRt nacl._sodiumRRRR.R&t,crypto_pwhash_scryptsalsa208sha256_strprefixt,crypto_pwhash_scryptsalsa208sha256_STRPREFIXt,crypto_pwhash_scryptsalsa208sha256_saltbytest,crypto_pwhash_scryptsalsa208sha256_SALTBYTESt+crypto_pwhash_scryptsalsa208sha256_strbytest+crypto_pwhash_scryptsalsa208sha256_STRBYTESt-crypto_pwhash_scryptsalsa208sha256_passwd_mint-crypto_pwhash_scryptsalsa208sha256_PASSWD_MINt-crypto_pwhash_scryptsalsa208sha256_passwd_maxt-crypto_pwhash_scryptsalsa208sha256_PASSWD_MAXt,crypto_pwhash_scryptsalsa208sha256_bytes_mint,crypto_pwhash_scryptsalsa208sha256_BYTES_MINt,crypto_pwhash_scryptsalsa208sha256_bytes_maxt,crypto_pwhash_scryptsalsa208sha256_BYTES_MAXt/crypto_pwhash_scryptsalsa208sha256_memlimit_mint/crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MINt/crypto_pwhash_scryptsalsa208sha256_memlimit_maxt/crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAXt/crypto_pwhash_scryptsalsa208sha256_opslimit_mint/crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MINt/crypto_pwhash_scryptsalsa208sha256_opslimit_maxt/crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAXt7crypto_pwhash_scryptsalsa208sha256_opslimit_interactivet7crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVEt7crypto_pwhash_scryptsalsa208sha256_memlimit_interactivet7crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVEt5crypto_pwhash_scryptsalsa208sha256_opslimit_sensitivet5crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVEt5crypto_pwhash_scryptsalsa208sha256_memlimit_sensitivet5crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVEtcrypto_pwhash_alg_argon2i13R3tcrypto_pwhash_alg_argon2id13R8tcrypto_pwhash_alg_defaulttcrypto_pwhash_ALG_DEFAULTtcrypto_pwhash_saltbytesR?tcrypto_pwhash_strbytestcrypto_pwhash_STRBYTEStcrypto_pwhash_passwd_mintcrypto_pwhash_PASSWD_MINtcrypto_pwhash_passwd_maxtcrypto_pwhash_PASSWD_MAXtcrypto_pwhash_bytes_minR@tcrypto_pwhash_bytes_maxRAtcrypto_pwhash_argon2i_strprefixtcrypto_pwhash_argon2i_STRPREFIXt"crypto_pwhash_argon2i_memlimit_minR4t"crypto_pwhash_argon2i_memlimit_maxR5t"crypto_pwhash_argon2i_opslimit_minR6t"crypto_pwhash_argon2i_opslimit_maxR7t*crypto_pwhash_argon2i_opslimit_interactivet*crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVEt*crypto_pwhash_argon2i_memlimit_interactivet*crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVEt'crypto_pwhash_argon2i_opslimit_moderatet'crypto_pwhash_argon2i_OPSLIMIT_MODERATEt'crypto_pwhash_argon2i_memlimit_moderatet'crypto_pwhash_argon2i_MEMLIMIT_MODERATEt(crypto_pwhash_argon2i_opslimit_sensitivet(crypto_pwhash_argon2i_OPSLIMIT_SENSITIVEt(crypto_pwhash_argon2i_memlimit_sensitivet(crypto_pwhash_argon2i_MEMLIMIT_SENSITIVEt crypto_pwhash_argon2id_strprefixt crypto_pwhash_argon2id_STRPREFIXt#crypto_pwhash_argon2id_memlimit_minR9t#crypto_pwhash_argon2id_memlimit_maxR:t#crypto_pwhash_argon2id_opslimit_minR;t#crypto_pwhash_argon2id_opslimit_maxR<t+crypto_pwhash_argon2id_opslimit_interactivet+crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVEt+crypto_pwhash_argon2id_memlimit_interactivet+crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVEt(crypto_pwhash_argon2id_opslimit_moderatet(crypto_pwhash_argon2id_OPSLIMIT_MODERATEt(crypto_pwhash_argon2id_memlimit_moderatet(crypto_pwhash_argon2id_MEMLIMIT_MODERATEt)crypto_pwhash_argon2id_opslimit_sensitivet)crypto_pwhash_argon2id_OPSLIMIT_SENSITIVEt)crypto_pwhash_argon2id_memlimit_sensitivet)crypto_pwhash_argon2id_MEMLIMIT_SENSITIVEtSCRYPT_OPSLIMIT_INTERACTIVEtSCRYPT_MEMLIMIT_INTERACTIVEtSCRYPT_OPSLIMIT_SENSITIVEtSCRYPT_MEMLIMIT_SENSITIVEtSCRYPT_SALTBYTESR,R tLOG2_UINT64_MAXR tSCRYPT_MAX_MEMRRR"R-R/R>RERFRGt crypto_pwhash_argon2i_str_verify(((s=/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_pwhash.pyts˜                                              (  0   ! 8 %