3 L]E@sddlmZmZmZddlZddlZddlmZej j Z ej j Z ej jZej jZej jZej jZej jZej jZej jZej jZej jZej j Z!Gddde"Z#dd dZ$dS))absolute_importdivisionprint_functionN)bytes_as_stringc@sxeZdZdZeZeZeZ e Z dedddfddZ e ddZe ddZe d d Zd d Zd dZddZddZdS)blake2bzK :py:mod:`hashlib` API compatible blake2b algorithm implementation cCs*t||||d|_||_|r&|j|dS)ac :py:class:`.blake2b` algorithm initializer :param data: :type data: bytes :param int digest_size: the requested digest size; must be at most :py:attr:`.MAX_DIGEST_SIZE`; the default digest size is :py:data:`.BYTES` :param key: the key to be set for keyed MAC/PRF usage; if set, the key must be at most :py:data:`.KEYBYTES_MAX` long :type key: bytes :param salt: an initialization salt at most :py:attr:`.SALT_SIZE` long; it will be zero-padded if needed :type salt: bytes :param person: a personalization string at most :py:attr:`.PERSONAL_SIZE` long; it will be zero-padded if needed :type person: bytes )keysaltperson digest_sizeN) _b2b_init_state _digest_sizeupdate)selfdatar rr r r0/tmp/pip-install-wfra5znf/pynacl/nacl/hashlib.py__init__.s  zblake2b.__init__cCs|jS)N)r)rrrrr Lszblake2b.digest_sizecCsdS)Nr)rrrr block_sizePszblake2b.block_sizecCsdS)Nrr)rrrrnameTsz blake2b.namecCst|j|dS)N) _b2b_updater )rrrrrrXszblake2b.updatecCstjj|j}t||jS)N)naclbindings%crypto_generichash_blake2b_state_copyr _b2b_finalr )r_strrrdigest[szblake2b.digestcCsttj|jS)N)rbinasciihexlifyr)rrrr hexdigest_szblake2b.hexdigestcCs$t||jd}t|j}||_|S)N)r )typer _b2b_copyr )rZ_cprrrrcopybs z blake2b.copyN)__name__ __module__ __qualname____doc__BYTESMAX_DIGEST_SIZE KEYBYTES_MAX MAX_KEY_SIZE PERSONALBYTES PERSON_SIZE SALTBYTES SALT_SIZErpropertyr rrrrr!r$rrrrr%s   r@c Cstjj|||||||dS)z Derive a cryptographic key using the scrypt KDF. Implements the same signature as the ``hashlib.scrypt`` implemented in cpython version 3.6 )maxmemdklen)rrZ%crypto_pwhash_scryptsalsa208sha256_ll)passwordr nrpr9r:rrrscryptisr?)r2r@r5r6rAr8)% __future__rrrrZ nacl.bindingsrZ nacl.utilsrrZcrypto_generichash_BYTESr)Zcrypto_generichash_BYTES_MINZ BYTES_MINZcrypto_generichash_BYTES_MAXZ BYTES_MAXZcrypto_generichash_KEYBYTESZKEYBYTESZcrypto_generichash_KEYBYTES_MINZ KEYBYTES_MINZcrypto_generichash_KEYBYTES_MAXr+Zcrypto_generichash_SALTBYTESr/Z crypto_generichash_PERSONALBYTESr-Zcrypto_generichash_blake2b_initr Z crypto_generichash_blake2b_finalrrr#Z!crypto_generichash_blake2b_updaterobjectrr?rrrrs$ D