+
    '(j                        ^ RI Ht ^ RIt^ RIt^ RIt^ RIHtHtHtH	t	H
t
 ^ RIHt ^ RIHtHtHtHt ^ RIHtHtHt ^ RIHtHt ^ RIHt ^R	IHtHtHt ^R
IHt   ! R R]!4      t" ! R R]#4      t$R t%R t&R&R lt'R t(R'R lt)R t*R t+R t,R t-R t.R t/R t0R t1R t2R&R lt3]4R8X  d   ^ RI5t5Rt6]R ,          Pn                  Pq                  4       t9R!t:]5Pj                  ! 4       t;]<! ]:4       F  t=]9]6,          t>K  	  ]?! R"]5Pj                  ! 4       ];,
          ]:,          R#,          R$4       ]5Pj                  ! 4       t;]<! ]:4       F  t=]>]6,          t>K  	  ]?! R%]5Pj                  ! 4       ];,
          ]:,          R#,          R$4       R# R# )(    )print_functionN)bordtobytestostrbchr	is_string)Integer)DerObjectIdDerOctetStringDerSequenceDerBitString)_expand_subject_public_key_info_create_subject_public_key_info _extract_subject_public_key_info)SHA512SHAKE256)get_random_bytes)EccPoint	EccXPoint_curves)CurveIDc                       ] tR t^7tRtR# )UnsupportedEccFeature N)__name__
__module____qualname____firstlineno____static_attributes__r       I/home/ubuntu/cf-venv/lib/python3.14/site-packages/Crypto/PublicKey/ECC.pyr   r   7   s    r    r   c                      a  ] tR t^;t o RtR tR tR tR tR t	R t
]R 4       t]R	 4       t]R
 4       tR tR tR tR tR tRR ltR tR tR tR tR tR tR tRtV tR# )EccKeya  Class defining an ECC key.
Do not instantiate directly.
Use :func:`generate`, :func:`construct` or :func:`import_key` instead.

:ivar curve: The **canonical** name of the curve as defined in the `ECC table`_.
:vartype curve: string

:ivar pointQ: an ECC point representing the public component.
:vartype pointQ: :class:`EccPoint` or :class:`EccXPoint`

:ivar d: A scalar that represents the private component
         in NIST P curves. It is smaller than the
         order of the generator point.
:vartype d: integer

:ivar seed: A seed that represents the private component
            in Ed22519 (32 bytes), Curve25519 (32 bytes),
            Curve448 (56 bytes), Ed448 (57 bytes).
:vartype seed: bytes
c                
   \        V4      pVP                  RR4      pVP                  RR4      V n        VP                  RR4      V n        VP                  RR4      V n        Vf)   V P                  '       d   V P                  P
                  pV'       d   \        R\        V4      ,           4      hV\        9  d   \        RV,          4      h\        V,          V n
        V P                  P                  V n        \        V P                  RJ4      \        V P                  RJ4      ,           pV^ 8X  d   V P                  f   \        R4      hR# V^8X  d   \        R	4      hV P                  P                  \        P                  8X  d   V P                  e   \        R
4      h\!        V P                  4      ^ 8w  d   \        R4      h\"        P$                  ! V P                  4      P'                  4       pVR,          V n        \+        VR,          4      pV^ ;;,          ^,          uu&   V^,          ^,          ^@,          V^&   \,        P.                  ! VRR7      V n        R# V P                  P                  \        P0                  8X  d   V P                  e   \        R
4      h\!        V P                  4      ^98w  d   \        R4      h\2        P$                  ! V P                  4      P5                  ^r4      pVR,          V n        \+        VR,          4      pV^ ;;,          ^,          uu&   V^7;;,          ^,          uu&   ^ V^8&   \,        P.                  ! VRR7      V n        R# V P                  P                  \        P6                  8X  d   V P                  e   \        R
4      h\!        V P                  4      ^ 8w  d   \        R4      h\+        V P                  4      pV^ ;;,          ^,          uu&   V^,          ^,          ^@,          V^&   \,        P.                  ! VRR7      V n        R# V P                  P                  \        P8                  8X  d   V P                  e   \        R
4      h\!        V P                  4      ^88w  d   \        R4      h\+        V P                  4      pV^ ;;,          ^,          uu&   V^7;;,          ^,          uu&   \,        P.                  ! VRR7      V n        R# V P                  e   \        R4      h\-        V P                  4      V n        ^V P                  u;8:  d   V P                  P:                  8  g   M \        R4      hR# )a(  Create a new ECC key

Keywords:
  curve : string
    The name of the curve.
  d : integer
    Mandatory for a private key one NIST P curves.
    It must be in the range ``[1..order-1]``.
  seed : bytes
    Mandatory for a private key on Ed25519 (32 bytes),
    Curve25519 (32 bytes), Curve448 (56 bytes) or Ed448 (57 bytes).
  point : EccPoint or EccXPoint
    Mandatory for a public key. If provided for a private key,
    the implementation will NOT check whether it matches ``d``.

Only one parameter among ``d``, ``seed`` or ``point`` may be used.
curveNdseedpointUnknown parameters: zUnsupported curve (%s)zGAt lest one between parameters 'point', 'd' or 'seed' must be specifiedz,Parameters d and seed are mutually exclusivez/Parameter d can only be used with NIST P curvesz0Parameter seed must be 32 bytes long for Ed25519:    NN:Nr*   Nlittle	byteorderz.Parameter seed must be 57 bytes long for Ed448:9   NN:Nr.   Nz3Parameter seed must be 32 bytes long for Curve25519z1Parameter seed must be 56 bytes long for Curve448z2Parameter 'seed' cannot be used with NIST P-curvesz;Parameter d must be an integer smaller than the curve order)dictpop_d_seed_pointr%   	TypeErrorstrr   
ValueError_curve	canonicalintid_CurveIDED25519lenr   newdigest_prefix	bytearrayr	   
from_bytesED448r   read
CURVE25519CURVE448order)selfkwargskwargs_
curve_namecount	seed_hashtmps   &,     r!   __init__EccKey.__init__Q   s   & v,[[$/
++c4([[.
kk'40$+++**J2S\ABBW$5
BCCj)[[**
DGG4'(3tzz/E+FFA:{{" !jkkA:KLL
 ;;>>X---ww" !RSS4::"$ !STT

4::.557I$S>DLIcN+CFdNF2w~-CG((ADG[[^^x~~-ww" !RSS4::"$ !QRR TZZ055c:I$S>DLIcN+CFdNFGtOGCG((ADG[[^^x222ww" !RSS4::"$ !VWWDJJ'CFdNF2w~-CG((ADG[[^^x000ww" !RSS4::"$ !TUUDJJ'CFdNFGtOG((ADG zz% !UVVdgg&DG3$++"3"33 !^__ 4r    c                    \        V\        4      '       g   R # VP                  4       V P                  4       8w  d   R # VP                  V P                  8H  # )F)
isinstancer#   has_privatepointQ)rH   others   &&r!   __eq__EccKey.__eq__   sB    %(($"2"2"44||t{{**r    c                Z   V P                  4       '       dk   V P                  P                  '       d2   R \        \        P
                  ! V P                  4      4      ,          pMR\        V P                  4      ,          pMRpV P                  P                  \        P                  \        P                  39   d8   V P                  P                  pRV P                  P                  W!3,          pV# V P                  P                   w  r$RV P                  P                  W$V3,          pV# )z	, seed=%sz, d=%d z EccKey(curve='%s', point_x=%d%s)z,EccKey(curve='%s', point_x=%d, point_y=%d%s))rS   r7   
is_edwardsr   binasciihexlifyr2   r9   r1   r:   r;   rE   rF   rT   xr8   xy)rH   extrar]   resultys   &    r!   __repr__EccKey.__repr__   s    {{%%%#eH,<,<TZZ,H&II 3tww</E;;>>h11&//1 1A74;;;P;PRS:[[F  ;;>>DACt{{G\G\^_diFjjFr    c                    V P                   RJ# )zJ``True`` if this key can be used for making signatures or decrypting data.N)r1   rH   s   &r!   rS   EccKey.has_private   s     wwd""r    c                   ^ Tu;8  d   V P                   P                  8  g   Q h Q hV P                   P                  p\        P                  ! ^VR7      pV P                  V,          pWB,          P                  V4      pV P                   P                  V,          P                  V,          pWdV,          WW,          ,           ,          V,          pWx3# )r   )min_inclusivemax_exclusive)r7   rG   r	   random_ranger1   inverseGr]   )	rH   zkrG   blindblind_dinv_blind_krss	   &&&      r!   _signEccKey._sign   s    1(t{{(((((((!!$$138: ''E/y))%0[[]]Q!!E)19w{23e;vr    c                8   V P                   P                  pV^,          P                  V4      pV P                   P                  WA,          V,          ,          pV P                  WB^ ,          ,          V,          ,          pWV,           P
                  V^ ,          8H  # )   )r7   rG   rk   rl   rT   r]   )rH   rm   rsrG   sinvpoint1point2s   &&&    r!   _verifyEccKey._verify   sl    !!!u}}U#48u"451 67""be++r    c                \    V P                  4       '       g   \        R 4      hV P                  # zThis is not a private ECC key)rS   r6   r1   re   s   &r!   r&   EccKey.d   s&    !!<==wwr    c                \    V P                  4       '       g   \        R 4      hV P                  # r   )rS   r6   r2   re   s   &r!   r'   EccKey.seed   s'    !!<==zzr    c                    V P                   f-   V P                  P                  V P                  ,          V n         V P                   # N)r3   r7   rl   r1   re   s   &r!   rT   EccKey.pointQ   s.    ;;++--$''1DK{{r    c                X    \        V P                  P                  V P                  R7      # )zFA matching ECC public key.

Returns:
    a new :class:`EccKey` object
)r%   r(   )r#   r7   r8   rT   re   s   &r!   
public_keyEccKey.public_key   s     DKK11EEr    c                   V P                   P                  '       g   \        R 4      hV P                  P	                  4       pV'       d^   V P                  P
                  P                  4       '       d   RpMRpVV P                  P                  P                  V4      ,           pV# RV P                  P                  P                  V4      ,           V P                  P
                  P                  V4      ,           pV# )z/SEC1 format is only supported for NIST P curves         )	r7   is_weierstrassr6   rT   size_in_bytesra   is_oddr]   to_bytes)rH   compressmodulus_bytes
first_byter   s   &&   r!   _export_SEC1EccKey._export_SEC1  s    {{)))NOO 113{{}}##%%$
$
$++--00?@J  "++--00?@++--00?@J r    c                   V P                   P                  w  rV P                  P                  \        P
                  8X  d?   \        VP                  ^ RR7      4      pV^,          ^,          V^,          ,          V^&   MdV P                  P                  \        P                  8X  d1   \        VP                  ^9RR7      4      pV^,          ^,          V^8&   M\        R4      h\        V4      # )r*   r+   r,   zNot an EdDSA key to export)rT   r^   r7   r:   r;   r<   rA   r   rC   r6   bytes)rH   r]   ra   r`   s   &   r!   _export_eddsa_publicEccKey._export_eddsa_public   s    {{~~;;>>X---qzz"zABFq5Q,&*4F2J[[^^x~~-qzz"zABFa%AF2J9::V}r    c                    V P                   P                  '       g   \        R 4      hV P                  P                  pV P                  P                  4       p\        VP                  VRR7      4      p\        V4      # )zNot a Montgomery key to exportr+   r,   )	r7   is_montgomeryr6   rT   r]   r   rA   r   r   )rH   r]   
field_sizer`   s   &   r!   _export_montgomery_public EccKey._export_montgomery_public,  s^    {{(((=>>KKMM[[..0
1::jH:EFV}r    c                   V P                   P                  '       d*   V P                   P                  pV P                  4       pR pMwV P                   P                  '       d*   V P                   P                  pV P                  4       pR pM2RpV P                  V4      p\        V P                   P                  4      p\        VVV4      # )N1.2.840.10045.2.1)	r7   rZ   oidr   r   r   r   r
   r   )rH   r   r   r   paramss   &&   r!   _export_subjectPublicKeyInfo#EccKey._export_subjectPublicKeyInfo4  s    ;;!!!++//C224JF[[&&&++//C779JF%C**84J 1F.s/9/57 	7r    c                   V P                  4       '       g   Q hV P                  P                  4       pR V P                  P                  P	                  V4      ,           V P                  P
                  P	                  V4      ,           p^\        V P                  P	                  V4      4      \        V P                  P                  ^ R7      \        V^R7      .pV'       g   V^ \        V4      P                  4       # )r   explicit)rS   rT   r   r]   r   ra   r   r&   r
   r7   r   r   r   encode)rH   include_ec_paramsr   r   seqs   &&   r!   _export_rfc5915_private_der"EccKey._export_rfc5915_private_derF  s    !!!! 113kkmm,,];<kkmm,,];<
 dffoom<=4;;??Q7J35
 !A3&&((r    c                   ^ RI Hp VP                  RR4      e   RV9  d   \        R4      hV P                  e=   V P
                  P                  p\        V P                  4      P                  4       pRpM3RpV P                  RR7      p\        V P
                  P                  4      pVP                  ! VV3R	V/VB pV# )
r   PKCS8
passphraseN
protectionz3At least the 'protection' parameter must be presentr   F)r   
key_params)	Crypto.IOr   getr6   r2   r7   r   r   r   r   r
   wrap)rH   rI   r   r   private_keyr   r`   s   &,     r!   _export_pkcs8EccKey._export_pkcs8a  s    #::lD)5,f:TRSS::!++//C(4;;=KF%C::U:SK 1FK&'-& %& r    c                T    ^ RI Hp V P                  V4      pVP                  VR4      # )r   PEMz
PUBLIC KEY)r   r   r   r   )rH   r   r   encoded_ders   &&  r!   _export_public_pemEccKey._export_public_pemv  s&    !77Azz+|44r    c                X    ^ RI Hp V P                  4       pVP                  ! VRV3/ VB # )r   r   zEC PRIVATE KEY)r   r   r   r   rH   r   rI   r   r   s   &&,  r!   _export_private_pemEccKey._export_private_pem|  s,    !668zz+'7NvNNr    c                R    ^ RI Hp V P                  4       pVP                  VR4      # )r   r   zPRIVATE KEY)r   r   r   r   )rH   r   r   s   &  r!   (_export_private_clear_pkcs8_in_clear_pem/EccKey._export_private_clear_pkcs8_in_clear_pem  s$    !((*zz+}55r    c                    ^ RI Hp V'       g   Q hRV9  d   \        R4      hV P                  ! RRV/VB pVP	                  VR4      # )r   r   r   z5At least the 'protection' parameter should be presentr   zENCRYPTED PRIVATE KEYr   )r   r   r6   r   r   r   s   &&,  r!   ,_export_private_encrypted_pkcs8_in_clear_pem3EccKey._export_private_encrypted_pkcs8_in_clear_pem  sK    !zv%TUU((IJI&Izz+'>??r    c                   V P                  4       '       d   \        R 4      hV P                  P                  pVf   \        RV P                  ,          4      hVR8X  d)   V P                  4       p\        V4      \        V4      3pEMV P                  P                  4       pV'       db   ^V P                  P                  P                  4       ,           p\        V4      V P                  P                  P                  V4      ,           pMVRV P                  P                  P                  V4      ,           V P                  P                  P                  V4      ,           pVP                  R4      ^,          p\        V4      \        V4      V3pRP                  V Uu. uF*  p\         P"                  ! R\%        V4      4      V,           NK,  	  up4      p	VR,           \'        \(        P*                  ! V	4      4      ,           # u upi )z"Cannot export OpenSSH private keysz Cannot export %s keys as OpenSSHssh-ed25519r   -r    >I )rS   r6   r7   opensshr%   r   r   rT   r   ra   r   r   r]   r   splitjoinstructpackr=   r   r[   
b2a_base64)
rH   r   descr   compsr   r   middler]   blobs
   &&        r!   _export_opensshEccKey._export_openssh  s   ABB{{""<?$**LMM]"224JT]GJ$78E KK557M!5!5!77
":."kkmm44]CD
 &"kkmm44]CD"kkmm44]CD
 ZZ_Q'FT]GFOZ@ExxF1T3q62Q66FGczE("5"5d";<<< Gs   0Hc                Z   VP                  4       pVP                  R4      pVR9  d   \        RV,          4      hVP                  RR4      pV P                  4       '       Edg   VP                  R	R
4      p\	        V4      '       d   \        V4      pV'       g   \        R4      hVP                  RR4      pVRJ da   V P                  P                  '       d   \        R4      hV P                  P                  '       d   \        R4      hRV9   d   \        R4      hVR8X  dG   V'       d,   V'       d   V P                  ! V3/ VB # V P                  4       # V P                  ! V3/ VB # VR8X  dH   V'       d   V'       g   \        R4      hV'       d   V P                  ! RR	V/VB # V P                  4       # \        RV,          4      hV'       d   \        RV,          4      hVR8X  d   V P                  V4      # VR8X  d   V P                  V4      # VR8X  d   V P!                  V4      # VR8X  dj   V P                  P                  '       d   V P#                  4       # V P                  P                  '       d   V P%                  4       # V P!                  V4      # V P'                  V4      # )a  Export this ECC key.

Args:
  format (string):
    The output format:

    - ``'DER'``. The key will be encoded in ASN.1 DER format (binary).
      For a public key, the ASN.1 ``subjectPublicKeyInfo`` structure
      defined in `RFC5480`_ will be used.
      For a private key, the ASN.1 ``ECPrivateKey`` structure defined
      in `RFC5915`_ is used instead (possibly within a PKCS#8 envelope,
      see the ``use_pkcs8`` flag below).
    - ``'PEM'``. The key will be encoded in a PEM_ envelope (ASCII).
    - ``'OpenSSH'``. The key will be encoded in the OpenSSH_ format
      (ASCII, public keys only).
    - ``'SEC1'``. The public key (i.e., the EC point) will be encoded
      into ``bytes`` according to Section 2.3.3 of `SEC1`_
      (which is a subset of the older X9.62 ITU standard).
      Only for NIST P-curves.
    - ``'raw'``. The public key will be encoded as ``bytes``,
      without any metadata.

      * For NIST P-curves: equivalent to ``'SEC1'``.
      * For Ed25519 and Ed448: ``bytes`` in the format
        defined in `RFC8032`_.
      * For Curve25519 and Curve448: ``bytes`` in the format
        defined in `RFC7748`_.

  passphrase (bytes or string):
    (*Private keys only*) The passphrase to protect the
    private key.

  use_pkcs8 (boolean):
    (*Private keys only*)
    If ``True`` (default and recommended), the `PKCS#8`_ representation
    will be used.
    It must be ``True`` for Ed25519, Ed448, Curve25519, and Curve448.

    If ``False`` and a passphrase is present, the obsolete PEM
    encryption will be used.

  protection (string):
    When a private key is exported with password-protection
    and PKCS#8 (both ``DER`` and ``PEM`` formats), this parameter MUST be
    present,
    For all possible protection schemes,
    refer to :ref:`the encryption parameters of PKCS#8<enc_params>`.
    It is recommended to use ``'PBKDF2WithHMAC-SHA512AndAES128-CBC'``.

  compress (boolean):
    If ``True``, the method returns a more compact representation
    of the public key, with the X-coordinate only.

    If ``False`` (default), the method returns the full public key.

    This parameter is ignored for Ed25519/Ed448/Curve25519/Curve448,
    as compression is mandatory.

  prot_params (dict):
    When a private key is exported with password-protection
    and PKCS#8 (both ``DER`` and ``PEM`` formats), this dictionary
    contains the  parameters to use to derive the encryption key
    from the passphrase.
    For all possible values,
    refer to :ref:`the encryption parameters of PKCS#8<enc_params>`.
    The recommendation is to use ``{'iteration_count':21000}`` for PBKDF2,
    and ``{'iteration_count':131072}`` for scrypt.

.. warning::
    If you don't provide a passphrase, the private key will be
    exported in the clear!

.. note::
    When exporting a private key with password-protection and `PKCS#8`_
    (both ``DER`` and ``PEM`` formats), any extra parameters
    to ``export_key()`` will be passed to :mod:`Crypto.IO.PKCS8`.

.. _PEM:        http://www.ietf.org/rfc/rfc1421.txt
.. _`PEM encryption`: http://www.ietf.org/rfc/rfc1423.txt
.. _OpenSSH:    http://www.openssh.com/txt/rfc5656.txt
.. _RFC5480:    https://tools.ietf.org/html/rfc5480
.. _SEC1:       https://www.secg.org/sec1-v2.pdf
.. _RFC7748:    https://tools.ietf.org/html/rfc7748

Returns:
    A multi-line string (for ``'PEM'`` and ``'OpenSSH'``) or
    ``bytes`` (for ``'DER'``, ``'SEC1'``, and ``'raw'``) with the encoded key.
formatr   DERSEC1rawzUnknown format '%s'r   Fr   NzEmpty passphrase	use_pkcs8Tz%'pkcs8' must be True for EdDSA curvesz#'pkcs8' must be True for Curve25519r   z)'protection' is only supported for PKCS#8z8Private keys can only be encrpyted with DER using PKCS#8z2Private keys cannot be exported in the '%s' formatzUnexpected parameters: '%s')r   r   OpenSSHr   r   r   )copyr0   r6   rS   r   r   r7   rZ   r   r   r   r   r   r   r   r   r   r   r   r   )rH   rI   args
ext_formatr   r   r   s   &,     r!   
export_keyEccKey.export_key  sd   t {{}XXh'
EE2Z?@@88J.,5J$$$Z0
!$%788d3IE!;;)))$%LMM;;,,,$%JKK4'$%PQQU"!#PPQ[d_cdd#LLNN33JG$GGu$i$%_``--LLtLL;;==  "68B"C D D  !>!EFFU"..x88u$88BBv%((22u$;;)))4466[[...99;;,,X66++H55r    )r7   r1   r3   r@   r2   r%   N)T)r   r   r   r   __doc__rO   rV   rb   rS   rt   r|   propertyr&   r'   rT   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classdictcell__)__classdict__s   @r!   r#   r#   ;   s     *``D+"#,  
  
  
F8
7$)6*5O6@=:U6 U6r    r#   c                    V P                  R4      p\        V,          pV P                  R\        4      pV '       d   \        R\	        V 4      ,           4      h\        V,          P
                  \        P                  8X  d   V! ^ 4      p\        WR7      pV# \        V,          P
                  \        P                  8X  d   V! ^94      p\        WR7      pV# \        V,          P
                  \        P                  8X  d=   V! ^ 4      p\        WR7      p\        V,          P                  VP                  4       V# \        V,          P
                  \        P                  8X  d=   V! ^84      p\        WR7      p\        V,          P                  VP                  4       V# \        P                  ! ^VP                   VR7      p\        WR7      pV# )a  Generate a new private key on the given curve.

Args:

  curve (string):
    Mandatory. It must be a curve name defined in the `ECC table`_.

  randfunc (callable):
    Optional. The RNG to read randomness from.
    If ``None``, :func:`Crypto.Random.get_random_bytes` is used.
r%   randfuncr)   r%   r'   )rh   ri   r   )r%   r&   )r0   r   r   r4   r5   r:   r;   r<   r#   rC   rE   validaterT   rF   r	   rj   rG   )rI   rK   r%   r   r'   new_keyr&   s   ,      r!   generater   F  sr    G$JJEzz*&67H.V<==z!1!11|z5$ N# 
			8>>	1|z5 N 
			8#6#6	6|z5
$$W^^4 N 
			8#4#4	4|z5
$$W^^4 N   q/4{{*24 z/Nr    c                    V R,          p\         V,          pV P                  RR4      pV P                  RR4      pRV 9   d   \        R4      hVP                  \        P
                  8X  d;   Ve   \        W14      V R&   \        R/ V B pVP                  VP                  4       V# VP                  \        P                  8X  d;   Ve   \        W14      V R&   \        R/ V B pVP                  VP                  4       V# RW439  d   \        W4V4      V R&   \        R/ V B pVP                  4       '       dB   RV 9   d;   VP                  VP                  ,          pVP                  W438w  d   \!        R4      hV# )	ay  Build a new ECC key (private or public) starting
from some base components.

In most cases, you will already have an existing key
which you can read in with :func:`import_key` instead
of this function.

Args:
  curve (string):
    Mandatory. The name of the elliptic curve, as defined in the `ECC table`_.

  d (integer):
    Mandatory for a private key and a NIST P-curve (e.g., P-256).
    It must be an integer in the range ``[1..order-1]``.

  seed (bytes):
    Mandatory for a private key and curves Ed25519 (32 bytes),
    Curve25519 (32 bytes), Curve448 (56 bytes) and Ed448 (57 bytes).

  point_x (integer):
    The X coordinate (affine) of the ECC point.
    Mandatory for a public key.

  point_y (integer):
    The Y coordinate (affine) of the ECC point.
    Mandatory for a public key,
    except for Curve25519 and Curve448.

Returns:
  :class:`EccKey` : a new ECC key object
r%   point_xNpoint_yr(   zUnknown keyword: pointz(Private and public ECC keys do not matchr   )r   r0   r4   r:   r;   rE   r   r#   r   rT   rF   r   rS   rl   r&   r^   r6   )rI   rK   r%   r   r   r   pub_keys   ,      r!   	constructr   p  sV   B JJEjjD)GjjD)G&011xx8&&&'<F7O"6"w~~&, N) 
X&&	&'<F7O"6"w~~& N ))&wDF7O"6"   W%6gg		)Gzzg// !KLLNr    c                   \         P                  ! 4        F(  w  r4V'       d   VP                  V8X  d    M8W#8X  g   K(   M.	  V'       d   \        RV,          4      h\        RV,          4      hVP                  P                  4       p\        V ^ ,          4      pV^8X  dj   \        V 4      ^^V,          ,           8w  d   \        R4      h\        P                  ! V ^V^,            4      p\        P                  ! W^,           R 4      pMVR9   d   \        V 4      ^V,           8w  d   \        R4      h\        P                  ! V R,          4      pV^,          V^,          ,
          VP                  ,           P                  VP                  4      pV^8X  d*   VP                  4       '       d   VP                  V,
          pV^8X  d*   VP                  4       '       d   VP                  V,
          pM\        R4      h\        W7VR7      # )	zConvert an encoded EC point into an EccKey object

ec_point: byte string with the EC point (SEC1-encoded)
curve_oid: string with the name the curve
curve_name: string with the OID of the curve

Either curve_id or curve_name must be specified

Unsupported ECC curve (OID: %s)zUnsupported ECC curve (%s)zIncorrect EC point lengthN:rw   NNzIncorrect EC point encodingr%   r   r         )r   itemsr   r   pr   r   r=   r6   r	   rB   bsqrtr   is_evenr   )	ec_point	curve_oidrK   _curve_namer%   r   
point_typer]   ra   s	   &&&      r!   _import_public_derr    s    &mmoi/$	 . '(II(UVV'(Dz(QRR GG))+Mhqk"J Tx=Q]!223899x-/:;xa(89:	|	#x=Q./899x|,TAaCZ%''!''0!((**!A!))++!A677;1==r    c                `   \        V 4      w  r#pRpRR\        3RR\        3/pRR\        3RR\        3/pW%9   dK   V'       g   \        R	V,          4      h \        4       P                  V4      P                  p\        Y8R7      # W&9   d<   Wb,          w  rV'       d   \        RV,          4      hV
! V4      w  r\        WV	R7      # W'9   d9   Wr,          w  rV'       d   \        RV,          4      hV! V4      p\        WR7      # \        RV,          4      h  \
         d    \        R
4      hi ; i)z4Convert a subjectPublicKeyInfo into an EccKey object1.3.101.112Ed255191.3.101.113Ed4481.3.101.110
Curve255191.3.101.111Curve448z%Missing ECC parameters for ECC OID %szError decoding namedCurver  z(Unexpected ECC parameters for ECC OID %s)r   r   r%   )r   r%   zUnsupported ECC OID: %sr   z1.3.132.1.12z1.3.132.1.13)r   _import_ed25519_public_key_import_ed448_public_key_import_curve25519_public_key_import_curve448_public_keyr6   r
   decodevaluer  r   r   )encodedrI   r   r   r   nist_p_oids
eddsa_oidsxdh_oidsr  rK   import_eddsa_public_keyr]   ra   import_xdh_public_keys   &*            r!   _import_subjectPublicKeyInfor    sI    <GDC6K 		#=>#;<J
 	&CD
$?@H
  DsJKK	:#,,V4::I
 "(@@		.8o+
 G#MNN&x0Z@@	,4M)
 G#MNN!(+55 $$=$CDD9  	:899	:s   #D D-c                    \        4       P                  V RR7      pV^ ,          ^8w  d   \        R4      h\        4       P                  V^,          4      P                  p^pV\        V4      8  dM    \        ^ R7      P                  W5,          4      P                  pVe   Wb8w  d   \        R4      hTpV^,          pVf   \        R4      h\        P                  ! 4        F  w  rxVP                  V8X  g   K   M	  \        RV,          4      hVP                  P                  4       p	\        V4      V	8w  d   \        R4      hR;rV\        V4      8  dn    \        ^R7      P                  W5,          4      P                  p\        WR	7      pVP                   P"                  p
VP                   P$                  pV^,          p\&        P(                  ! V4      p\+        W~WR
7      #   \         d     EL8i ; i  \         d     LBi ; i)r   )nr_elementsz!Incorrect ECC private key versionr   NzCurve mismatchzNo curve foundr   zPrivate key is too smallr  )r%   r&   r   r   r   r      )r   r  r6   r   payloadr=   r
   r  r   r   r   r   r   r   r   r  rT   r]   ra   r	   rB   r   )r  r   r  ec_private_keyscalar_bytesnext_element
parametersrK   r%   r   r   r   public_key_encr   r&   s   &&&            r!   _import_rfc5915_derr'  2  s    !]))'y)INaA<==!#**>!+<=EELL c.))	$a0778TU[[J$)@ !122"IAL )**$]]_
99	! - $$E	$QRRGG))+M
<M)344 Gc.))	)15<<^=YZ``N+NPJ ''))G ''))GAL 	<(A:GMM;  		2  		s&   2AG' A,G9 'G65G69HHc                 2   ^ RI Hp VP                  W4      w  r4pRpRRRR/pRRRR	/pW69   d0   \        4       P	                  V4      P
                  p	\        WAV	4      # W79   dH   Ve   \        R4      hR
p	\        4       P	                  V4      P                  p
\        Ws,          V
R7      # W89   dW   W,          pVe   \        RV,          4      hR
p	\        4       P	                  V4      P                  p
\        W,          V
R7      # \        RV,          4      h)r   r   r  r  r  r	  r
  r  r  r  Nz.EdDSA ECC private key must not have parametersr   z+%s ECC private key must not have parametersz!Unsupported ECC purpose (OID: %s)r  )r   r   unwrapr
   r  r  r'  r6   r   r!  r   r   )r  r   r   algo_oidr   r   r  r  r  r  r'   rK   s   &&          r!   _import_pkcs8r+  m  s#   $)LL$E!H6K 	ywJ
 	|zH
 M((066	";IFF		MNN	&&{3;;z3$??		'
J'( ) )	&&{3;;x1==#$G($RSSr    c                 .    \        V 4      p\        V4      # r   )r   r  )r  rI   sp_infos   &* r!   _import_x509_certr.    s    .w7G'00r    c                     \        W4      #   \         d   pThR p?i\        \        \        3 d     Mi ; i \        Y4      #   \         d   pThR p?i\        \        \        3 d     Mi ; i \        Y4      #   \         d   pThR p?i\        \        \        3 d     Mi ; i \        Y4      #   \         d   pThR p?i\        \        \        3 d     Mi ; i\        R4      h)NzNot an ECC DER key)r  r   r6   r4   
IndexErrorr.  r'  r+  )r  r   errs   && r!   _import_derr2    s    +G@@  		:.  55  		:. "777  		:. W11  		:.  )
**s   
 6666
A A.AA.*A.-A.2
A= =B&B

B&"B&%B&*
B5 5C CCCCc                 \   V P                  R 4      p\        V4      R9  d   \        R4      h \        P                  ! V^,          4      p. p\        V4      ^8  dO   \
        P                  ! RVR,          4      ^ ,          pVP                  V^^V,            4       V^V,           R pK^  V^ ,          V^ ,          8w  d   \        R4      hV^ ,          P                  R4      '       d   \        P                  ! 4        Fs  w  rVVP                  f   K  VP                  P                  R4      '       g   K8  \        VP                  P                  R4      ^,          4      pV^,          V8X  g   Ks   M	  \        R	X,           4      h\        V^,          VP                  R
7      pV# V^ ,          R8X  d$   \        V^,          4      w  r\!        RWR7      pV# \        RV^ ,          ,           4      h  \"        \$        \        P&                  3 d    \        RT^ ,          ,           4      hi ; i)    zNot an openssh public keyr   :Nr   NNzMismatch in openssh public key   ecdsa-sha2-
ecdsa-sha2r   zUnsupported ECC curve: r     ssh-ed25519r  r   zUnsupported SSH key type: zError parsing SSH key type: r   )r   r=   r6   r[   
a2b_base64r   unpackappend
startswithr   r   r   r   r  r   r  r   r0  r4   Error)r  parts	keystringkeypartslkrK   r%   r   ecc_keyr]   ra   s   &          r!   _import_openssh_publicrB    s   MM$E
5z455$D''a1	)nq tYr]3A6BOOIaB/0!!b&'*I8x{"=>> 8~..%,]]_!
==(}}//== !4!4S!9!!<=A;&( &5 !!:V!CDD(!		JG N 1X'-hqk:DAiFG N 9E!HDEE	8>>2 D7%(BCCDs+   B:G1 )A
G1 48G1 14G1 '/G1 G1 1:H+c                 j   ^RI HpHpHpHp V! W4      w  rgRR\
        ^ 3/pVP                  R4      '       Ed   V! V4      w  rV	\        9  d   \        RV	,          4      h\        V	,          p
V
P                  ^,           ^,          pV! V4      w  r\        V^ ,          4      ^8w  d   \        R4      h\        V4      ^V,          ^,           8w  d   \        R4      h\        P                  ! V^^V,            4      p\        P                  ! V^V,           R 4      pV! V4      w  r\        P                  ! V4      pR	VR
V	/pMOWh9   d8   W,          w  pppV! V4      w  rV! V4      w  rV! V4      w  ppVRV pRVR
V/pM\        RV,           4      hV! V4      w  ppV! V4       \        RRVRV/VB # )rw   )import_openssh_private_generic
read_bytesread_stringcheck_paddingr   r  r6  zUnsupported ECC curve %sz/Only uncompressed OpenSSH EC keys are supportedzIncorrect public key lengthNr&   r%   r'   zUnsupport SSH agent key type:r   r   r   )_opensshrD  rE  rF  rG  r  r;  r   r   modulus_bitsr   r6   r=   r	   rB   r   )datapasswordrD  rE  rF  rG  key_type	decrypted
eddsa_keysecdsa_curve_namer%   r   r   r   r   r   r&   r   rK   r  seed_lenprivate_public_keyr'   _paddeds   &&                       r!   _import_openssh_private_eccrT    s   C C 9HH 		#=rBJ
 <((&1)&<#7*'(BEU(UVV()++a/A5 *9 5

1!#NOOz?a-/!33:;;$$Z!M/%BC$$Z-0@%AB!+I!6{+q'#34		8B8L5
+X *9 5
2:>(29(=%I!)8,$488CDDI&IAv&@W@g@@@r    c                b   \        V 4      ^ 8w  d   \        R4      h\        R4      pRp\        V 4      pV^,          ^,	          pV^;;,          ^,          uu&   \        P                  ! VRR7      pWQ8  d   \        R4      hV^8X  d   R# V^,          ^,
          V,          pV^,          V,          V,          ^,           V,          p VP                  V4      pWh,          V,          p	\        P                  ! W4      p
V
^,          V8w  d	   W,
          p
W3#   \         d    \        R4      hi ; i)	aA  Import an Ed25519 ECC public key, encoded as raw bytes as described
in RFC8032_.

Args:
  encoded (bytes):
    The Ed25519 public key to import. It must be 32 bytes long.

Returns:
  x and y (integer)

Raises:
  ValueError: when the given key cannot be parsed.

.. _RFC8032: https://datatracker.ietf.org/doc/html/rfc8032
z9Incorrect length. Only Ed25519 public keys are supported.l   l   x&(7Z/
;(P8 se:8
w6Rr+   r,   zInvalid Ed25519 key (y)zInvalid Ed25519 public keyr   rw   )r=   r6   r	   rA   rB   rk   _tonelli_shanksr  r   r&   ra   x_lsbr   uvv_invx2r   s   &          r!   r  r  !  s   " 7|rTUURSAUA'AbEQJEbETME  h7G|233!|	!a1A
1*q.A		!Q&A7		!i1_))"0aKE!kG   75667s   AD D.c                    \        V 4      ^ 8w  d   \        R4      h\        V 4      pV^;;,          ^,          uu&   \        P                  ! VRR7      pV# )a@  Import a Curve25519 ECC public key,
encoded as raw bytes as described in RFC7748_.

Args:
  encoded (bytes):
    The Curve25519 public key to import. It must be 32 bytes long.

Returns:
  x (integer)

Raises:
  ValueError: when the given key cannot be parsed.

.. _RFC7748: https://datatracker.ietf.org/doc/html/rfc7748
zIncorrect Curve25519 key lengthr+   r,   )r=   r6   rA   r	   rB   )r  r]   r   s   &  r!   r  r  N  sJ    " 7|r:;;'AbETME  h7GNr    c                l    \        V 4      ^88w  d   \        R4      h\        P                  ! V RR7      pV# )a<  Import a Curve448 ECC public key,
encoded as raw bytes as described in RFC7748_.

Args:
  encoded (bytes):
    The Curve448 public key to import. It must be 56 bytes long.

Returns:
  x (integer)

Raises:
  ValueError: when the given key cannot be parsed.

.. _RFC7748: https://datatracker.ietf.org/doc/html/rfc7748
zIncorrect Curve448 key lengthr+   r,   )r=   r6   r	   rB   )r  r   s   & r!   r  r  j  s3    " 7|r899  H=GNr    c                l   \        V 4      ^98w  d   \        R4      h\        R,          P                  pVR,
          pV R,          p\	        V ^8,          4      ^,	          p\
        P                  ! VRR7      pWQ8  d   \        R4      hV^8X  d   R	# V^,          ^,
          V,          pV^,          V,          V,          ^,
          V,          p VP                  V4      pWh,          V,          p	\
        P                  ! W4      p
V
^,          V8w  d	   W,
          p
W3#   \         d    \        R4      hi ; i)
a?  Import an Ed448 ECC public key, encoded as raw bytes as described
in RFC8032_.

Args:
  encoded (bytes):
    The Ed448 public key to import. It must be 57 bytes long.

Returns:
    x and y (integer)

Raises:
  ValueError: when the given key cannot be parsed.

.. _RFC8032: https://datatracker.ietf.org/doc/html/rfc8032
z7Incorrect length. Only Ed448 public keys are supported.curve448i  :N8   Nr+   r,   zInvalid Ed448 key (y)zInvalid Ed448 public keyrV  )	r=   r6   r   r   r   r	   rB   rk   rW  rX  s   &          r!   r  r    s   " 7|rRSS
A	E	AA"E  h7G|011!|	!a1A
1*q.A		!Q&A5		!i1_))"0aKE!kG   53445s   AD D3c                n   ^ RI Hp \        V 4      p Ve   \        V4      pV P                  R4      '       d-   \	        V 4      pVP                  WA4      w  rVp\        WQ4      pV# V P                  R4      '       dr   \	        V 4      pRp	Rp
\        P                  ! V	R,           V
,           RV\        P                  R	7      pVP                  WA4      w  rpV'       d   Rp \        W4      pV# V P                  R4      '       d   \        V 4      # \        V 4      ^ 8  d#   \        V ^ ,          4      ^08X  d   \        W4      # \        V 4      ^ 8  d3   \        V ^ ,          4      R9   d   Vf   \        R4      h\!        WR7      # \        R4      h  \         d   pThRp?i\         d    \        R
4      hi ; i)a
  Import an ECC key (public or private).

Args:
  encoded (bytes or multi-line string):
    The ECC key to import.
    The function will try to automatically detect the right format.

    Supported formats for an ECC **public** key:

    * X.509 certificate: binary (DER) or ASCII (PEM).
    * X.509 ``subjectPublicKeyInfo``: binary (DER) or ASCII (PEM).
    * SEC1_ (or X9.62), as ``bytes``. NIST P curves only.
      You must also provide the ``curve_name`` (with a value from the `ECC table`_)
    * OpenSSH line, defined in RFC5656_ and RFC8709_ (ASCII).
      This is normally the content of files like ``~/.ssh/id_ecdsa.pub``.

    Supported formats for an ECC **private** key:

    * A binary ``ECPrivateKey`` structure, as defined in `RFC5915`_ (DER).
      NIST P curves only.
    * A `PKCS#8`_ structure (or the more recent Asymmetric Key
      Package, RFC5958_): binary (DER) or ASCII (PEM).
    * `OpenSSH 6.5`_ and newer versions (ASCII).

    Private keys can be in the clear or password-protected.

    For details about the PEM encoding, see `RFC1421`_/`RFC1423`_.

  passphrase (byte string):
    The passphrase to use for decrypting a private key.
    Encryption may be applied protected at the PEM level (not recommended)
    or at the PKCS#8 level (recommended).
    This parameter is ignored if the key in input is not encrypted.

  curve_name (string):
    For a SEC1 encoding only. This is the name of the curve,
    as defined in the `ECC table`_.

.. note::

    To import EdDSA private and public keys, when encoded as raw ``bytes``, use:

    * :func:`Crypto.Signature.eddsa.import_public_key`, or
    * :func:`Crypto.Signature.eddsa.import_private_key`.

.. note::

    To import X25519/X448 private and public keys, when encoded as raw ``bytes``, use:

    * :func:`Crypto.Protocol.DH.import_x25519_public_key`
    * :func:`Crypto.Protocol.DH.import_x25519_private_key`
    * :func:`Crypto.Protocol.DH.import_x448_public_key`
    * :func:`Crypto.Protocol.DH.import_x448_private_key`

Returns:
  :class:`EccKey` : a new ECC key object

Raises:
  ValueError: when the given key cannot be parsed (possibly because
    the pass phrase is wrong).

.. _RFC1421: https://datatracker.ietf.org/doc/html/rfc1421
.. _RFC1423: https://datatracker.ietf.org/doc/html/rfc1423
.. _RFC5915: https://datatracker.ietf.org/doc/html/rfc5915
.. _RFC5656: https://datatracker.ietf.org/doc/html/rfc5656
.. _RFC8709: https://datatracker.ietf.org/doc/html/rfc8709
.. _RFC5958: https://datatracker.ietf.org/doc/html/rfc5958
.. _`PKCS#8`: https://datatracker.ietf.org/doc/html/rfc5208
.. _`OpenSSH 6.5`: https://flak.tedunangst.com/post/new-openssh-key-format-and-bcrypt-pbkdf
.. _SEC1: https://www.secg.org/sec1-v2.pdf
r   Ns   -----BEGIN OPENSSH PRIVATE KEYs   -----z-----BEGIN EC PARAMETERS-----z-----END EC PARAMETERS-----z.*?rY   )flagsz(Invalid DER encoding inside the PEM filezNo curve name was provided)rK   zECC key format is not supported)r5  r7  r  )r   r   r   r;  r   r  rT  resubDOTALLr2  r   r6   rB  r=   r   r  )r  r   rK   r   text_encodedopenssh_encodedmarkerenc_flagr`   ecparams_startecparams_endder_encodeduefs   &&&          r!   
import_keyrp    s   R gGZ(
 ;<<W~,/JJ|,P),_I			H	%	%W~ 94vvnu4|CR*$&II/ ),

<(L%XJ	I 9F
  :;;%g.. 7|aD,47// 7|aD,0BB9::!'AA
6
77) % 	I 	IGHH	Is   F F4FF4'F4__main__l   _,)N$chKf-5lk<Xk#E p256i  z	(P-256 G)i  msz(P-256 arbitrary point))NNr   )@
__future__r   re  r   r[   Crypto.Util.py3compatr   r   r   r   r   Crypto.Math.Numbersr	   Crypto.Util.asn1r
   r   r   r   Crypto.PublicKeyr   r   r   Crypto.Hashr   r   Crypto.Randomr   r3   r   r   r   r   r;   r6   r   objectr#   r   r   r  r  r'  r+  r.  r2  rB  rT  r  r  r  r  rp  r   timer&   rl   r   r(   rL   startranger]   pointXprintr   r    r!   <module>r     sw  > & 	   G G ', ,@ @ ) * 0 0 '	J 	H6V H6V'TDN5>p@EF8Nv%TP1+B+\4An*Z82)X{8| zJAFO""$EEIIKE5\ 	+		e+u4t;TBIIKE5\! 	
#diikE&9U%BT%I4P# r    