U af @sddlmZmZmZmZddlZddlZddlZddlm Z m Z ddl m Z ddl mZmZmZejdkrpeZndd Zd gZd d ZdS) )unicode_literalsdivisionabsolute_importprint_functionN)int_from_bytes int_to_bytes)pretty_message) type_namebyte_cls int_types)cCs t|gS)N)bytes)numrA/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/oscrypto/_pkcs12.pychr_clssr pkcs12_kdfcCslt|tsttdt|t|ts8ttdt|t|tsTttdt||dkrnttdt|t|tsttdt||dkrttdt||tdd d d d d gkrttdt||tdddgkrttdt|| d dd}t t |}ddddddd|}|dkr6d} nd} t || } d} |dkr| tttt|| } t| | kr| |7} qr| d| } d} |dkr| tttt|| }t| |kr| |7} q| d|} | | }ttt||}d ||}td|dD]:}|| |}td|dD]}||}qF||krd}t|| kr||7}qht|d| d}tdt|| D]t}|| }|d| }|||}tt||}t|}|| kr||| d!}|d||||d!}q|d|}t||}|d||d||||d!}q"|d|S)"a KDF from RFC7292 appendix b.2 - https://tools.ietf.org/html/rfc7292#page-19 :param hash_algorithm: The string name of the hash algorithm to use: "md5", "sha1", "sha224", "sha256", "sha384", "sha512" :param password: A byte string of the password to use an input to the KDF :param salt: A cryptographic random byte string :param iterations: The numbers of iterations to use when deriving the key :param key_length: The length of the desired key in bytes :param id_: The ID of the usage - 1 for key, 2 for iv, 3 for mac :return: The derived key as a byte string z@ password must be a byte string, not %s z< salt must be a byte string, not %s z? iterations must be an integer, not %s rzC iterations must be greater than 0 - is %s z? key_length must be an integer, not %s zC key_length must be greater than 0 - is %s md5sha1sha224sha256sha384sha512z hash_algorithm must be one of "md5", "sha1", "sha224", "sha256", "sha384", "sha512", not %s r z< id_ must be one of 1, 2, 3, not %s zutf-8zutf-16bes 0@)rrrrrr)rrrN) isinstancer TypeErrorr r r ValueErrorreprsetdecodeencodegetattrhashlibrintmathceilfloatlenrangedigestrrmin)Zhash_algorithmpasswordZsaltZ iterationsZ key_lengthZid_Zutf16_passwordalgouvdsZs_lenpZp_lenicarZa2_bZnum2startendZi_num2Zi_num2_lbeginZto_copyrrrrs                      ,) __future__rrrrsysr,r.Z_asn1rr_errorsr _typesr r r version_infochrr__all__rrrrrs