
    il                        S SK r S SKrS SKJr  S SKJrJrJrJrJ	r	  SSK
Jr  Sr\ R                  S:X  a  \" S5      e\" S	\5      rS	\S
.r\" \S5      (       a  \" S5      e " S S\5      r\" 5       r\S   S:X  a,  S SKJrJrJrJr   " S S\5      rS r\\R8                  l        O	S SKJr  S rS\R>                  " S5      -  r  " S S\5      r!g)    N)is_native_int)backendload_libc_ulongc_size_tc_uint8_ptr   )IntegerBasea  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);

        size_t __gmpz_size (const mpz_t op);
        UNIX_ULONG __gmpz_getlimbn (const mpz_t op, size_t n);
        win32zNot using GMP on Windowsgmp)libraryapi__mpir_versionzMPIR library detectedc                       \ rS rSrS rSrg)_GMPn   c                     UR                  S5      (       a	  SUSS  -   nO-UR                  S5      (       a	  SUSS  -   nO[        SU-  5      e[        [        U5      n[	        XU5        U$ )Nmpz___gmpz_   gmp___gmp_zAttribute %s is invalid)
startswithAttributeErrorgetattrlibsetattr)selfname	func_namefuncs       R/var/www/html/trading/venv/lib/python3.13/site-packages/Crypto/Math/_IntegerGMP.py__getattr___GMP.__getattr__p   sl    ??6""!DH,I__V$$ 48+I !:T!ABBsI&D!     N)__name__
__module____qualname____firstlineno__r#   __static_attributes__r&   r%   r"   r   r   n   s    	r%   r   r   ctypes)	Structurec_intc_void_pbyrefc                   *    \ rS rSrS\4S\4S\4/rSrg)_MPZ   	_mp_alloc_mp_size_mp_dr&   N)r'   r(   r)   r*   r.   r/   _fields_r+   r&   r%   r"   r2   r2      s!     %('h')r%   r2   c                  (    [        [        5       5      $ N)r0   r2   r&   r%   r"   new_mpzr:      s    TV}r%   )ffic                  .    [         R                  " S5      $ )NzMPZ*)r;   newr&   r%   r"   r:   r:      s    wwvr%      Pc                      \ rS rSrSr\" 5       r\R                  \\	" S5      5        S r
S rS rS rS rS	 rS:S
 jr\S;S j5       rS rS rS rS rS rS rS rS r\rS rS rS rS rS r S r!S<S jr"S<S jr#S r$S<S jr%S r&S  r'S! r(S" r)S# r*S$ r+S% r,S& r-S' r.S( r/S) r0S* r1S+ r2S, r3S- r4S. r5S/ r6S0 r7S1 r8S2 r9S3 r:S4 r;S5 r<\S6 5       r=\S7 5       r>S8 r?S9r@g)=
IntegerGMP   z#A fast, arbitrary precision integerr   c           	         [        5       U l        SU l        [        U[        5      (       a  [        S5      e[        U5      (       GaE  [        R                  U R                  5        SU l        US:X  a  g[        5       n[        R                  U5         US:  n[        U5      nUR                  5       S-
  S-  S-   nUS:  a  US-
  n[        R                  U[        SXES-  -	  -  5      5        [        R                  X"[        US-  5      5        [        R                  U R                  U R                  U5        US:  a  M  [        R                  U5        U(       d+  [        R!                  U R                  U R                  5        gg[        U["        5      (       a2  [        R%                  U R                  UR                  5        SU l        g[&        e! [        R                  U5        f = f)	z*Initialize the integer to the given value.Fz-A floating point type is not a natural numberTr   Nr	           )r:   _mpz_p_initialized
isinstancefloat
ValueErrorr   _gmpmpz_initabs
bit_length
mpz_set_uir   mpz_mul_2expmpz_add	mpz_clearmpz_negrA   mpz_init_setNotImplementedError)r   valuetmppositivereduceslotss         r"   __init__IntegerGMP.__init__   s    i!eU##LMMMM$++& $Dz)CMM#$ A:U**,q0R7!;ai!AIEOOC$+J&RZ:P,Q$RT%%c
0CDLLdkk3? ai s#T[[$++6  z**dkk5<<8 $D%% s#s   B.G G1c                     [        5       n[        R                  XR                  5         SnSn[        R	                  XR
                  5      S:w  ak  [        R                  U5      S-  nX$US-  -  -  n[        R                  X[        S5      5        US-   n[        R	                  XR
                  5      S:w  a  Mk  [        R                  U5        U S:  a  U* n[        U5      $ ! [        R                  U5        f = f)Nr   rE   rD   r	   )r:   rK   rT   rF   mpz_cmp_zero_mpz_p
mpz_get_uimpz_tdiv_q_2expr   rR   int)r   rW   rV   slotlsbs        r"   __int__IntegerGMP.__int__   s    i#{{+		 ED,,s$4$45:ooc*Z7++$$Swr{;ax	 ,,s$4$45: NN3!8FE5z	 NN3s   BC& &C=c                 *    [        [        U 5      5      $ r9   )strrb   r   s    r"   __str__IntegerGMP.__str__       3t9~r%   c                     S[        U 5      -  $ )NzInteger(%s))rh   ri   s    r"   __repr__IntegerGMP.__repr__   s    s4y((r%   c                 *    [        [        U 5      5      $ r9   )hexrb   ri   s    r"   __hex__IntegerGMP.__hex__   rl   r%   c                     [        U 5      $ r9   )rb   ri   s    r"   	__index__IntegerGMP.__index__   s    4yr%   c                    U S:  a  [        S5      e[        R                  U R                  5      n[        S:X  a  Sn[        SX1S-   S-  5      nO*[        S:X  a  S	n[        SX1S
-   S-  5      nO[        S5      e[        U5       Vs/ s H(  n[        R                  U R                  X5-
  S-
  5      PM*     nn[        R                  " SXC-  -   /UQ76 n[        U5      U-
  nUS:X  a  UR                  S5      nO1US:  a  USU SU-  :w  a  [        S5      eXxS nOUS:  a	  SU* -  U-   nUS:X  a	  USSS2   nOUS:X  a  O[        S5      e[        U5      S:X  a  SnU$ s  snf )a2  Convert the number into a byte string.

This method encodes the number in network order and prepends
as many zero bytes as required. It only works for non-negative
values.

:Parameters:
  block_size : integer
    The exact size the output byte string must have.
    If zero, the string has the minimal length.
  byteorder : string
    'big' for big-endian integers (default), 'little' for litte-endian.
:Returns:
  A byte string.
:Raise ValueError:
  If the value is negative or if ``block_size`` is
  provided and the length of the byte string would exceed it.
r   .Conversion only valid for non-negative numbersrD   Lr	      r   @   Q   r>   zUnknown limb size>    Nz@Number is too big to convert to byte string of prescribed lengthlittlebigIncorrect byteorder)rJ   rK   mpz_sizerF   	_sys_bitsmaxrangempz_getlimbnstructpacklenlstrip)	r   
block_size	byteorder	num_limbsspcharilimbsresult
cutoff_lens	            r"   to_bytesIntegerGMP.to_bytes   s   ( !8MNNMM$++.	?FAy>a*?@I"_FAy>a*?@I011 MRR[L\]L\q""4;;	0ABL\]S6#55>>[:-
?]]7+F!^kz"g&<<  "D E EK(F!^,v5F DbD\F%233v;!F1 ^s   /Ec                 (   [        S5      nUS:X  a  O-US:X  a  [        U 5      n U R                  5         O[        S5      e[        R                  UR                  [        [        U 5      5      S[        S5      S[        S5      [        U 5      5        U$ )aF  Convert a byte string into a number.

:Parameters:
  byte_string : byte string
    The input number, encoded in network order.
    It can only be non-negative.
  byteorder : string
    'big' for big-endian integers (default), 'little' for litte-endian.

:Return:
  The ``Integer`` object carrying the same value as the input.
r   r   r   r   r	   )
rA   	bytearrayreverserJ   rK   
mpz_importrF   r   r   r   )byte_stringr   r   s      r"   
from_bytesIntegerGMP.from_bytes(  s     A("#K0K!233 [!12  #K0	2 r%   c                 |    [        U[        5      (       d  [        U5      nU" U R                  UR                  5      $ r9   )rH   rA   rF   )r   r!   terms      r"   _apply_and_returnIntegerGMP._apply_and_returnI  s.    $
++d#DDKK--r%   c                     [        U[        5      (       d  [        U5      (       d  gU R                  [        R
                  U5      S:H  $ )NFr   rH   rA   r   r   rK   r^   r   r   s     r"   __eq__IntegerGMP.__eq__N  s8    4,,d0C0C%%dllD9Q>>r%   c                     [        U[        5      (       d  [        U5      (       d  gU R                  [        R
                  U5      S:g  $ )NTr   r   r   s     r"   __ne__IntegerGMP.__ne__S  s8    4,,d0C0C%%dllD9Q>>r%   c                 H    U R                  [        R                  U5      S:  $ Nr   r   rK   r^   r   s     r"   __lt__IntegerGMP.__lt__X      %%dllD9A==r%   c                 H    U R                  [        R                  U5      S:*  $ r   r   r   s     r"   __le__IntegerGMP.__le__[      %%dllD9Q>>r%   c                 H    U R                  [        R                  U5      S:  $ r   r   r   s     r"   __gt__IntegerGMP.__gt__^  r   r%   c                 H    U R                  [        R                  U5      S:  $ r   r   r   s     r"   __ge__IntegerGMP.__ge__a  r   r%   c                 \    [         R                  U R                  U R                  5      S:g  $ r   rK   r^   rF   r_   ri   s    r"   __nonzero__IntegerGMP.__nonzero__d  s"    ||DKK)9)9:a??r%   c                 \    [         R                  U R                  U R                  5      S:  $ r   r   ri   s    r"   is_negativeIntegerGMP.is_negativeh  s"    ||DKK)9)9:Q>>r%   c                     [        S5      n[        U[         5      (       d   [        U5      n[        R                  UR                  U R                  UR                  5        U$ ! [         a	    [        s $ f = fr   )rA   rH   rU   NotImplementedrK   rQ   rF   r   r   r   s      r"   __add__IntegerGMP.__add__l  g    A$
++&!$' 	V]][[[[	"  ' &%%&   A$ $A76A7c                     [        S5      n[        U[         5      (       d   [        U5      n[        R                  UR                  U R                  UR                  5        U$ ! [         a	    [        s $ f = fr   )rA   rH   rU   r   rK   mpz_subrF   r   s      r"   __sub__IntegerGMP.__sub__x  r   r   c                     [        S5      n[        U[         5      (       d   [        U5      n[        R                  UR                  U R                  UR                  5        U$ ! [         a	    [        s $ f = fr   )rA   rH   rU   r   rK   mpz_mulrF   r   s      r"   __mul__IntegerGMP.__mul__  r   r   c                 8   [        U[        5      (       d  [        U5      n[        R                  UR                  U R
                  5      S:X  a  [        S5      e[        S5      n[        R                  UR                  U R                  UR                  5        U$ )Nr   Division by zero)rH   rA   rK   r^   rF   r_   ZeroDivisionError
mpz_fdiv_q)r   divisorr   s      r"   __floordiv__IntegerGMP.__floordiv__  sx    ':.. )G<<((*-./#$677A	( r%   c                 ^   [        U[        5      (       d  [        U5      n[        R                  UR                  U R
                  5      nUS:X  a  [        S5      eUS:  a  [        S5      e[        S5      n[        R                  UR                  U R                  UR                  5        U$ Nr   r   Modulus must be positive	rH   rA   rK   r^   rF   r_   r   rJ   mpz_mod)r   r   compr   s       r"   __mod__IntegerGMP.__mod__  s    ':.. )G||GNN ,,.19#$677!8788AV]][[^^	% r%   Nc           	         Uca  US:  a  [        S5      eUS:  a  [        S5      e[        R                  U R                  U R                  [	        [        U5      5      5        U $ [        U[        5      (       d  [        U5      nU(       d  [        S5      eUR                  5       (       a  [        S5      e[        U5      (       ad  US:  a  [        S5      eUS:  aA  [        R                  U R                  U R                  [	        U5      UR                  5        U $ [        U5      nO UR                  5       (       a  [        S5      e[        R                  U R                  U R                  UR                  UR                  5        U $ )Nr   zExponent must not be negative   zExponent is too bigr   r      )rJ   rK   
mpz_pow_uirF   r   rb   rH   rA   r   r   r   mpz_powm_uimpz_powm)r   exponentmoduluss      r"   inplace_powIntegerGMP.inplace_pow  sH   ?!| !@AA #~ !677OODKK KK#CM28 - gz22$W-'(:;;""$$ !;<<X&&a<$%DEEe#$$T[[%)[[%,X%6%,^^5  K%h/%%'' !@AAMM$++++"//!..* r%   c                 :    [        U 5      nUR                  X5      $ r9   )rA   r   )r   r   r   r   s       r"   __pow__IntegerGMP.__pow__  s    D!!!(44r%   c                 p    [        S5      n[        R                  UR                  U R                  5        U$ r   )rA   rK   mpz_absrF   )r   r   s     r"   __abs__IntegerGMP.__abs__  s&    AV]]DKK0r%   c                 "   UcH  U S:  a  [        S5      e[        S5      n[        R                  UR                  U R                  5        U$ US::  a  [        S5      e[        U5      n[        U R                  [        U 5      U-  U5      5      nU$ )z?Return the largest Integer that does not
exceed the square rootr   zSquare root of negative valuer   )rJ   rA   rK   mpz_sqrtrF   rb   _tonelli_shanksr   r   r   s      r"   sqrtIntegerGMP.sqrt  s     ?ax !@AA]FMM&--++'  !| !;<<'lG 4 4SY5H' RSFr%   c                    [        U5      (       a  SUs=::  a  S:  a9  O  O6[        R                  U R                  U R                  [	        U5      5        U $ SUs=:  a  S:  a:  O  O7[        R                  U R                  U R                  [	        U* 5      5        U $ [        U5      n[        R                  U R                  U R                  UR                  5        U $ Nr   r    )r   rK   
mpz_add_uirF   r   
mpz_sub_uirA   rQ   r   s     r"   __iadd__IntegerGMP.__iadd__      D 5  $ '/  q  $ '0 d#DT[[[[[[	" r%   c                    [        U5      (       a  SUs=::  a  S:  a9  O  O6[        R                  U R                  U R                  [	        U5      5        U $ SUs=:  a  S:  a:  O  O7[        R                  U R                  U R                  [	        U* 5      5        U $ [        U5      n[        R                  U R                  U R                  UR                  5        U $ r   )r   rK   r   rF   r   r   rA   r   r   s     r"   __isub__IntegerGMP.__isub__  r   r%   c                    [        U5      (       a  SUs=::  a  S:  a9  O  O6[        R                  U R                  U R                  [	        U5      5        U $ SUs=:  a  S:  ad  O  Oa[        R                  U R                  U R                  [	        U* 5      5        [        R                  U R                  U R                  5        U $ [        U5      n[        R                  U R                  U R                  UR                  5        U $ r   )r   rK   
mpz_mul_uirF   r   rS   rA   r   r   s     r"   __imul__IntegerGMP.__imul__  s    D 5  $ '/  q  $ '0 T[[$++6d#DT[[[[[[	" r%   c                 H   [        U[        5      (       d  [        U5      n[        R                  UR                  UR
                  5      nUS:X  a  [        S5      eUS:  a  [        S5      e[        R                  U R                  U R                  UR                  5        U $ r   r   )r   r   r   s      r"   __imod__IntegerGMP.__imod__$  s    ':.. )G||GNN#//119#$677!8788T[[[[^^	% r%   c                     [        S5      n[        U[         5      (       d  [        U5      n[        R                  UR                  U R                  UR                  5        U$ r   )rA   rH   rK   mpz_andrF   r   s      r"   __and__IntegerGMP.__and__3  I    A$
++d#DV]][[[[	" r%   c                     [        S5      n[        U[         5      (       d  [        U5      n[        R                  UR                  U R                  UR                  5        U$ r   )rA   rH   rK   mpz_iorrF   r   s      r"   __or__IntegerGMP.__or__<  r  r%   c           	          [        S5      nUS:  a  [        S5      eUS:  a  U S:  a  gg[        R                  UR                  U R                  [        [        U5      5      5        U$ Nr   znegative shift countr   r   )rA   rJ   rK   ra   rF   r   rb   r   posr   s      r"   
__rshift__IntegerGMP.__rshift__E  s`    A7344;axV]]![[$SX.	0 r%   c           	          US:  a  [        S5      eUS:  a  U S:  a  gg[        R                  U R                  U R                  [	        [        U5      5      5        U $ r  )rJ   rK   ra   rF   r   rb   r   r  s     r"   __irshift__IntegerGMP.__irshift__S  sW    7344;axT[[![[$SX.	0 r%   c           	          [        S5      nSUs=::  a  S:  d  O  [        S5      e[        R                  UR                  U R                  [        [        U5      5      5        U$ Nr   r   zIncorrect shift count)rA   rJ   rK   rP   rF   r   rb   r  s      r"   
__lshift__IntegerGMP.__lshift__`  sR    AC%455&--++!#c(+	- r%   c           	          SUs=::  a  S:  d  O  [        S5      e[        R                  U R                  U R                  [	        [        U5      5      5        U $ r  )rJ   rK   rP   rF   r   rb   r  s     r"   __ilshift__IntegerGMP.__ilshift__i  sI    C%455$++++!#c(+	- r%   c           
          U S:  a  [        S5      eUS:  a  [        S5      eUS:  a  g[        [        R                  U R                  [        [        U5      5      5      5      $ )zHReturn True if the n-th bit is set to 1.
Bit 0 is the least significant.r   z)no bit representation for negative valuesznegative bit countr   )rJ   boolrK   
mpz_tstbitrF   r   rb   )r   ns     r"   get_bitIntegerGMP.get_bitq  s]     !8HIIq5122u9DOODKK$+CFO5 6 	6r%   c                 H    [         R                  U R                  S5      S:H  $ )Nr   r	   rK   r$  rF   ri   s    r"   is_oddIntegerGMP.is_odd      t{{A.!33r%   c                 H    [         R                  U R                  S5      S:H  $ r   r)  ri   s    r"   is_evenIntegerGMP.is_even  r,  r%   c                 d    U S:  a  [        S5      e[        R                  U R                  S5      $ )z=Return the minimum number of bits that can encode the number.r   rx      )rJ   rK   mpz_sizeinbaserF   ri   s    r"   size_in_bitsIntegerGMP.size_in_bits  s.     !8MNN""4;;22r%   c                 4    U R                  5       S-
  S-  S-   $ )z>Return the minimum number of bytes that can encode the number.r	   r>   )r3  ri   s    r"   size_in_bytesIntegerGMP.size_in_bytes  s     !!#a'A-11r%   c                 F    [         R                  U R                  5      S:g  $ r   )rK   mpz_perfect_square_prF   ri   s    r"   is_perfect_squareIntegerGMP.is_perfect_square  s    ((5::r%   c                 B   [        U5      (       aU  SUs=:  a  S:  a=  O  O:[        R                  U R                  [	        U5      5      (       a  [        S5      eg[        U5      n[        R                  U R                  UR                  5      (       a  [        S5      eg)z3Raise an exception if the small prime is a divisor.r   r   zThe value is compositeN)r   rK   mpz_divisible_ui_prF   r   rJ   rA   mpz_divisible_p)r   small_primes     r"   fail_if_divisible_byIntegerGMP.fail_if_divisible_by  s     %%;&&**4;;+2;+?A A$%=>>$[1K + 2 24 45664r%   c                     [        U[        5      (       d  [        U5      n[        U5      (       a  SUs=:  a  S:  a9  O  O6[        R	                  U R
                  UR
                  [        U5      5        U $ SUs=:  a  S:  a:  O  O7[        R                  U R
                  UR
                  [        U* 5      5        U $ [        U5      n[        R                  U R
                  UR
                  UR
                  5        U $ )z/Increment the number by the product of a and b.r   r   r   )	rH   rA   r   rK   mpz_addmul_uirF   r   mpz_submul_ui
mpz_addmul)r   abs      r"   multiply_accumulateIntegerGMP.multiply_accumulate  s     !Z((1A1}u}""4;;#$88#*1:/ ~A~""4;;#$88#*A2;0 1A	" r%   c                     [        U[        5      (       d  [        U5      n[        R                  U R                  UR                  5        U $ )z'Set the Integer to have the given value)rH   rA   rK   mpz_setrF   )r   sources     r"   setIntegerGMP.set  s9     &*--'FT[[]]	$r%   c                 l   [        U[        5      (       d  [        U5      n[        R                  UR                  U R
                  5      nUS:X  a  [        S5      eUS:  a  [        S5      e[        R                  U R                  U R                  UR                  5      nU(       d  [        S5      eU $ )zmCompute the inverse of this number in the ring of
modulo integers.

Raise an exception if no inverse exists.
r   Modulus cannot be zeror   z No inverse value can be computed)	rH   rA   rK   r^   rF   r_   r   rJ   
mpz_invert)r   r   r   r   s       r"   inplace_inverseIntegerGMP.inplace_inverse  s     ':.. )G||GNN ,,.19#$<==!8788!%!(1 ?@@r%   c                 >    [        U 5      nUR                  U5        U$ r9   )rA   rR  r   s      r"   inverseIntegerGMP.inverse  s    D!w'r%   c                 H   [        S5      n[        U5      (       aQ  SUs=:  a  S:  a9  O  O6[        R                  UR                  U R                  [        U5      5        U$ [        U5      n[        R                  UR                  U R                  UR                  5        U$ )zMCompute the greatest common denominator between this
number and another term.r   i  )rA   r   rK   
mpz_gcd_uirF   r   mpz_gcdr   s      r"   gcdIntegerGMP.gcd  sw     A4% $ '/ d#DV]]DKK=r%   c                     [        S5      n[        U[         5      (       d  [        U5      n[        R                  UR                  U R                  UR                  5        U$ )zICompute the least common multiplier between this
number and another term.r   )rA   rH   rK   mpz_lcmrF   r   s      r"   lcmIntegerGMP.lcm  sE     A$
++d#DV]]DKK=r%   c                 "   [        U [        5      (       d  [        U 5      n [        U[        5      (       d  [        U5      nUS::  d  UR                  5       (       a  [        S5      e[        R                  U R                  UR                  5      $ )zCompute the Jacobi symbolr   z,n must be positive odd for the Jacobi symbol)rH   rA   r.  rJ   rK   
mpz_jacobirF   )rF  r%  s     r"   jacobi_symbolIntegerGMP.jacobi_symbol  sf     !Z((1A!Z((1A6QYY[[KLLqxx22r%   c                 z   [        U [        5      (       d  [        U 5      n [        U[        5      (       d  [        U5      n[        U[        5      (       d  [        U5      nUS:  a  [        S5      eUS:X  a  [        S5      eUS-  S:X  a  [        S5      eX-  U-  nUR	                  UR                  5       5      $ )Nr   r   rP  r	   zOdd modulus is required)rH   rA   rJ   r   r   r6  )term1term2r   products       r"   _mult_modulo_bytesIntegerGMP._mult_modulo_bytes  s    %,,u%E%,,u%E':.. )GQ;788a<#$<==aKA677=G+ 5 5 788r%   c                      U R                   b0  U R                  (       a  [        R                  U R                   5        S U l         g ! [         a     g f = fr9   )rF   rG   rK   rR   r   ri   s    r"   __del__IntegerGMP.__del__  sC    	{{&$$NN4;;/DK 		s   AA 
AA)rG   rF   )r   r   )r   r9   )Ar'   r(   r)   r*   __doc__r:   r_   rK   mpz_init_set_uir   r[   re   rj   rn   rr   ru   r   staticmethodr   r   r   r   r   r   r   r   r   __bool__r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r   r&  r*  r.  r3  r6  r:  r@  rH  rM  rR  rU  rZ  r^  rb  rh  rk  r+   r&   r%   r"   rA   rA      s[   -)Kgaj1'&T&):x  @.
?
?
>?>?@H?



%N5
$$$&64432;7,0
 	3 	3 9 9&	r%   rA   )"sysr   Crypto.Util.py3compatr   Crypto.Util._raw_apir   r   r   r   r   _IntegerBaser
   gmp_defsplatformImportErrorr   implementationhasattrobjectr   rK   r,   r-   r.   r/   r0   r2   r:   r   restyper;   calcsizer   rA   r&   r%   r"   <module>r}     s   >   /B B &8t <<7
0
11uh"73
3 !!
-
..6  v %H$88)y )
 !(D )
 $$	D
 D
r%   