XylotrechusZ
�
��Fh)W � �: � d dl Z d dlZd dlmZ d dlmZmZmZmZm Z m
Z
mZ d dlm
Z
mZmZmZmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZmZmZmZ ed d
� � Z edd� � Z!dd�Z"dd�Z# G d� de$� � Z%dd�Z&d d�Z'd� Z(d� Z)d� Z*d!d�Z+d� Z,d"d�Z-dS )#� N)�reduce)�tobytes�bord�_copy_bytes�
iter_range�tostr�bchr�bstr)�SHA1�SHA256�HMAC�CMAC�BLAKE2s)�strxor)�get_random_bytes)�size�
long_to_bytes�
bytes_to_long)�load_pycryptodome_raw_lib�create_string_buffer�get_raw_buffer�c_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 }||k rt d|z � � �t |� � dk rt
dt |� � z � � �t |dz
� � D ])}|� |� � � � � }�*|� � � d|� S )aM Derive 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
<https://www.ietf.org/rfc/rfc2898.txt>`_.
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 r �new�digest_size� TypeError�len�
ValueErrorr �digest)�password�salt�dkLen�count�hashAlgo�pHashr"