ffwhddlZddlmZmZddlmZmZmZmZm Z m Z m Z m Z m Z ddlmZdZejdkr eded eZd ed Zeed r ed ed dkrddlmZmZmZmZGddeZdZn ddlmZdZGddeZeZ GddeZ!dS)N)tobytes is_native_int) backendload_libget_raw_buffer get_c_string null_pointercreate_string_bufferc_ulongc_size_t c_uint8_ptr) IntegerBaseaY typedef unsigned long UNIX_ULONG; typedef struct { int a; int b; void *c; } MPZ; typedef MPZ mpz_t[1]; typedef UNIX_ULONG mp_bitcnt_t; void __gmpz_init (mpz_t x); void __gmpz_init_set (mpz_t rop, const mpz_t op); void __gmpz_init_set_ui (mpz_t rop, UNIX_ULONG op); UNIX_ULONG __gmpz_get_ui (const mpz_t op); void __gmpz_set (mpz_t rop, const mpz_t op); void __gmpz_set_ui (mpz_t rop, UNIX_ULONG op); void __gmpz_add (mpz_t rop, const mpz_t op1, const mpz_t op2); void __gmpz_add_ui (mpz_t rop, const mpz_t op1, UNIX_ULONG op2); void __gmpz_sub_ui (mpz_t rop, const mpz_t op1, UNIX_ULONG op2); void __gmpz_addmul (mpz_t rop, const mpz_t op1, const mpz_t op2); void __gmpz_addmul_ui (mpz_t rop, const mpz_t op1, UNIX_ULONG op2); void __gmpz_submul_ui (mpz_t rop, const mpz_t op1, UNIX_ULONG op2); void __gmpz_import (mpz_t rop, size_t count, int order, size_t size, int endian, size_t nails, const void *op); void * __gmpz_export (void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, const mpz_t op); size_t __gmpz_sizeinbase (const mpz_t op, int base); void __gmpz_sub (mpz_t rop, const mpz_t op1, const mpz_t op2); void __gmpz_mul (mpz_t rop, const mpz_t op1, const mpz_t op2); void __gmpz_mul_ui (mpz_t rop, const mpz_t op1, UNIX_ULONG op2); int __gmpz_cmp (const mpz_t op1, const mpz_t op2); void __gmpz_powm (mpz_t rop, const mpz_t base, const mpz_t exp, const mpz_t mod); void __gmpz_powm_ui (mpz_t rop, const mpz_t base, UNIX_ULONG exp, const mpz_t mod); void __gmpz_pow_ui (mpz_t rop, const mpz_t base, UNIX_ULONG exp); void __gmpz_sqrt(mpz_t rop, const mpz_t op); void __gmpz_mod (mpz_t r, const mpz_t n, const mpz_t d); void __gmpz_neg (mpz_t rop, const mpz_t op); void __gmpz_abs (mpz_t rop, const mpz_t op); void __gmpz_and (mpz_t rop, const mpz_t op1, const mpz_t op2); void __gmpz_ior (mpz_t rop, const mpz_t op1, const mpz_t op2); void __gmpz_clear (mpz_t x); void __gmpz_tdiv_q_2exp (mpz_t q, const mpz_t n, mp_bitcnt_t b); void __gmpz_fdiv_q (mpz_t q, const mpz_t n, const mpz_t d); void __gmpz_mul_2exp (mpz_t rop, const mpz_t op1, mp_bitcnt_t op2); int __gmpz_tstbit (const mpz_t op, mp_bitcnt_t bit_index); int __gmpz_perfect_square_p (const mpz_t op); int __gmpz_jacobi (const mpz_t a, const mpz_t b); void __gmpz_gcd (mpz_t rop, const mpz_t op1, const mpz_t op2); UNIX_ULONG __gmpz_gcd_ui (mpz_t rop, const mpz_t op1, UNIX_ULONG op2); void __gmpz_lcm (mpz_t rop, const mpz_t op1, const mpz_t op2); int __gmpz_invert (mpz_t rop, const mpz_t op1, const mpz_t op2); int __gmpz_divisible_p (const mpz_t n, const mpz_t d); int __gmpz_divisible_ui_p (const mpz_t n, UNIX_ULONG d); win32zNot using GMP on Windowsgmp)libraryapi__mpir_versionzMPIR library detectedrctypes) Structurec_intc_void_pbyrefc$eZdZdefdefdefgZdS)_MPZ _mp_alloc_mp_size_mp_dN)__name__ __module__ __qualname__rr_fields_y/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Math/_IntegerGMP.pyrrps- %('h')r$rc8ttSN)rrr#r$r%new_mpzr(usTVV}}r$)ffic*tjdS)NzMPZ*)r)newr#r$r%r(r(|swvr$ceZdZdZdS)_GMPc|drd|ddz}n5|drd|ddz}ntd|ztt|}t ||||S)Nmpz___gmpz_gmp___gmp_zAttribute %s is invalid) startswithAttributeErrorgetattrlibsetattr)selfname func_namefuncs r% __getattr__z_GMP.__getattr__s ??6 " " C!DH,II __V $ $ C 48+II !:T!ABB BsI&&dD!!! r$N)rr r!r=r#r$r%r-r-s#     r$r-ceZdZdZeZeeeddZ dZ dZ dZ dZ dZd8d Zed9d Zd Zd ZdZdZdZdZdZdZeZdZdZdZdZdZdZ d:dZ!d:dZ"dZ#d:dZ$dZ%d Z&d!Z'd"Z(d#Z)d$Z*d%Z+d&Z,d'Z-d(Z.d)Z/d*Z0d+Z1d,Z2d-Z3d.Z4d/Z5d0Z6d1Z7d2Z8d3Z9d4Z:d5Z;ed6Z>r$ct|tst|sdS|tj|dkS)NTrrrs r%__ne__zIntegerGMP.__ne__AsE4,,  d0C0C 4%%dlD99Q>>r$cJ|tj|dkSNrrrHrZrs r%__lt__zIntegerGMP.__lt__F%%dlD99A==r$cJ|tj|dkSrrrs r%__le__zIntegerGMP.__le__I%%dlD99Q>>r$cJ|tj|dkSrrrs r%__gt__zIntegerGMP.__gt__Lrr$cJ|tj|dkSrrrs r%__ge__zIntegerGMP.__ge__Orr$cTt|j|jdkSrrHrZrCr[rds r% __nonzero__zIntegerGMP.__nonzero__Rs ||DK)9::a??r$cTt|j|jdkSrrrds r% is_negativezIntegerGMP.is_negativeVs ||DK)9::Q>>r$ctd}t|ts( t|}n#t$r tcYSwxYwt|j|j|j|Sr)r?rErRNotImplementedrHrNrCr9rrs r%__add__zIntegerGMP.__add__ZA$ ++ & &!$''& & & &%%%% & V][[ " " " 6A  A ctd}t|ts( t|}n#t$r tcYSwxYwt|j|j|j|Sr)r?rErRrrHmpz_subrCrs r%__sub__zIntegerGMP.__sub__frrctd}t|ts( t|}n#t$r tcYSwxYwt|j|j|j|Sr)r?rErRrrHmpz_mulrCrs r%__mul__zIntegerGMP.__mul__rrrc2t|tst|}t|j|jdkrt dtd}t|j|j|j|S)NrDivision by zero)rEr?rHrZrCr[ZeroDivisionError mpz_fdiv_q)r9divisorrs r% __floordiv__zIntegerGMP.__floordiv__~s':.. * ))G <<( * *-. / /#$677 7A    ( ( ( r$c`t|tst|}t|j|j}|dkrt d|dkrtdtd}t|j|j|j|SNrrModulus must be positive rEr?rHrZrCr[rrGmpz_mod)r9rcomprs r%__mod__zIntegerGMP.__mod__s':.. * ))G||GN ,.. 199#$677 7 !88788 8A V][^ % % % r$Nc $|l|dkrtd|dkrtdt|j|jt t |n!t |tst|}|std| rtdt|rf|dkrtd|dkr;t |j|jt ||j|St|}n#| rtdt |j|j|j|j|S)NrzExponent must not be negativezExponent is too bigrr) rGrH mpz_pow_uirCr r^rEr?rrr mpz_powm_uimpz_powm)r9exponentmoduluss r% inplace_powzIntegerGMP.inplace_pows ?!|| !@AAA#~~ !6777 OODK K#CMM22     gz22 .$W-- <'(:;;;""$$ = !;<<<X&& Ba<<$%DEEEe##$$T[%)[%,X%6%6%,^555 K%h//%%'' B !@AAA MM$++"/!. * * * r$cLt|}|||Sr')r?r)r9rrrs r%__pow__zIntegerGMP.__pow__s%D!!!!(G444r$cntd}t|j|j|Sr)r?rHmpz_absrC)r9rs r%__abs__zIntegerGMP.__abs__s*A V]DK000 r$cL|J|dkrtdtd}t|j|jnW|dkrtdt |}t|t ||z|}|S)zGReturn the largest Integer that does not exceed the square rootNrzSquare root of negative valuer)rGr?rHmpz_sqrtrCr^_tonelli_shanksr9rrs r%sqrtzIntegerGMP.sqrts ?axx !@AAA]]F MM&-+ ' ' ' '!|| !;<<<'llG 4 4SYY5H' R RSSF r$ct|rd|cxkrdkr8nn5t|j|jt ||Sd|cxkrdkr9nn6t|j|jt | |St |}t|j|j|j|SNrr)rrH mpz_add_uirCr mpz_sub_uir?rNrs r%__iadd__zIntegerGMP.__iadd__    $D    5      $ ' ///     q      $ '000 d##D T[[[ " " " r$ct|rd|cxkrdkr8nn5t|j|jt ||Sd|cxkrdkr9nn6t|j|jt | |St |}t|j|j|j|Sr)rrHrrCr rr?rrs r%__isub__zIntegerGMP.__isub__rr$ct|rd|cxkrdkr8nn5t|j|jt ||Sd|cxkrdkr^nn[t|j|jt | t|j|j|St |}t|j|j|j|Sr)rrH mpz_mul_uirCr rPr?rrs r%__imul__zIntegerGMP.__imul__s    $D    5      $ ' ///     q      $ '000 T[$+666 d##D T[[[ " " " r$cBt|tst|}t|j|j}|dkrt d|dkrtdt|j|j|j|Srr)r9rrs r%__imod__zIntegerGMP.__imod__s':.. * ))G||GN#/11 199#$677 7 !88788 8 T[[^ % % % r$ctd}t|tst|}t|j|j|j|Sr)r?rErHmpz_andrCrs r%__and__zIntegerGMP.__and__!WA$ ++ $d##D V][[ " " " r$ctd}t|tst|}t|j|j|j|Sr)r?rErHmpz_iorrCrs r%__or__zIntegerGMP.__or__*rr$c td}|dkrtd|dkr |dkrdSdSt|j|jt t ||SNrznegative shift countr)r?rGrHr]rCr r^r9posrs r% __rshift__zIntegerGMP.__rshift__3szA 77344 4 ;;axxrq V]![$SXX.. 0 0 0 r$c |dkrtd|dkr |dkrdSdSt|j|jt t ||Sr)rGrHr]rCr r^r9rs r% __irshift__zIntegerGMP.__irshift__Aso 77344 4 ;;axxrq T[![$SXX.. 0 0 0 r$c td}d|cxkrdksntdt|j|jt t ||SNrrzIncorrect shift count)r?rGrHrMrCr r^rs r% __lshift__zIntegerGMP.__lshift__NstAC%455 5 &-+!#c((++ - - - r$c d|cxkrdksntdt|j|jt t ||Sr)rGrHrMrCr r^rs r% __ilshift__zIntegerGMP.__ilshift__WsiC%455 5 $++!#c((++ - - - r$c |dkrtd|dkrtd|dkrdStt|jt t |S)zPReturn True if the n-th bit is set to 1. Bit 0 is the least significant.rz)no bit representation for negative valuesznegative bit countr)rGboolrH mpz_tstbitrCr r^)r9ns r%get_bitzIntegerGMP.get_bit_sw !88HII I q55122 2 u991DOODK$+CFFOO5566 6r$cJt|jddkS)NrrrHrrCrds r%is_oddzIntegerGMP.is_oddmt{A..!33r$cJt|jddkSrrrds r%is_evenzIntegerGMP.is_evenprr$cl|dkrtdt|jdS)z=Return the minimum number of bits that can encode the number.rrprq)rGrHrwrCrds r% size_in_bitszIntegerGMP.size_in_bitsss4 !88MNN N""4;222r$c<|dz dzdzS)z>Return the minimum number of bytes that can encode the number.rrs)rrds r% size_in_byteszIntegerGMP.size_in_byteszs#!!##a'A-11r$cHt|jdkSr)rHmpz_perfect_square_prCrds r%is_perfect_squarezIntegerGMP.is_perfect_square~s((55::r$cFt|r]d|cxkrdkrAnn>t|jt |rt ddSt |}t|j|jrt ddS)z3Raise an exception if the small prime is a divisor.rrzThe value is compositeN)rrHmpz_divisible_ui_prCr rGr?mpz_divisible_p)r9 small_primes r%fail_if_divisible_byzIntegerGMP.fail_if_divisible_bys  % % 2;&&&&&&&&&**4;+2;+?+?AA?$%=>>>$[11K    + 2 4 4 7566 6 7 7r$ct|tst|}t|rd|cxkrdkr8nn5t|j|jt ||Sd|cxkrdkr9nn6t|j|jt | |St|}t|j|j|j|S)z/Increment the number by the product of a and b.rrr) rEr?rrH mpz_addmul_uirCr mpz_submul_ui mpz_addmul)r9abs r%multiply_accumulatezIntegerGMP.multiply_accumulates!Z(( 1 A    1}}}}u}}}}}""4;#$8#*1::/// ~~~~A~~~~~""4;#$8#*A2;;000 1 A   " " " r$ct|tst|}t|j|j|S)z'Set the Integer to have the given value)rEr?rHmpz_setrC)r9sources r%setzIntegerGMP.setsG&*-- (''F T[] $ $ $ r$cdt|tst|}t|j|j}|dkrt d|dkrtdt|j|j|j}|std|S)zCompute the inverse of this number in the ring of modulo integers. Raise an exception if no inverse exists. rzModulus cannot be zerorz No inverse value can be computed) rEr?rHrZrCr[rrG mpz_invert)r9rrrs r%inplace_inversezIntegerGMP.inplace_inverses':.. * ))G||GN ,.. 199#$<== = !88788 8!%!(11 A?@@ @ r$cNt|}|||Sr')r?rrs r%inversezIntegerGMP.inverses(D!!w''' r$c@td}t|rTd|cxkrdkr8nn5t|j|jt ||St|}t|j|j|j|S)zUCompute the greatest common denominator between this number and another term.ri)r?rrH mpz_gcd_uirCr mpz_gcdrs r%gcdzIntegerGMP.gcdsA    $4% $ ' /// d##D V]DK=== r$ctd}t|tst|}t|j|j|j|S)zQCompute the least common multiplier between this number and another term.r)r?rErHmpz_lcmrCrs r%lcmzIntegerGMP.lcmsOA$ ++ $d##D V]DK=== r$c.t|tst|}t|tst|}|dks|rtdt|j|jS)zCompute the Jacobi symbolrz,n must be positive odd for the Jacobi symbol)rEr?rrGrH mpz_jacobirC)r rs r% jacobi_symbolzIntegerGMP.jacobi_symbolsz!Z(( 1 A!Z(( 1 A 66QYY[[6KLL Lqx222r$c |j&|jrt|jd|_dS#t$rYdSwxYwr')rCrDrHrOr5rds r%__del__zIntegerGMP.__del__s[ {&$0NN4;///DKKK    DD s48 AA)rrn)rnr')>rr r!__doc__r(r[rHmpz_init_set_uir rXrarerhrkrmr staticmethodrrrrrrrrr__bool__rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr!r#r#r$r%r?r?s}--'))Kggajj111'&'&'&V&)))0000d\@... ??? ??? >>>???>>>???@@@H???               %%%%N5555 $$$&          6 6 6444444333222;;; 7 7 7,0    3 3\ 3     r$r?)"sysCrypto.Util.py3compatrrCrypto.Util._raw_apirrrrr r r r r _IntegerBasergmp_defsplatform ImportErrorr7implementationhasattrrrrrrrr(r)objectr-rHr?r#r$r%r2s8> 88888888BBBBBBBBBBBBBBBBBBBBBB &%%%%%5 n<7 +0 1 11huh"733 73 !!/ +- . .. %H$$888888888888)))))y)))  )(((((     6    tvvh h h h h h h h h h r$