§
    qŠtj"  ã                   óZ   — d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 g d¢Z
d„ Zd	„ Zdd„ZdS )a  
RFC 6979:
    Deterministic Usage of the Digital Signature Algorithm (DSA) and
    Elliptic Curve Digital Signature Algorithm (ECDSA)

    http://tools.ietf.org/html/rfc6979

Many thanks to Coda Hale for his implementation in Go language:
    https://github.com/codahale/rfc6979
é    N)Úhexlifyé   )Únumber_to_stringÚnumber_to_string_cropÚ
bit_length)Úhmac_compat)r   Úbits2intÚbits2octetsÚ
generate_kc                 ó€   — t          t          | ¦  «        d¦  «        }t          | ¦  «        dz  }||k    r|||z
  z	  S |S )Né   é   )Úintr   Úlen)ÚdataÚqlenÚxÚls       úK/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/ecdsa/rfc6979.pyr	   r	      sB   € Ý�G�D‰MŒM˜2ÑÔ€AÝˆD‰	Œ	�A‰€Aàˆ4‚x€xØ�Q˜‘X‰ÐØ€Hó    c                 óv   — t          | t          |¦  «        ¦  «        }||z
  }|dk     r|}t          ||¦  «        S )Nr   )r	   r   r   )r   ÚorderÚz1Úz2s       r   r
   r
       s@   € Ý	�$�
 5Ñ)Ô)Ñ	*Ô	*€BØ	ˆe‰€Bà	ˆA‚v€vØˆå   UÑ+Ô+Ð+r   r   c                 ó°  — t          | ¦  «        } |¦   «         j        }|dz   dz  }t          t          || ¦  «        ¦  «        t          t	          || ¦  «        ¦  «        t          |¦  «        f}	d|z  }
d|z  }t          j        ||¬¦  «        }|                     |
dz   ¦  «         |	D ]}|                     |¦  «         Œ|                     ¦   «         }t          j        ||
|¦  «                             ¦   «         }
t          j        ||¬¦  «        }|                     |
dz   ¦  «         |	D ]}|                     |¦  «         Œ|                     ¦   «         }t          j        ||
|¦  «                             ¦   «         }
	 d}t          |¦  «        |k     r@t          j        ||
|¦  «                             ¦   «         }
||
z  }t          |¦  «        |k     °@t          ||¦  «        }d|cxk    r| k     rn n|d	k    r|S |dz  }t          j        ||
dz   |¦  «                             ¦   «         }t          j        ||
|¦  «                             ¦   «         }
ŒÖ)
aD  
    Generate the ``k`` value - the nonce for DSA.

    :param int order: order of the DSA generator used in the signature
    :param int secexp: secure exponent (private key) in numeric form
    :param hash_func: reference to the same hash function used for generating
        hash, like :py:class:`hashlib.sha1`
    :param bytes data: hash in binary form of the signing data
    :param int retry_gen: how many good 'k' values to skip before returning
    :param bytes extra_entropy: additional added data in binary form as per
        section-3.6 of rfc6979
    :rtype: int
    é   r   ó   ó    )Ú	digestmodTr   r   r   )r   Údigest_sizer   r   r
   ÚhmacÚnewÚupdateÚdigestr   r	   )r   ÚsecexpÚ	hash_funcr   Ú	retry_genÚextra_entropyr   ÚholenÚrolenÚbxÚvÚkÚiÚtÚsecrets                  r   r   r   +   sX  € õ �eÑÔ€DØˆI‰KŒKÔ#€EØ�A‰X˜!‰O€EåÕ$ V¨UÑ3Ô3Ñ4Ô4Ý•K  eÑ,Ô,Ñ-Ô-Ý�MÑ"Ô"ð
€Bð 	�%‰€Að 	�%‰€Aõ 	Œ�˜iÐ(Ñ(Ô(€AØ‡H‚HˆQ�‰[ÑÔÐØð ð ˆØ	�Š�‰ŒˆˆØ	�Š‰
Œ
€Aõ 	Œ��A�yÑ!Ô!×(Ò(Ñ*Ô*€Aõ 	Œ�˜iÐ(Ñ(Ô(€AØ‡H‚HˆQ�‰[ÑÔÐØð ð ˆØ	�Š�‰ŒˆˆØ	�Š‰
Œ
€Aõ 	Œ��A�yÑ!Ô!×(Ò(Ñ*Ô*€Að/àˆõ �!‰fŒf�uŠnˆnÝ”˜˜A˜yÑ)Ô)×0Ò0Ñ2Ô2ˆAØ�‰FˆAõ �!‰fŒf�uŠnˆnõ
 ˜!˜TÑ"Ô"ˆà�ÐÐÒÐ˜ÒÐÐÐÐØ˜AŠ~ˆ~Ø�Ø˜‰NˆIåŒH�Q˜˜G™ YÑ/Ô/×6Ò6Ñ8Ô8ˆÝŒH�Q˜˜9Ñ%Ô%×,Ò,Ñ.Ô.ˆð%/r   )r   r   )Ú__doc__r!   Úbinasciir   Úutilr   r   r   Ú_compatr   Ú__all__r	   r
   r   © r   r   ú<module>r7      s¬   ðð	ð 	ð €€€Ø Ð Ð Ð Ð Ð Ø EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EØ  Ð  Ð  Ð  Ð  Ð  ð
 BÐ
AÐ
A€ðð ð ð,ð ,ð ,ðF/ð F/ð F/ð F/ð F/ð F/r   