+
    '(jk,                         R t ^ RIHt ^ RIHt ^ RIHt ^ t^tRR lt	R t
^ RIHt ]! ]R,          4      tRR	 ltR
 tR tR# )zHFunctions to create and test prime numbers.

:undocumented: __package__
)Random)Integer)
iter_rangeNc                   \        V \        4      '       g   \        V 4      p V R9   d   \        # V P                  4       '       d   \        # \        ^4      p\        V ^,
          4      pVf    \
        P                  ! 4       P                  p\        V4      p^ pVP                  4       '       d   V^,          pV^,          pK*  \        V4       F  p^pWV39   d>   \        P                  ! ^V ^,
          VR7      p^Tu;8:  d   V ^,
          8:  d   K@  Q h Q h\        WV 4      p	WV39   d   K`  \        ^V4       F)  p
\        V	^V 4      p	W8X  d    K  W8X  g   K!  \        u u # 	  \        u # 	  \        # )a  Perform a Miller-Rabin primality test on an integer.

The test is specified in Section C.3.1 of `FIPS PUB 186-4`__.

:Parameters:
  candidate : integer
    The number to test for primality.
  iterations : integer
    The maximum number of iterations to perform before
    declaring a candidate a probable prime.
  randfunc : callable
    An RNG function where bases are taken from.

:Returns:
  ``Primality.COMPOSITE`` or ``Primality.PROBABLY_PRIME``.

.. __: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
)min_inclusivemax_inclusiverandfunc            )
isinstancer   PROBABLY_PRIMEis_even	COMPOSITEr   newreadr   random_rangepow)	candidate
iterationsr   one	minus_onemaibasezjs   &&&        J/home/ubuntu/cf-venv/lib/python3.14/site-packages/Crypto/Math/Primality.pymiller_rabin_testr!   -   sX   ( i))I&	L 
!*C	A&I::<$$ 		A	A
))++	a	Q
 
# I&&''a"+a-%'D -	A-.-.- #i   Aq!AAq)$A~x   " / $4     c                   \        V \        4      '       g   \        V 4      p V R9   d   \        # V P                  4       '       g   V P	                  4       '       d   \
        # R pV! 4        F<  pWV) 39   d   K  \        P                  ! W 4      pV^ 8X  d	   \
        u # VR8X  g   K<   M	  V ^,           pVP                  4       ^,
          p\        ^4      p\        ^4      p\        ^ 4      p\        ^ 4      p	\        V^,
          RR4       EF\  p
VP                  V4       W,          pW,          pV	P                  V4       W,          p	V	X,          p	V	P                  Ww4       V	P                  4       '       d	   W,          p	V	^,          p	W,          p	VP                  V
4      '       d   VP                  V4       Wi,          pVP                  4       '       d	   W`,          pV^,          pW`,          pVP                  V	4       VP                  W4       VP                  4       '       d	   Wp,          pV^,          pWp,          pEK:  VP                  V4       VP                  V	4       EK_  	  V^ 8X  d   \        # \
        # )a?  Perform a Lucas primality test on an integer.

The test is specified in Section C.3.3 of `FIPS PUB 186-4`__.

:Parameters:
  candidate : integer
    The number to test for primality.

:Returns:
  ``Primality.COMPOSITE`` or ``Primality.PROBABLY_PRIME``.

.. __: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
c               3   V   "   ^p  V x  V ^ 8  d   V ^,          p M	V ^,          p V ) p K$  5i)r    )values    r    	alternatelucas_test.<locals>.alternate   s2     Kqy

FEs   ')r	   )r   r   r   r   is_perfect_squarer   jacobi_symbolsize_in_bitsr   setmultiply_accumulateis_oddget_bit)r   r'   DjsKrU_iV_iU_tempV_tempr   s   &          r    
lucas_testr9   w   s    i))I&	 L i99;; [QB""1078  	AA	1A !*C
!*CQZFQZFAr2& 	

3

3!""3,==??F199Q<<GGFOMCzz|| AICCGGFO##F.zz|| AICCGGFOGGFOC 'F axr"   )
sieve_base:Nd   Nc                6  a Vf    \         P                  ! 4       P                  p\        V \        4      '       g   \	        V 4      p \        V 4      \        9   d   \        #  \        V P                  \        4       RpT P                  4       o \        \        T3R lT4      4      ^ ,          ^,          p\!        YTR7      \        8X  d   \        # \#        T 4      \        8X  d   \        # \        #   \         d
    \        u # i ; i  \         d    ^p Lbi ; i)a  Test if a number is prime.

A number is qualified as prime if it passes a certain
number of Miller-Rabin tests (dependent on the size
of the number, but such that probability of a false
positive is less than 10^-30) and a single Lucas test.

For instance, a 1024-bit candidate will need to pass
4 Miller-Rabin tests.

:Parameters:
  candidate : integer
    The number to test for primality.
  randfunc : callable
    The routine to draw random bytes from to select Miller-Rabin bases.
:Returns:
  ``PROBABLE_PRIME`` if the number if prime with very high probability.
  ``COMPOSITE`` if the number is a composite.
  For efficiency reasons, ``COMPOSITE`` is also returned for small primes.
c                    < SV ^ ,          8  # )    r%   )xbit_sizes   &r    <lambda>%test_probable_prime.<locals>.<lambda>  s    h1or"   r   )
)      )i     )i     )i   
   )il     )i     )iz  r   )i     )i  r   )it  r   )r   r   r   r   r   int_sieve_baser   mapfail_if_divisible_by
ValueErrorr   r,   listfilter
IndexErrorr!   r9   )r   r   	mr_rangesmr_iterationsr@   s   &&  @r    test_probable_primerV      s   , ::<$$i))I&	 9~$I**K8'I %%'HV$=$-/ 0013346
 "*,/89)	)-    s$   !C1 'D 1DDDDc                    V P                  RR4      pV P                  RR4      pV P                  RR 4      pV '       d!   \        RV P                  4       ,           4      hVf   \        R4      hV^8  d   \        R4      hVf    \        P                  ! 4       P
                  p\        pV\        8X  d=   \        P                  ! VVR	7      ^,          pV! V4      '       g   K:  \        WR4      pKG  X# )
a  Generate a random probable prime.

The prime will not have any specific properties
(e.g. it will not be a *strong* prime).

Random numbers are evaluated for primality until one
passes all tests, consisting of a certain number of
Miller-Rabin tests with random bases followed by
a single Lucas test.

The number of Miller-Rabin iterations is chosen such that
the probability that the output number is a non-prime is
less than 1E-30 (roughly 2^{-100}).

This approach is compliant to `FIPS PUB 186-4`__.

:Keywords:
  exact_bits : integer
    The desired size in bits of the probable prime.
    It must be at least 160.
  randfunc : callable
    An RNG function where candidate primes are taken from.
  prime_filter : callable
    A function that takes an Integer as parameter and returns
    True if the number can be passed to further primality tests,
    False if it should be immediately discarded.

:Return:
    A probable prime in the range 2^exact_bits > p > 2^(exact_bits-1).

.. __: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf

exact_bitsNr   prime_filterc                     R # )Tr%   )r?   s   &r    rA   )generate_probable_prime.<locals>.<lambda><  s    r"   Unknown parameters: zMissing exact_bits parameterzPrime number is not big enough.rX   r   )
poprP   keysr   r   r   r   r   randomrV   )kwargsrX   r   rY   resultr   s   ,     r    generate_probable_primerc     s    D L$/Jzz*d+H::nn=L/&++-?@@788C:;;::<$$F
I
NNj,4689:	I&&$Y9r"   c                    V P                  RR4      pV P                  RR4      pV '       d!   \        RV P                  4       ,           4      hVf    \        P                  ! 4       P
                  p\        pV\        8X  dJ   \        V^,
          VR7      pV^,          ^,           pVP                  4       V8w  d   KF  \        WRR7      pKT  X# )as  Generate a random, probable safe prime.

Note this operation is much slower than generating a simple prime.

:Keywords:
  exact_bits : integer
    The desired size in bits of the probable safe prime.
  randfunc : callable
    An RNG function where candidate primes are taken from.

:Return:
    A probable safe prime in the range
    2^exact_bits > p > 2^(exact_bits-1).
rX   Nr   r\   r]   rC   )
r^   rP   r_   r   r   r   r   rc   r,   rV   )ra   rX   r   rb   qr   s   ,     r    generate_probable_safe_primerf   R  s      L$/Jzz*d+H/&++-?@@::<$$F
I
#zA~QEAI	!!#z1$YBr"   )N)__doc__Cryptor   Crypto.Math.Numbersr   Crypto.Util.py3compatr   r   r   r!   r9   Crypto.Util.numberr:   _sieve_base_larger-   rM   rV   rc   rf   r%   r"   r    <module>rm      sU   >
  ' ,	GT^B ? #D)*7t7tr"   