U
    g'                     @   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Cryptodome.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   B/tmp/pip-unpacked-wheel-_q8s9isk/Cryptodome/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DjSg9g(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!#BXtJ9!'|%VA-l   4~ 
f&Dv@h!fE0m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`Opq^cv
3,e<1U]>{|R*Zl   Q%x+Ohbi+}s   @ l   B11e	%:f=K`wrH7gHK8hkl   Q~o]l+fUg+<)Z?8O?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`gwlX_[nlv|l   
dxRjoyU8T(	:ss"nZL8k&"_Ul   _!uR/sX0
@qaNQNB&JxS8KJEY	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%b95~cte1oR{V;LHw>l-rZE]"Sr&Ga9}*Fl#   	dp"z\}[z3"nZ;PK#
`7roCQl#   f=xK)H-apY$3^Q	n%k{;/K!u{4-{?$Od8V1l3s:l#   Pf?QE$XN!85aZUWL9YLhz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Cryptodome.Math.Numbersr   ZCryptodome.Util._raw_apir   r   r   r   r	   r
   ZCryptodome.Util.numberr   ZCryptodome.Random.randomr   r   objectr   r)   r,   r/   r1   r3   r   r   r   r   <module>   s    
 &&&&