ó 9(Zc@`sdZddlmZmZmZmZddlZddlZddlm Z m Z yŠddl m Z m Z mZmZmZejƒdkrŸeƒ‚nyddlmZd „ZWn eefk rÞeƒ‚nXWn eefk rd „ZnXd „ZdS( uN Function for calculating the modular inverse. Exports the following items: - inverse_mod() Source code is derived from http://webpages.charter.net/curryfans/peter/downloads.html, but has been heavily modified to fit into this projects lint settings. The original project license is listed below: Copyright (c) 2014 Peter Pearson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. i(tunicode_literalstdivisiontabsolute_importtprint_functionNi(t int_to_bytestint_from_bytes(tbuffer_from_bytestbytes_from_buffertFFIEngineErrortLibraryNotFoundErrortnulluPyPy(t libcryptocC`sttjƒ}tt|ƒƒ}tt|ƒƒ}t|ƒ}tj|t|ƒtƒƒ}|dkrytj|dƒnt|ƒ}tj|t|ƒtƒƒ}|dkrÂtj|dƒntj tƒ|||ƒ} tj | ƒ} t t j | dƒƒ} t| ƒ} tj| | ƒt| | ƒ} t| ƒ}tj|ƒtj|ƒtj| ƒtj|ƒ|S(u× Compute the modular inverse of a (mod p) :param a: An integer :param p: An integer :return: An integer iii(R t BN_CTX_newRtabsRt BN_bin2bntlenR tBN_set_negativetBN_mod_inverset BN_num_bitstinttmathtceilt BN_bn2binRRtBN_freet BN_CTX_free(tatptctxta_bytestp_bytesta_bufta_bntp_buftp_bntr_bnt r_len_bitstr_lentr_buftr_bytestresult((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_int.pyt inverse_mod:s.           c C`sÒ|dks||kr%||}n||}}d\}}}}x]|dkr£t||ƒ|f\}}}||||||||f\}}}}qGW|dks¶t‚|dkrÆ|S||SdS(u· Compute the modular inverse of a (mod p) :param a: An integer :param p: An integer :return: An integer iiN(iiii(tdivmodtAssertionError( RRtctdtuctvctudtvdtq((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_int.pyR(ks  2 cC`s'x t|ƒ|kr"d|}qW|S(u  Ensure a byte string representing a positive integer is a specific width (in bytes) :param bytes_: The integer byte string :param width: The desired width as an integer :return: A byte string of the width specified t(R(tbytes_twidth((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_int.pyt fill_widthŽs(t__doc__t __future__RRRRRtplatformtutilRRt_ffiRRRR R tpython_implementationtEnvironmentErrort_perf._big_num_ctypesR R(t ImportErrorR5(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_int.pyt s "  (   + #