ff ddlmZddlZddlZddlZddlmZddlmZm Z m Z m Z m Z ddl mZmZddlmZddlmZmZmZmZddlmZmZmZmZmZmZmZdd lm Z m!Z!m"Z"dd l#m$Z$m%Z%dd l&m'Z'dd l(m)Z)ed dZ*eddZ+eddZ,dZ-eddZ.iZ/gda0dZ1e1[1gda2dZ3e3[3gda4dZ5e5[5gda6dZ7e7[7gda8dZ9e9[9d d!ga:d"Z;e;[;d#d$gaZ?Gd(d)e@ZAeAe/d*jBe/d*jCd*ZDe/d*EeD+ZFe/GeHIt`eF[D[Fb0eAe/d,jBe/d,jCd,ZJe/d,EeJ+ZKe/GeHItdeK[J[Kb2eAe/d-jBe/d-jCd-ZLe/d-EeL+ZMe/GeHItheM[L[Mb4eAe/d.jBe/d.jCd.ZNe/d.EeN+ZOe/GeHItleO[N[Ob6eAe/d/jBe/d/jCd/ZPe/d/EeP+ZQe/GeHItpeQ[P[Qb8eAe/d!jBe/d!jCd!ZRe/d!EeR+ZSe/GeHItteS[R[Sb:eAe/d$jBe/d$jCd$ZTe/d$EeT+ZUe/GeHItxeU[T[Ub<Gd0d1e@ZVd2ZWd3ZXdFd4ZYd5ZZdGd6Z[d7Z\d8Z]d9Z^d:Z_d;Z`d<Zad=ZbdFd>Zcedd?krddleZed@Zfe/d-jghZidAZjeejeZkelejD]ZmeiefzZneodBeejeekz ejz dCzdDeejeZkelejD]ZmenefzZneodEeejeekz ejz dCzdDdSdS)H)print_functionN) namedtuple)bordtobytestostrbchr is_string) bytes_to_long long_to_bytes)Integer) DerObjectIdDerOctetString DerSequence DerBitString)load_pycryptodome_raw_lib VoidPointer SmartPointerc_size_t c_uint8_ptr c_ulonglong null_pointer)_expand_subject_public_key_info_create_subject_public_key_info _extract_subject_public_key_info)SHA512SHAKE256)get_random_bytes) getrandbitszCrypto.PublicKey._ec_wsa typedef void EcContext; typedef void EcPoint; int ec_ws_new_context(EcContext **pec_ctx, const uint8_t *modulus, const uint8_t *b, const uint8_t *order, size_t len, uint64_t seed); void ec_free_context(EcContext *ec_ctx); int ec_ws_new_point(EcPoint **pecp, const uint8_t *x, const uint8_t *y, size_t len, const EcContext *ec_ctx); void ec_ws_free_point(EcPoint *ecp); int ec_ws_get_xy(uint8_t *x, uint8_t *y, size_t len, const EcPoint *ecp); int ec_ws_double(EcPoint *p); int ec_ws_add(EcPoint *ecpa, EcPoint *ecpb); int ec_ws_scalar(EcPoint *ecp, const uint8_t *k, size_t len, uint64_t seed); int ec_ws_clone(EcPoint **pecp2, const EcPoint *ecp); int ec_ws_cmp(const EcPoint *ecp1, const EcPoint *ecp2); int ec_ws_neg(EcPoint *p); zCrypto.PublicKey._ed25519ai typedef void Point; int ed25519_new_point(Point **out, const uint8_t x[32], const uint8_t y[32], size_t modsize, const void *context); int ed25519_clone(Point **P, const Point *Q); void ed25519_free_point(Point *p); int ed25519_cmp(const Point *p1, const Point *p2); int ed25519_neg(Point *p); int ed25519_get_xy(uint8_t *xb, uint8_t *yb, size_t modsize, Point *p); int ed25519_double(Point *p); int ed25519_add(Point *P1, const Point *P2); int ed25519_scalar(Point *P, const uint8_t *scalar, size_t scalar_len, uint64_t seed); zCrypto.PublicKey._ed448a* typedef void EcContext; typedef void PointEd448; int ed448_new_context(EcContext **pec_ctx); void ed448_context(EcContext *ec_ctx); void ed448_free_context(EcContext *ec_ctx); int ed448_new_point(PointEd448 **out, const uint8_t x[56], const uint8_t y[56], size_t len, const EcContext *context); int ed448_clone(PointEd448 **P, const PointEd448 *Q); void ed448_free_point(PointEd448 *p); int ed448_cmp(const PointEd448 *p1, const PointEd448 *p2); int ed448_neg(PointEd448 *p); int ed448_get_xy(uint8_t *xb, uint8_t *yb, size_t len, const PointEd448 *p); int ed448_double(PointEd448 *p); int ed448_add(PointEd448 *P1, const PointEd448 *P2); int ed448_scalar(PointEd448 *P, const uint8_t *scalar, size_t scalar_len, uint64_t seed); c|jjdkrttd|z}nA|jjdkrttd|z}ntt d|z}|S)NEd25519ed25519_Ed448ed448_ec_ws_)_curvedescgetattr _ed25519_lib _ed448_lib_ec_lib)ecc_obj func_nameresults v/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/PublicKey/ECC.pylib_funcr/sg~i''zI'=>>   ' 'X %9::(Y"677 M_Curvez

E ;B ;B B''L 1b ! !Fub))J!mmO  & &'A'A'C'C'2<'@'@'26':':'2:'>'>'/L0A0A'B'B'2;r??'C'C ))FJ?&HIII?..00'2IJJG '!**!**%.."++"++''  D NN4==T2233333r0)p224 NIST P-224zP-224 prime224v1 secp224r1nistp224cTd}d}d}d}d}t|d}t|d}t|d}t}t|t |t |t |t t|ttd} | rtd| zt| tj } tt|t|t|t|t|dd d | d d d } t t$t(| dS)Nl?lF eY8 w-X"PVd/%PP!-l=*8%(?l!"X!#BXtJ9!'|%VA-l4~ f&Dv@h!fE0m9_ qlM/r9z#Error %d initializing P-224 contextz 1.3.132.0.33rRzecdsa-sha2-nistp224rQ)r rr*r;r<rrr=rrr>rr?r@r1r rArBrCrD p224_names) rFrGrHrIrJ p224_modulusp224_b p224_orderec_p224_contextr-rOrQs r. init_p224r^snBABA FE CB CB B''L 1b ! !Fub))J!mmO  & &'A'A'C'C'2<'@'@'26':':'2:'>'>'/L0A0A'B'B'2;r??'C'C ))FJ?&HIII?..00'2IJJG '!**!**%.."++"++ '  D NN4==T2233333r0)p256 NIST P-256zP-256 prime256v1 secp256r1nistp256cTd}d}d}d}d}t|d}t|d}t|d}t}t|t |t |t |t t|ttd} | rtd| zt| tj } tt|t|t|t|t|dd d | d d d } t t$t(| dS)Nl?@lK`Opq^cv 3,e< 1U]>{|R*ZlQ%x +Ohbi+}s@lB11e %:f=K`wrH7gHK8hklQ~o]l+fUg+<)Z?8O?q!O r9z#Error %d initializing P-256 contextz1.2.840.10045.3.1.7r`zecdsa-sha2-nistp256r_)r rr*r;r<rrr=rrr>rr?r@r1r rArBrCrD p256_names) rFrGrHrIrJ p256_modulusp256_b p256_orderec_p256_contextr-rOr_s r. init_p256rlsnJAJA NE KB KB B''L 1b ! !Fub))J!mmO  & &'A'A'C'C'2<'@'@'26':':'2:'>'>'/L0A0A'B'B'2;r??'C'C ))FJ?&HIII?..00'2IJJG '!**!**%.."++"++''  D NN4==T2233333r0)p384 NIST P-384zP-384 prime384v1 secp384r1nistp384cTd}d}d}d}d}t|d}t|d}t|d}t}t|t |t |t |t t|ttd} | rtd| zt| tj } tt|t|t|t|t|dd d | d d d } t t$t(| dS)Nl~l*'#.TEbc+Z'@=D 1 "(?7N2Z_+|S/1fls)e`gwl X_[nlv|l dxRjoyU8T( :ss"nZL8k&"_Ul_!uR/sX0 @qaNQNB&JxS8KJEY K%l0r9z#Error %d initializing P-384 contextiz 1.3.132.0.34rnzecdsa-sha2-nistp384rm)r rr*r;r<rrr=rrr>rr?r@r1r rArBrCrD p384_names) rFrGrHrIrJ p384_modulusp384_b p384_orderec_p384_contextr-rOrms r. init_p384ry0snjAjA nE kB kB B''L 1b ! !Fub))J!mmO  & &'A'A'C'C'2<'@'@'26':':'2:'>'>'/L0A0A'B'B'2;r??'C'C ))FJ?&HIII?..00'2IJJG '!**!**%.."++"++ '  D NN4==T2233333r0)p521 NIST P-521zP-521 prime521v1 secp521r1nistp521cTd}d}d}d}d}t|d}t|d}t|d}t}t|t |t |t |t t|ttd} | rtd| zt| tj } tt|t|t|t|t|dd d | d d d } t t$t(| dS)Nl#l#?VQ(zO%b95~cte1oR{V;LH w>l-rZE]"Sr&Ga9}*Fl# dp"z\}[z3"nZ;PK# `7roCQl#f=xK)H-apY$3^Q n%k{;/K!u{4-{?$Od8V1l3s: l#Pf?QE$XN!85aZU WL9YLhz f$Du13otc!% pMxjRr`Br9z#Error %d initializing P-521 contexti z 1.3.132.0.35r{zecdsa-sha2-nistp521rz)r rr*r;r<rrr=rrr>rr?r@r1r rArBrCrD p521_names) rFrGrHrIrJ p521_modulusp521_b p521_orderec_p521_contextr-rOrzs r. init_p521r_s} SA SA WE TB TB B''L 1b ! !Fub))J!mmO  & &'A'A'C'C'2<'@'@'26':':'2:'>'>'/L0A0A'B'B'2;r??'C'C ))FJ?&HIII?..00'2IJJG '!**!**%.."++"++ '  D NN4==T2233333r0ed25519r c"d}d}d}d}tt|dt|t|t|ddddddd }ttt |dS) NlS9i @eM^w|olUK5J,{$%Xci\-G' lJ[sii!lXfL33ffL33ffL33ffL33ff 1.3.101.112r ssh-ed25519r)r1r rArBrCrD ed25519_names)rFrHrIrJrs r. init_ed25519rsJA NE KB KBWQZZU^^R[[R[[""   G NN4==8899999r0ed448r"cd}d}d}d}t}t|}|rt d|zt |tj}tt|dt|t|t|ddd|ddd }t t t|dS) N?lDVJ Ru8a6!m,&vD}D2_l^@ 518`b8Cl\p*At(qmj.<+FaS[/SDZ74_3  lzadoeC@ ZK^DsxssZhNx02>Ilq2 vIZu gt' z#Error %d initializing Ed448 contexti 1.3.101.113r"r)rr)ed448_new_contextr<r>rr?ed448_free_contextr1r rArBrCrD ed448_names)rFrHrIrJ ed448_contextr-rOrs r. init_ed448rszA ~E {B {BMMM  ) )-*B*B*D*D E EF J?&HIII=,,.. 0MNNG 71::5>>2;;2;;   E NN4==e4455555r0ceZdZdS)UnsupportedEccFeatureN)__name__ __module__ __qualname__r0r.rrsDr0rceZdZdZddZdZdZdZdZdZ d Z d Z d Z e d Ze d Ze dZdZdZdZdZdZdZdZdZdS)EccPointaPA class to model a point on an Elliptic Curve. The class supports operators for: * Adding two points: ``R = S + T`` * In-place addition: ``S += T`` * Negating a point: ``R = -T`` * Comparing two points: ``if S == T: ...`` or ``if S != T: ...`` * Multiplying a point by a scalar: ``R = S*k`` * In-place multiplication by a scalar: ``T *= k`` :ivar x: The affine X-coordinate of the ECC point :vartype x: integer :ivar y: The affine Y-coordinate of the ECC point :vartype y: integer :ivar xy: The tuple with affine X- and Y- coordinates r_c t||_n-#t$r tdt |zwxYw||_|}t||}t||}t||kst||krtdt|d}t|d}t|_ |jj } n#t$r t} YnwxYw||j t#|t#|t%|| } | r'| dkrtdtd| zt'|j ||_ dS)NzUnknown curve name %szIncorrect coordinate length new_point free_pointz)The EC point does not belong to the curvez(Error %d while instantiating an EC point)rAr%KeyError ValueErrorstr _curve_name size_in_bytesr r=r/r_pointrOr?AttributeErrorrr<rrr) selfxycurve modulus_bytesxbybr free_funcrOr-s r.__init__zEccPoint.__init__s C!%.DKK C C C4s5zzABB B C **,, 1m , , 1m , , r77m # #s2ww-'?'?:;; ;T;// T<00 !mm  #k)--//GG # # #"GGG #4;1133&r??&r??#M22" $$  R|| !LMMMG&PQQ Q#4;??#4#4i@@ s*?&DDDc`t|d}t|d}t|_||j|j}|rt d|zt |j||_|S)Nclonerz"Error %d while cloning an EC point)r/rrr<r?rr)rpointrrr-s r.setz EccPoint.set sw''T<00 !mm t{--//|''))++  LAFJKK K"4;??#4#4i@@  r0ct|tsdSt|d}d||j|jkS)NFcmpr) isinstancerr/rr?)rrcmp_funcs r.__eq__zEccPoint.__eq__sY%** 5D%((HHT[__.. 0@0@0B0BCCCCr0c||k SNr)rrs r.__ne__zEccPoint.__ne__ s5=  r0ct|d}|}||j}|rt d|z|S)Nnegz$Error %d while inverting an EC point)r/copyrr?r)rneg_funcnpr-s r.__neg__zEccPoint.__neg__#sYD%(( YY[[")--//**  NCfLMM M r0cF|j\}}t|||j}|S)zReturn a copy of this point.)xyrr)rrrrs r.rz EccPoint.copy+s&w1 aD, - - r0c|jjdvS)Nrr)r%namers r. _is_eddsazEccPoint._is_eddsa1{#777r0cV|r |jdkS|jdkS)z,``True`` if this is the *point-at-infinity*.r)rr)rrrrs r.is_point_at_infinityzEccPoint.is_point_at_infinity4s/ >>   %6Q; 7f$ $r0c|rtdd|jStdd|jS)z-Return the *point-at-infinity* for the curve.r)rrrrs r.point_at_infinityzEccPoint.point_at_infinity<s@ >>   4Aq$"233 3Aq$"233 3r0c|jdS)Nrrrs r.rz EccPoint.xDwqzr0c|jdS)Nrrrs r.rz EccPoint.yHrr0c|}t|}t|}t|d}|t|t|t ||j}|rtd|ztt|tt|fS)Nget_xyz#Error %d while encoding an EC point) r bytearrayr/rrrr?rr r )rrrrrr-s r.rz EccPoint.xyLs**,, } % % } % %$)) B#B // ))++  MBVKLL L b))**GM"4E4E,F,FGGr0c6|dzdzS)z"Size of each coordinate, in bytes.) size_in_bitsrs r.rzEccPoint.size_in_bytes[s!!##a'A--r0c|jjS)z!Size of each coordinate, in bits.)r% modulus_bitsrs r.rzEccPoint.size_in_bits_s {''r0ct|d}||j}|rtd|z|S)zuDouble this point (in-place operation). Returns: This same object (to enable chaining). doublez#Error %d while doubling an EC pointr/rr?r)r double_funcr-s r.rzEccPoint.doublecsPtX.. T[__..//  MBVKLL L r0ct|d}||j|j}|r'|dkrtdtd|z|S)zAdd a second point to this oneaddz#EC points are not on the same curvez#Error %d while adding two EC pointsr)rradd_funcr-s r.__iadd__zEccPoint.__iadd__psxD%(($+//++U\-=-=-?-?@@  M|| !FGGGBVKLL L r0c8|}||z }|S)z8Return a new point, the addition of this one and anotherr)rrrs r.__add__zEccPoint.__add__{sYY[[ e  r0c bt|d}|dkrtdt|}||jt |t t|ttd}|rtd|z|S)zMultiply this point by a scalarscalarrz?Scalar multiplication is only defined for non-negative integersr9z%Error %d during scalar multiplication) r/rr rr?rrr=rr)rr scalar_funcsbr-s r.__imul__zEccPoint.__imul__stX.. A::^__ _ 6 " "T[__..(__%c"gg..(R99;;  ODvMNN N r0c8|}||z}|S)z2Return a new point, the scalar product of this oner)rrrs r.__mul__zEccPoint.__mul__sYY[[ f  r0c,||Sr)r)r left_hands r.__rmul__zEccPoint.__rmul__s||I&&&r0N)r_)rrr__doc__rrrrrrrrrpropertyrrrrrrrrrrrrr0r.rrs~($A$A$A$AL   DDD!!! 888%%%444XX H HX H...(((         '''''r0rr2)GrQr_rmrzceZdZdZdZdZdZdZdZdZ dZ e d Z e d Z e d Zd Zd ZdZdZddZdZdZdZdZdZdZdZdS)EccKeyaClass defining an ECC key. Do not instantiate directly. Use :func:`generate`, :func:`construct` or :func:`import_key` instead. :ivar curve: The name of the curve as defined in the `ECC table`_. :vartype curve: string :ivar pointQ: an ECC point representating the public component. :vartype pointQ: :class:`EccPoint` :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 representats the private component in EdDSA curves (Ed25519, 32 bytes; Ed448, 57 bytes). :vartype seed: bytes c t|}|dd}|dd|_|dd|_|dd|_||jr |jj}|rt dt|z|tvrtd|zt||_ |j j |_ t|jdut|jduz}|dkr|jtd dS|d krtd |s^|jtd t|j|_d |jcxkr|j jksntddS|jtd|j jdkrt%|jdkrtdt'j|j}|dd|_t/|dd}|dxxdzcc<|ddzdz|d<n|j jdkrt%|jdkrtdt1j|jd}|dd|_t/|dd}|dxxdzcc<|dxxdzcc<d|d<tj|d |_dS)!aiCreate 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 the Ed25519 (32 bytes) or Ed448 (57 bytes) curve. point : EccPoint 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. rNdseedrUnknown parameters: zUnsupported curve (%s)rzGAt lest one between parameters 'point', 'd' or 'seed' must be specifiedz,Parameters d and seed are mutually exclusivez7Parameter 'seed' can only be used with Ed25519 or Ed448rz;Parameter d must be an integer smaller than the curve orderz/Parameter d can only be used with NIST P curvesrrez0Parameter seed must be 32 bytes long for Ed25519r9r9z.Parameter seed must be 57 bytes long for Ed448r78little byteorder)rCpop_d_seedrr TypeErrorrrArr%r&rintrr rHrr=rnewdigest_prefixrrread from_bytes)rkwargskwargs_ curve_namecount seed_hashtmps r.rzEccKey.__init__s-&v,,[[$// ++c4(([[.. kk'400  $+ 0J  C2S\\ABB B W $ $5 BCC Cj) [% DG4'((3tz/E+F+FF A::{" !jkkk F A::KLL L~~ Bz% !Z[[[dg&&DG3333$+"33333 !^___43w" !RSSS{9,,tz??b(($%WXXX"Jtz2299;; (~  #2#//A$r7T>T1B!W,,tz??b(($%UVVV$L4499#>> (~  #2#//A$B4B(AAADGGGr0c|jjdvS)N)r r")r%r&rs r.rzEccKey._is_eddsa#rr0ct|tsdS||krdS|j|jkS)NF)rr has_privatepointQ)rothers r.rz EccKey.__eq__&sP%(( 5     $"2"2"4"4 4 45|t{**r0c|rV|r*dttj|jz}ndt |jz}nd}|jj \}}d|j j |||fzS)Nz , seed=%sz, d=%dz,EccKey(curve='%s', point_x=%d, point_y=%d%s)) rrrbinasciihexlifyrrr rrr%r&)rextrarrs r.__repr__zEccKey.__repr__/s      ~~ 0#eH,<== =wr0cV|std|jSr<)rrrrs r.rz EccKey.seed\s-!! ><== =zr0cP|j|jj|jz|_|jSr)rr%rr rs r.rz EccKey.pointQbs$ ; +-$'1DK{r0cBt|jj|jS)z^A matching ECC public key. Returns: a new :class:`EccKey` object )rr)rr%r&rrs r. public_keyzEccKey.public_keyhsDK,DK@@@@r0c|rtd|j}|rF|jjrd}nd}||jj|z}nBd|jj|z|jj|z}|S)Nz+SEC1 format is unsupported for EdDSA curves)rrrrris_oddrto_bytes)rcompressr first_byter@s r. _export_SEC1zEccKey._export_SEC1qs >>   LJKK K 1133  A{}##%% %$ $ $+-00??@JJ"+-00??@+-00??@Jr0cn|jj\}}|jjdkr9t |dd}|dzdz|dz|d<nO|jjdkr0t |d d}|dzdz|d <nt d t|S) Nrrer r rrrrrrzNot an EdDSA key to export)rrr%rrrFrbytes)rrrr-s r. _export_eddsazEccKey._export_eddsas{~1 ; y ( (qzz"zAABBFq5Q,&*4F2JJ [  ( (qzz"zAABBFa%AF2JJ9:: :V}}r0c|r#|jj}|}d}n0d}||}t |jj}t |||S)N1.2.840.10045.2.1)rr%oidrLrIr r)rrGrOr@paramss r._export_subjectPublicKeyInfoz#EccKey._export_subjectPublicKeyInfosx >>   2+/C++--JFF%C**844J 11F.s/9/577 7r0Tc|sJ|j}d|jj|z|jj|z}dt |j|t|j j dt|dg}|s|d=t| S)NrDrrexplicitr)rrrrrFrrrr r%rOrrencode)rinclude_ec_paramsrr@seqs r._export_rfc5915_private_derz"EccKey._export_rfc5915_private_ders!!!!! 1133 km,,];;<km,,];;< dfoom<<==4;?Q777J3335 ! A3&&(((r0c zddlm}|ddd|vrtd|r5|jj}t|j }d}n1d}| d}t|jj}|j ||fd |i|}|S) NrPKCS8 passphrase protection5At least the 'protection' parameter should be presentrNF)rV key_params) Crypto.IOr[r?rrr%rOrrrUrXr wrap)rrr[rO private_keyrPr-s r. _export_pkcs8zEccKey._export_pkcs8s###### ::lD ) ) 5,f:T:TTUU U >>   2+/C(44;;==KFF%C::U:SSK 11FK&&'-&%&& r0cdddlm}||}||dS)NrPEMz PUBLIC KEY)r`rfrQrU)rrGrf encoded_ders r._export_public_pemzEccKey._export_public_pems;!!!!!!77AA zz+|444r0c Vddlm}|}|j|d|fi|S)NrrezEC PRIVATE KEY)r`rfrXrUrr\rrfrgs r._export_private_pemzEccKey._export_private_pemsD!!!!!!6688 sz+'7NNvNNNr0cbddlm}|}||dS)Nrrez PRIVATE KEY)r`rfrcrU)rrfrgs r.(_export_private_clear_pkcs8_in_clear_pemz/EccKey._export_private_clear_pkcs8_in_clear_pems9!!!!!!((** zz+}555r0c ddlm}|sJd|vrtd|jdd|i|}||dS)Nrrer]r^r\zENCRYPTED PRIVATE KEYr)r`rfrrcrUrjs r.,_export_private_encrypted_pkcs8_in_clear_pemz3EccKey._export_private_encrypted_pkcs8_in_clear_pemsk!!!!!!z v % %TUU U(d(IIJI&II zz+'>???r0cj|rtd|jj}|td|jjz|dkr3|}t |t |f}n|j}|rQd|jj z}t||jj |z}nBd|jj |z|jj |z}|dd}t |t ||f}dd|D}|d zt!t#j|zS) Nz"Cannot export OpenSSH private keysz Cannot export %s keys as OpenSSHrrrD-r0cXg|]'}tjdt||z(S)>I)structpackr=).0rs r. z*EccKey._export_openssh.. s/FFF1T3q6622Q6FFFr0 )rrr%opensshrrLrrrrrErrrFsplitjoinrr# b2a_base64) rrGr&r@compsrrHmiddleblobs r._export_opensshzEccKey._export_opensshs      CABB B{" <?$+BRRSS S ] " "++--JT]]GJ$7$78EE K5577M E!5!5!7!77 ":.."km44]CCD &"km44]CCD"km44]CCD ZZ__Q'FT]]GFOOZ@ExxFFFFFGGczE("5d";";<<<-4-LLLtLLL;;=== "68B"CDDD G !>!EFFFU""..x888u$$88BBBv%%((222u$$;#';;;--///,,X666++H555r0N)T)rrrrrrrr&rr4r:rrrrr@rIrLrQrXrcrhrkrmrorrrr0r.rrs*JBJBJBX888+++ ` ` `###   ,,,X X X AAA8    7 7 7))))6*555 OOO 666 @@@===:z6z6z6z6z6r0rc |d}t|}|dt}|rtdt |zt|jdkr|d}t ||}n`t|jdkr|d}t ||}n-tjd |j | }t || }|S) a1Generate 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. rrandfuncrrrerrrrr)r)r*r)rr) r rArrrrrr r+rH)rrrrrnew_keyrs r.generatersG$$J J Ezz*&677H >.V<===z9,,x||z555   !W , ,x||z555  q/4{*2 4 4 4zQ/// Nr0c |d}t|}|dd}|dd}d|vrtdd||fvrt||||d<t di|}|r/d|vr+|j|jz}|j||fkrtd|S) aBuild 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): the integer in the range ``[1..order-1]`` that represents the key. seed (bytes): Mandatory for a private key and an EdDSA curve. It must be 32 bytes for Ed25519, and 57 bytes for Ed448. point_x (integer): Mandatory for a public key: the X coordinate (affine) of the ECC point. point_y (integer): Mandatory for a public key: the Y coordinate (affine) of the ECC point. Returns: :class:`EccKey` : a new ECC key object rpoint_xNpoint_yrzUnknown keyword: pointz(Private and public ECC keys do not matchr) rAr rrrrrrrr)rrrrrrpub_keys r. constructrs<J J EjjD))GjjD))G&0111 GW%%%"7GZ@@wvGIF!2!2'GI% :'7+ + +GHH H Nr0ctD]\}}|r |j|krn/||krn'|rtd|ztd|z|j}t |d}|dkrgt|dd|zzkrtdtj |d|dz}tj ||dzd}n|d vrt|d|zkrtdtj |dd}|d z|d zz |j z |j}|dkr| r |j|z }|d kr|r |j|z }ntd t||| S) aConvert 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)zUnsupported ECC curve (%s)rrrzIncorrect EC point lengthNrrzIncorrect EC point encodingrrr)rAitemsrOrrFrrr=rr rrGsqrtrEis_evenr) ec_point curve_oidrrrr point_typerrs r._import_public_derrs&mmoo S S U  i// E  $ $ E %  S'(II(UVV V'(Dz(QRR RG))++Mhqk""JT x==Q]!22 3 3899 9  x-/(9: ; ;  x a(8(89 : : | # # x==Q. / /899 9  x| , , TAaCZ%' ! ' ' 0 0   !((** ! A   !))++ ! A6777 ;1 = = ==r0ct|\}}}d}dtfdtfd}||vrj|std|z t |j}n#t$rtdwxYwt||S||vr?||\}} |rtd|z| |\} } t| | | Std |z) z4Convert a subjectPublicKeyInfo into an EccKey objectrNz 1.3.132.1.12z 1.3.132.1.13r r"rrz%Missing ECC parameters for ECC OID %szError decoding namedCurverz(Unexpected ECC parameters for ECC OID %s)rrrzUnsupported ECC OID: %s) r_import_ed25519_public_key_import_ed448_public_keyrr decodevaluerrr) encodedrrOrrP nist_p_oids eddsa_oidsrrimport_eddsa_public_keyrrs r._import_subjectPublicKeyInforsA #;<J  k LDsJKK K :# ,,V44:II : : :899 9 :"(i@@@@  .8o+ +  OG#MNN N&&x001AZ@@@@#$=$CDDDs &A))Bct|d}|ddkrtd td|dj}|||krtd|}n#t$rYnwxYw|td t D]\}}|j|krntd |zt|dj }|j }t||krtd tj|} t|dkrXt!d|d j} t#| | } | jj} | jj} ndx} } t+|| | | S)N)rr) nr_elementsrrz!Incorrect ECC private key versionrSrzCurve mismatchzNo curve foundrzPrivate key is too smallr)rrrr)rrrr rrArrOrrpayloadrFrr=r rrrrrrr)rr\rrb parametersrr scalar_bytesrrpublic_key_encr@rrs r._import_rfc5915_derrPs--&&wF&CCK1~<===  !,,,33KNCCI  Z9%<%<-.. .      )***$]]__SS E 9 ! ! E "$$E $QRRR!##**;q>::BLG))++M <M))3444<((A ;!%q11188RIIO')LLL #%#%  ' :GW M M MMsAB BBcddlm}|||\}}}d}ddd}||vr7t|j}t |||S||vrP|tdd}t|j } t||| Std |z) NrrZrr r"rz.EdDSA ECC private key must not have parametersrz!Unsupported ECC purpose (OID: %s)) r`r[unwrapr rrrrrrrr) rr\r[algo_oidrbrPrrrrs r. _import_pkcs8rs$)LL*$E$E!Hk6K !J ;MM((006 "; IFFF Z    MNN N &&{33;z(3$????#$G($RSSSr0c>t|}t|Sr)rr)rrsp_infos r._import_x509_certrs.w77G ' 0 00r0c t||S#t$r}|d}~wtttf$rYnwxYw t ||S#t$r}|d}~wtttf$rYnwxYw t ||S#t$r}|d}~wtttf$rYnwxYw t||S#t$r}|d}~wtttf$rYnwxYwtd)NzNot an ECC DER key)rrrr IndexErrorrrr)rr\errs r. _import_derrso +GZ@@@   : .       *555   : .      "7J777   : .      Wj111   : .      ) * **sm ;;;A A8AA87A8<B B5BB54B59C C2CC21C2cv|d}t|dvrtd tj|d}g}t|dkrct jd|ddd}||dd|z|d|zd}t|dkc|d|dkrtd|dd rt D]c\}}|j  |j d s(t|j d d }|d|krndtd |zt|d |j}nO|ddkr+t|d\} } t!d| | }ntd|dzn8#t"t$tjf$rtd|dzwxYw|S)N rzNot an openssh public keyrrrsrzMismatch in openssh public key ecdsa-sha2- ecdsa-sha2rqrzUnsupported ECC curve: r ssh-ed25519r rzUnsupported SSH key type: zError parsing SSH key type: )rzr=rr# a2b_base64rtunpackappend startswithrArryrrrOrrrrError) rparts keystringkeypartslkrrr~ecc_keyrrs r._import_openssh_publicrsQ MM$  E 5zz4555$D'a11 )nnq  tYrr]33A6B OOIaBh/ 0 0 0!!b&''*I)nnq  8x{ " "=>> > 8  ~ . . F%,]]__ E E! E=(}// == !4!4S!9!9!!<==A;&((E)!!:V!CDDD(! JJJGG1X ' '-hqk::DAqiAFFFGG9E!HDEE E  8> 2DDD7%(BCCCD Ns G H5H6cddlm}m}m}m}|||\}}ddt dfi}|dr||\} }| tvrtd| zt| } | j dzd z} ||\} }t| d d krtd t| d | zdzkrtdtj| dd| z} tj| d| zd}||\}}tj|}|| d}n\||vrF||\}}}||\} }|| \} }||\}}|d|}||d}ntd|z||\}}||td| |d|S)Nr)import_openssh_private_generic read_bytes read_string check_paddingrr rerzUnsupported ECC curve %srrrrz/Only uncompressed OpenSSH EC keys are supportedrzIncorrect public key length)rr)rrzUnsupport SSH agent key type:)rrr)_opensshrrrrrrrArrrrr=r rr)datapasswordrrrrkey_type decrypted eddsa_keysecdsa_curve_namerrr@rrrbrrPrrseed_lenprivate_public_keyr_paddeds r._import_openssh_private_eccrsCCCCCCCCCCCC98xHHHi  #=rBJ <((#E&1k)&<&<#) 7 * *'(BEU(UVV V()+a/A5 * 9 5 5 I  1  ! # #NOO O z??a-/!3 3 3:;; ;$Z!M/0A%BCC$Z-0@0@%ABB!+I!6!6 Y  { + +#344 Z  8B88L5 +X * 9 5 5 I22:>>(2 9(=(=%I!)8),4488CDDD I&&IAvM&  @Wg @ @ @ @@r0c t|dkrtdtd}d}t|}|ddz }|dxxdzcc<tj|d }||krtd |d krd S|d zd z |z}|d z|z|zd z|z} ||}||z|z} tj| |} | d z|kr|| z } n#t$rtdwxYw| |fS)a~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: :class:`EccKey` : a new ECC key object Raises: ValueError: when the given key cannot be parsed. .. _RFC8032: https://datatracker.ietf.org/doc/html/rfc8032 rez9Incorrect length. Only Ed25519 public keys are supported.rlx&(7Z/ ;(P8se:8 w6Rrrrr r zInvalid Ed25519 key (y)rrrrzInvalid Ed25519 public key)r=rr rrr,_tonelli_shanks rrFrrx_lsbruvv_invx2rs r.rr*sP" 7||rTUUURSSAUA'A bEQJEbEEETMEEE h777G!||2333!||t !a1A 1*q.A  !Q&A7 ! %i1_)"a00 aKE ! !'kG 77756667 G s .AC//D ct|dkrtdtd}d}|dd}t|ddz }tj|d }||krtd |d krd S|d zd z |z}|d z|z|zd z |z} ||}||z|z} tj| |} | d z|kr|| z } n#t$rtdwxYw| |fS)azImport 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: :class:`EccKey` : a new ECC key object Raises: ValueError: when the given key cannot be parsed. .. _RFC8032: https://datatracker.ietf.org/doc/html/rfc8032 rz7Incorrect length. Only Ed448 public keys are supported.rlVg?Nrrr r zInvalid Ed448 key (y)rrrzInvalid Ed448 public key)r=rr rrr,rrs r.rrWsM" 7||rRSSSC D DAzA A    "E h777G!||0111!||t !a1A 1*q.A  !Q&A5 ! %i1_)"a00 aKE ! !'kG 55534445 G s &AC''Dcddlm}t|}|t|}|dr;t |}|||\}}}t ||}|S|drt |}d} d} tj| dz| zd |tj }|||\} }}|rd} t| |}n,#t$r} | d} ~ wt$rtd wxYw|S|d rt|St|dkr)t|dd krt||St|dkr9t|ddvr"|tdt!||Std)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`. 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 rreNs-----BEGIN OPENSSH PRIVATE KEYs-----z-----BEGIN EC PARAMETERS-----z-----END EC PARAMETERS-----z.*?r")flagsz(Invalid DER encoding inside the PEM file)rrrsszNo curve name was provided)rzECC key format is not supported)r`rfrrrrrresubDOTALLrrrrr=rr) rr\rrf text_encodedopenssh_encodedmarkerenc_flagr-ecparams_start ecparams_end der_encodeduefs r. import_keyrs0~gGZ(( ;<<W~~ ,/JJ|Z,P,P),_jII   H % %W~~ 94 vnu4|CR*$&I/// ), <(L(L% VX  J I j99FF$   I I I IGHH H I :;;/%g... 7||aD,,447J/// 7||aD,,??  9:: :!'jAAAA 6 7 77s&C77 D DD __main__l_,)N$c hKf-5lkrs>&%%%%% """"""GGGGGGGGGGGGGG;;;;;;;;'''''',,,,,,,,,,,,==================@@@@@@@@@@)(((((((******,,,,,, $ #$=@  >)()DG "' &'@C ,4 H\ ] ]  $4$4$4N   $4$4$4N   $4$4$4N   $4$4$4N   $4$4$4N  I& :::,  666:      J   J'J'J'J'J'vJ'J'J'\ '&/$gfo&8& A Av&))t}}Z../// D* '&/$gfo&8& A Av&))t}}Z../// D* '&/$gfo&8& A Av&))t}}Z../// D* '&/$gfo&8& A Av&))t}}Z../// D* '&/$gfo&8& A Av&))t}}Z../// D* HWY'*GI,>,A9 M M )  % % % 2 2t}}]G44555 w (77#&(8(;W E E!!G!,,t}}[%00111 UKH6H6H6H6H6VH6H6H6VD333l5>5>5>5>p1E1E1Eh/N/N/N/NdTTT8111 +++B+++\4A4A4An***Z)))Xq8q8q8q8h zKKKJA FO  " " $ $E E DIKKE U5\\ E+  e+u4t;TBBB DIKKE U5\\! E #idikkE&9U%BT%I4PPPPP#r0