: 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!ddZ"ddZ# G d de$ Z%ddZ&d dZ'd Z(d Z)d Z*d!dZ+d Z,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 }||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
`_.
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 newdigest_size TypeErrorlen
ValueErrorr digest)passwordsaltdkLencounthashAlgopHashr" is u/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Protocol/KDF.pyPBKDF1r+ 7 s : x HLL$''E
Fv~~TW]]^^^
4yyA~~G#d))STTT
a
* * %,,..))<<>>&5&!! c @
t t | }rrt d t st d sfd fd
d}d}t | |k rp |t j d| z gd z |t t
fd
t | D z
}|dz
}t | |k pnd}d}t | |k rt j d }|
|t j d| z } || | | z
}|dz
}t | |k |d| S )a Derive 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_assistc T t j | | S N)r
r r" )pshmac_hash_modules r* zPBKDF2..