U
    ÈZj±'  ã                   @   s–   d dl mZ ddlmZ ddlmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZ eddƒZG d	d
„ d
eƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )é   )Ú_Curveé    )ÚInteger)Úload_pycryptodome_raw_libÚVoidPointerÚSmartPointerÚc_size_tÚc_uint8_ptrÚc_ulonglong)Úlong_to_bytes)ÚgetrandbitszCrypto.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_ws_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);
c                   @   sN   e Zd ZejZejZejZ	ej
ZejZejZejZejZejZejZejZdS )ÚEcLibN)Ú__name__Ú
__module__Ú__qualname__Ú_ec_libÚec_ws_new_contextZnew_contextÚec_ws_free_contextZfree_contextZec_ws_new_pointZ	new_pointZec_ws_free_pointZ
free_pointZec_ws_get_xyZget_xyZec_ws_doubleÚdoubleZ	ec_ws_addÚaddZec_ws_scalarZscalarZec_ws_cloneÚcloneZ	ec_ws_cmpÚcmpZ	ec_ws_negÚneg© r   r   ú]/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/Crypto/PublicKey/_nist_ecc.pyr   -   s   r   c                  C   sÂ   d} d}d}d}d}t | dƒ}t |dƒ}t |dƒ}tƒ }t | ¡ t|ƒt|ƒt|ƒtt|ƒƒtt	dƒƒ¡}	|	r|t
d|	 ƒ‚t| ¡ tjƒ}
tt| ƒt|ƒt|ƒt|ƒt|ƒd d	d
|
ddtƒ}|S )Nl   ÿÿÿÿïÿÿÿÿÿÿÿÿl   ±9�³{ÆuŸ†DÜjôSg9–g(Bl   1(¤iÆ&^#aß;æÿÿÿÿÿÿl   þö+ø' 1tÐ:�_|v!aÀ:@mˆl   Hò<„^ËW]™dZ{cx´ÿW\Iq é   é@   z#Error %d initializing P-192 contextéÀ   z1.2.840.10045.3.1.1z
NIST P-192zecdsa-sha2-nistp192©r   r   r   r   Z
address_ofr	   r   Úlenr
   r   ÚImportErrorr   Úgetr   r   r   r   )ÚpÚbÚorderÚGxÚGyZp192_modulusZp192_bZ
p192_orderZec_p192_contextÚresultÚcontextZp192r   r   r   Ú
p192_curve;   sB    





ûõr)   c                  C   sÂ   d} d}d}d}d}t | dƒ}t |dƒ}t |dƒ}tƒ }t | ¡ t|ƒt|ƒt|ƒtt|ƒƒtt	dƒƒ¡}	|	r|t
d|	 ƒ‚t| ¡ tjƒ}
tt| ƒt|ƒt|ƒt|ƒt|ƒd d	d
|
ddtƒ}|S )Nl              Àÿÿÿÿÿÿÿÿ?l   ´«FeY8¢ûwõ-X"PVdÕ/�%ÀPP!-l   =*¸8%éá¸(‹ÿÿÿÿÿÿÿ?l   !¸"X”!#BXÕtàJ9!'È|û%»V—AÃ-l   4~ 
f¬&Dvè@hº!Íf¿E0m9_qlM/é   r   z#Error %d initializing P-224 contextéà   z1.3.132.0.33z
NIST P-224zecdsa-sha2-nistp224r   )r"   r#   r$   r%   r&   Zp224_modulusZp224_bZ
p224_orderZec_p224_contextr'   r(   Zp224r   r   r   Ú
p224_curvea   sB    





ûõr,   c                  C   sÂ   d} d}d}d}d}t | dƒ}t |dƒ}t |dƒ}tƒ }t | ¡ t|ƒt|ƒt|ƒtt|ƒƒtt	dƒƒ¡}	|	r|t
d|	 ƒ‚t| ¡ tjƒ}
tt| ƒt|ƒt|ƒt|ƒt|ƒd d	d
|
ddtƒ}|S )Nl   ÿÿÿÿÿÿ?               @ÿÿ l   K`¤Oøpq^cv
3,ƒe<1ÚUê]>{|RŽ*ìÆZl   Q%Æx+ÎOhóbi+}s¼ÿÿÿÿ   @ÿÿ l   –B11e	%:f=K`¾wr�HŽ7g‹HK8ùhkl   õQ~o ²]ìl+fÚUg+<ð)Z?î8óO†?q!ãOé    r   z#Error %d initializing P-256 contexté   z1.2.840.10045.3.1.7z
NIST P-256zecdsa-sha2-nistp256r   )r"   r#   r$   r%   r&   Zp256_modulusZp256_bZ
p256_orderZec_p256_contextr'   r(   Zp256r   r   r   Ú
p256_curve‡   sB    





ûõr/   c                  C   sÂ   d} d}d}d}d}t | dƒ}t |dƒ}t |dƒ}tƒ }t | ¡ t|ƒt|ƒt|ƒtt|ƒƒtt	dƒƒ¡}	|	r|t
d|	 ƒ‚t| ¡ tjƒ}
tt| ƒt|ƒt|ƒt|ƒt|ƒd d	d
|
ddtƒ}|S )Nl   ÿÿ       Àÿÿ~ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿl   ï*Ø'·#.TÒÚEbc+ÆZ'@=D 1 "( ?7N2Zà_+à“|¹ñS/1fl   s)Š«e`g®w’lX_[nÐlv|ÿÿÿÿÿÿÿÿÿÿÿÿÿl   ·
ìdáx¢RÃ¥joyU8T(	:Ÿssé"±nèZ‚L÷8kñ&Á"_ÊUl   _Ô!òuR×Ð/‡sX0
@qa×NˆQ�N�B&JÞôxS8KJüEéYë‹	K%Þl é0   r   z#Error %d initializing P-384 contexti€  z1.3.132.0.34z
NIST P-384zecdsa-sha2-nistp384r   )r"   r#   r$   r%   r&   Zp384_modulusZp384_bZ
p384_orderZec_p384_contextr'   r(   Zp384r   r   r   Ú
p384_curve­   sB    





ûõr1   c                  C   sÂ   d} d}d}d}d}t | dƒ}t |dƒ}t |dƒ}tƒ }t | ¡ t|ƒt|ƒt|ƒtt|ƒƒtt	dƒƒ¡}	|	r|t
d|	 ƒ‚t| ¡ tjƒ}
tt| ƒt|ƒt|ƒt|ƒt|ƒd d	d
|
ddtƒ}|S )Nl#   ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿl#    ? VQ(zO†%bï95~cîte1oR{¨VÂÄ;ŒLHw>ÅlÌ-rZE]´"Sr‡&Ga9}*Fl#   	dp"z\}[ëzˆ3"näZ;PKÜ#
`ü7ÍrËoÁC†Qôÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿl#   f=ËÇxóK¿)H-apY$3^Q‹	ná%kù{;/K!u{4-{Š?$íO‚�d8ÑV1¶lÇ3s:·l#   Pf¢?ÚQôE$XN¨!85aZþÈUÈ½WL9îYLù¹hûzÑf«$Du13otc!û%‘pMxjRr`éB   r   z#Error %d initializing P-521 contexti	  z1.3.132.0.35z
NIST P-521zecdsa-sha2-nistp521r   )r"   r#   r$   r%   r&   Zp521_modulusZp521_bZ
p521_orderZec_p521_contextr'   r(   Zp521r   r   r   Ú
p521_curveÓ   sB    





ûõr3   N)Z_curver   ZCrypto.Math.Numbersr   ZCrypto.Util._raw_apir   r   r   r   r	   r
   ZCrypto.Util.numberr   ZCrypto.Random.randomr   r   Úobjectr   r)   r,   r/   r1   r3   r   r   r   r   Ú<module>   s    
 &&&&