
    i0                     t    S SK Jr  S SKJrJr  S SKJrJr  S SKJ	r	J
r
JrJr  S rS r " S S\5      rSS
 jrg	)    )Integer)SHA512SHAKE256)bchris_bytes)EccKey	construct_import_ed25519_public_key_import_ed448_public_keyc                     [        U 5      S:X  a  [        U 5      u  pSnO6[        U 5      S:X  a  [        U 5      u  pSnO[        S[        U 5      -  5      e[	        X1US9$ )a  Create a new Ed25519 or Ed448 public key object,
starting from the key encoded as raw ``bytes``,
in the format described in RFC8032.

Args:
  encoded (bytes):
    The EdDSA public key to import.
    It must be 32 bytes for Ed25519, and 57 bytes for Ed448.

Returns:
  :class:`Crypto.PublicKey.EccKey` : a new ECC key object.

Raises:
  ValueError: when the given key cannot be parsed.
    Ed255199   Ed448zNot an EdDSA key (%d bytes))curvepoint_xpoint_y)lenr
   r   
ValueErrorr	   )encodedxy
curve_names       Q/var/www/html/trading/venv/lib/python3.13/site-packages/Crypto/Signature/eddsa.pyimport_public_keyr   )   s`    " 7|r)'2
	W	'0
6WEFF:!<<    c                 r    [        U 5      S:X  a  SnO[        U 5      S:X  a  SnO[        S5      e[        XS9$ )a  Create a new Ed25519 or Ed448 private key object,
starting from the key encoded as raw ``bytes``,
in the format described in RFC8032.

Args:
  encoded (bytes):
    The EdDSA private key to import.
    It must be 32 bytes for Ed25519, and 57 bytes for Ed448.

Returns:
  :class:`Crypto.PublicKey.EccKey` : a new ECC key object.

Raises:
  ValueError: when the given key cannot be parsed.
r   ed25519r   ed448z8Incorrect length. Only EdDSA private keys are supported.)seedr   )r   r   r	   )r   r   s     r   import_private_keyr!   E   s?    " 7|r
	W	
STT
 '44r   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)EdDSASigSchemec   z`An EdDSA signature object.
Do not instantiate directly.
Use :func:`Crypto.Signature.eddsa.new`.
c                 |    Xl         X l        UR                  5       U l        UR                  R
                  U l        g)zmCreate a new EdDSA object.

Do not instantiate this object directly,
use `Crypto.Signature.DSS.new` instead.
N)_key_context_export_eddsa_public_A_curveorder_order)selfkeycontexts      r   __init__EdDSASigScheme.__init__i   s/     	**,jj&&r   c                 6    U R                   R                  5       $ )zJReturn ``True`` if this signature object can be used
for signing messages.)r&   has_private)r-   s    r   can_signEdDSASigScheme.can_signu   s     yy$$&&r   c                    U R                   R                  5       (       d  [        S5      eU R                   R                  S:X  aI  [	        U[
        R                  5      nU(       d  [        U5      (       d  [        S5      eU R                  nOnU R                   R                  S:X  aI  [	        U[        R                  5      nU(       d  [        U5      (       d  [        S5      eU R                  nO[        S5      eU" X5      $ )a  Compute the EdDSA signature of a message.

Args:
  msg_or_hash (bytes or a hash object):
    The message to sign (``bytes``, in case of *PureEdDSA*) or
    the hash that was carried out over the message (hash object, for *HashEdDSA*).

    The hash object must be :class:`Crypto.Hash.SHA512` for Ed25519,
    and :class:`Crypto.Hash.SHAKE256` object for Ed448.

:return: The signature as ``bytes``. It is always 64 bytes for Ed25519, and 114 bytes for Ed448.
:raise TypeError: if the EdDSA key has no private half
zPrivate key is needed to signr   -'msg_or_hash' must be bytes of a SHA-512 hashr   .'msg_or_hash' must be bytes of a SHAKE256 hashIncorrect curve for EdDSA)r&   r3   	TypeErrorr   
isinstancer   
SHA512Hashr   _sign_ed25519r   SHAKE256_XOF_sign_ed448r   )r-   msg_or_hashpheddsa_sign_methods       r   signEdDSASigScheme.sign{   s     yy$$&&;<<99??i'K):):;B(;// OPP $ 2 2YY__'K)>)>?B(;// PQQ $ 0 0 899 11r   c                 P   U R                   (       d  U(       aF  [        U5      nS[        U5      -   [        [        U R                   5      5      -   U R                   -   nOSnU(       a  UR	                  5       OUn[
        R                  " X@R                  R                  -   U-   5      R	                  5       n[        R                  " US5      U R                  -  n[        XpR                  R                  R                  -  S9R                  5       n[
        R                  " XH-   U R                   -   U-   5      R	                  5       n	[        R                  " U	S5      U R                  -  n
XzU R                  R"                  -  -   U R                  -  nXR%                  SS5      -   $ )N    SigEd25519 no Ed25519 collisionsr   littlepointr   )r'   intr   r   digestr   newr&   _prefixr   
from_bytesr,   r   r*   Gr(   r)   dto_bytes)r-   r@   rA   flagdom2PHMr_hashrR_pkk_hashkss               r   r=   EdDSASigScheme._sign_ed25519   s<   ==Br7D6dCDMM*+,.2mm<D D&(k  "k
 D99#4#44s:;BBDvx04;;>A		 0 0 2 223HHJDK$''1C78??Avx04;;>TYY[[ DKK/jjX...r   c                 <   [        U5      nS[        U5      -   [        [        U R                  5      5      -   U R                  -   nU(       a  UR	                  5       R                  S5      OUn[        R                  " X@R                  R                  -   U-   5      R                  S5      n[        R                  " US5      U R                  -  n[        XpR                  R                  R                  -  S9R!                  5       n[        R                  " XH-   U R"                  -   U-   5      R                  S5      n	[        R                  " U	S5      U R                  -  n
XzU R                  R$                  -  -   U R                  -  nXR'                  SS5      -   $ )N   SigEd448@   r   rG   rH   r   )rJ   r   r   r'   copyreadr   rL   r&   rM   r   rN   r,   r   r*   rO   r(   r)   rP   rQ   )r-   r@   rA   rR   dom4rT   rU   rV   rW   rX   rY   rZ   s               r   r?   EdDSASigScheme._sign_ed448   s=   2wT$Z'C&'(*.--8 .0k %%b)[
 dYY%6%66<=BB3Gvx04;;>A		 0 0 2 223HHJdkDGG3c9:??Dvx04;;>TYY[[ DKK/jjX...r   c                    U R                   R                  S:X  aI  [        U[        R                  5      nU(       d  [        U5      (       d  [        S5      eU R                  nOnU R                   R                  S:X  aI  [        U[        R                  5      nU(       d  [        U5      (       d  [        S5      eU R                  nO[        S5      eU" XU5      $ )a'  Check if an EdDSA signature is authentic.

Args:
  msg_or_hash (bytes or a hash object):
    The message to verify (``bytes``, in case of *PureEdDSA*) or
    the hash that was carried out over the message (hash object, for *HashEdDSA*).

    The hash object must be :class:`Crypto.Hash.SHA512` object for Ed25519,
    and :class:`Crypto.Hash.SHAKE256` for Ed448.

  signature (``bytes``):
    The signature that needs to be validated.
    It must be 64 bytes for Ed25519, and 114 bytes for Ed448.

:raise ValueError: if the signature is not authentic
r   r7   r   r8   r9   )r&   r   r;   r   r<   r   r:   _verify_ed25519r   r>   _verify_ed448r   )r-   r@   	signaturerA   eddsa_verify_methods        r   verifyEdDSASigScheme.verify   s    $ 99??i'K):):;B(;// OPP"&"6"6YY__'K)>)>?B(;// PQQ"&"4"4 899";2>>r   c                 `   [        U5      S:w  a  [        S5      eU R                  (       d  U(       aF  [        U5      nS[	        U5      -   [	        [        U R                  5      5      -   U R                  -   nOSnU(       a  UR                  5       OUn [        US S 5      R                  n[        R                  " USS  S5      nXR                  :  a  [        S5      e[        R                  " XRS S -   U R                  -   U-   5      R                  5       n	[        R                  " U	S5      U R                  -  n
US	-  U R                  R                  R                   -  nS	U-  U
S	-  U R                  R                  -  -   nX:w  a  [        S
5      eg ! [         a    [        S5      ef = f)Nr^   'The signature is not authentic (length)rF   r   r   "The signature is not authentic (R)rG   "The signature is not authentic (S)   The signature is not authentic)r   r   r'   rJ   r   rK   r   pointQr   rN   r,   r   rL   r)   r&   r*   rO   )r-   r@   rg   rA   rR   rS   rT   RrZ   rX   rY   point1point2s                r   re   EdDSASigScheme._verify_ed25519   s   y>RFGG==Br7D6dCDMM*+,.2mm<D D&(k  "k
	C!)CR.188A y~x8{{?ABBDSb>1DGG;cABIIKvx04;;>Q))+++ QQ!1!111=>>   	CABB	Cs   F F-c                 J   [        U5      S:w  a  [        S5      e[        U5      nS[        U5      -   [        [        U R                  5      5      -   U R                  -   nU(       a  UR                  5       R                  S5      OUn [        US S 5      R                  n[        R                  " USS  S5      nXR                  :  a  [        S5      e[        R                  " XRS S -   U R                  -   U-   5      R                  S5      n	[        R                  " U	S5      U R                  -  n
US	-  U R                  R                   R"                  -  nS	U-  U
S	-  U R                  R                  -  -   nX:w  a  [        S
5      eg ! [         a    [        S5      ef = f)Nr_   rl   r]   r^   r   rm   rG   rn   ro   rp   )r   r   rJ   r   r'   r`   ra   r   rq   r   rN   r,   r   rL   r)   r&   r*   rO   )r-   r@   rg   rA   rR   rb   rT   rr   rZ   rX   rY   rs   rt   s                r   rf   EdDSASigScheme._verify_ed448  s   y>S FGG2wT$Z'C&'(*.--8 .0k %%b)[
	C!)CR.188A y~x8{{?ABBds^3dgg=CDII#Nvx04;;>Q))+++ QQ!1!111=>>   	CABB	Cs   	F F")r)   r'   r&   r,   N)__name__
__module____qualname____firstlineno____doc__r0   r4   rC   r=   r?   ri   re   rf   __static_attributes__ r   r   r#   r#   c   s2    

''!2F/6/0!?F!?F?r   r#   Nc                     [        U [        5      (       a  U R                  S;  a  [        S5      eUS:w  a  [        S5      eUc  SnO[	        U5      S:  a  [        S5      e[        X5      $ )aq  Create a signature object :class:`EdDSASigScheme` that
can perform or verify an EdDSA signature.

Args:
    key (:class:`Crypto.PublicKey.ECC` object):
        The key to use for computing the signature (*private* keys only)
        or for verifying one.
        The key must be on the curve ``Ed25519`` or ``Ed448``.

    mode (string):
        This parameter must be ``'rfc8032'``.

    context (bytes):
        Up to 255 bytes of `context <https://datatracker.ietf.org/doc/html/rfc8032#page-41>`_,
        which is a constant byte string to segregate different protocols or
        different applications of the same key.
)r   r   z&EdDSA can only be used with EdDSA keysrfc8032zMode must be 'rfc8032'r      z3Context for EdDSA must not be longer than 255 bytes)r;   r   r   r   r   r#   )r.   moder/   s      r   rL   rL   9  sj    & c6""cii7K&KABBy122	W	NOO#''r   )N)Crypto.Math.Numbersr   Crypto.Hashr   r   Crypto.Util.py3compatr   r   Crypto.PublicKey.ECCr   r	   r
   r   r   r!   objectr#   rL   r~   r   r   <module>r      s8   > ( ( 0< <=85<S?V S?l(r   