
    E6i8                        S SK r S SKrS SKrS SKrS SKJr  S SKJr  S SKJr  S SK	J
r
Jr  S SKJrJr  S SKJr  S SKJr   S SKrS	rSS jrS rS rS rS r " S S\R6                  5      r " S S\R6                  5      r " S S\R6                  5      r " S S\R6                  5      r0 4S jr \!S:X  a  S r"\RF                  " SS9  gg! \ a    S
r Nf = f)    N)	unhexlify)SkipTest)list_test_cases)tostrFileNotFoundError)DerSequenceDerBitString)SHAKE128)ECCTFc                 X   S n [         (       d=  [        [        R                  [        R
                  " [        R                  5      U 5      eSn[        R                  R                  [        R                  5      n[        R                  R                  [        R                  R                  " U/UQ76 U 5      n[        XQ5       nUR                  5       nS S S 5        Uc  [!        SU -  5      eU$ ! , (       d  f       N!= f! [         a    [        R                  " S[        SS9   NJf = f)N)	PublicKeyr   z(Warning: skipping extended tests for ECC   )
stacklevelz
Missing %s)test_vectors_availabler   errnoENOENTosstrerrorpathdirnamepycryptodome_test_vectors__file__joinopenreadwarningswarnUserWarningr   )	file_namemoderesults	dir_compsinit_dirfull_file_namefile_ins          j/home/james-whalen/.local/lib/python3.13/site-packages/Crypto/SelfTest/PublicKey/test_import_Curve25519.py	load_filer'   4   s    G$%%#ELL$&KK$=$-/ / )	77??#<#E#EFbggll8&Hi&H)T.'7llnG ( |i/00N ('  $@!!"	$$s0   CD C1D 1
C?;D ?D $D)(D)c                     SR                  U 5      n[        [        U5      R                  SS5      R                  SS5      5      $ )N      :)r   r   r   replace)linesexts     r&   compactr0   N   s8    
((5/CU3Z''R088bABBr)   c                      [        S5      R                  5       n [        U SS 5      n[        R                  " SUS9nX"R                  5       4$ )Nzecc_x25519.txt      
Curve25519)curveseed)r'   
splitlinesr0   r   	construct
public_key)	key_linesr6   keys      r&   create_ref_keys_x25519r<   S   sF    *+668I9Qq>"D
--l
6C!""r)   c                  ^    [         R                  " 5       R                  S5      R                  $ )Ns   SEED)r
   newupdater    r)   r&   get_fixed_prngrA   Z   s    <<>  )...r)   c                     [        5       nUR                  U 5        [        5       nUR                  US   5        UR                  $ )N   )r   decoder	   value)dataseqbss      r&   extract_bitstring_from_spkirI   ^   s5    
-CJJt	BIIc!f88Or)   c                        \ rS rSrS rS rSrg)
TestImportf   c                 N    U R                  [        [        R                  S5        g )Nr)   )assertRaises
ValueErrorr   
import_keyselfs    r&   
test_emptyTestImport.test_emptyh   s    *cnnc:r)   c                 h    Sn[        U5      nU R                  [        [        R                  U5        g )N`302e020100300506032b656f042204207009906b64ec727d5cb5c23007bf0425b3fd79014c6cd62ca3dddfcf0f278f79)r   rN   rO   r   rP   )rR   mismatch_hexmismatchs      r&   test_mismatchTestImport.test_mismatchk   s'    y\**cnnh?r)   r@   N)__name__
__module____qualname____firstlineno__rS   rY   __static_attributes__r@   r)   r&   rK   rK   f   s    ;@r)   rK   c                   d   ^  \ rS rSrU 4S jrS rS rS rS rS r	S r
S	 rS
 rS rS rSrU =r$ )TestImport_Curve25519r   c                 \   > [         [        U ]
  " U0 UD6  [        5       u  U l        U l        g N)superra   __init__r<   ref_private
ref_publicrR   argskwargs	__class__s      r&   rf   TestImport_Curve25519.__init__t   *    #T3TDVD,B,D)$/r)   c                 H   [        S5      n[        R                  " U5      nU R                  U R                  U5        [        R
                  " US 5      nU R                  U R                  U5        [        R                  " U5      nU R                  U R                  U5        g )Necc_x25519_public.der)r'   r   _import_subjectPublicKeyInfoassertEqualrh   _import_derrP   rR   key_filer;   s      r&   test_import_public_der,TestImport_Curve25519.test_import_public_derx   sw    45..x8#.ooh-#.nnX&#.r)   c                     [        S5      n[        R                  " US 5      nU R                  U R                  U5        [        R
                  " U5      nU R                  U R                  U5        g )Necc_x25519_private.derr'   r   rs   rr   rg   rP   rt   s      r&   test_import_pkcs8_der+TestImport_Curve25519.test_import_pkcs8_der   sW    56ooh-))3/nnX&))3/r)   c                     [        S5      n[        R                  " US5      nU R                  U R                  U5        [        R
                  " US5      nU R                  U R                  U5        g )Nzecc_x25519_private_p8.dersecretrz   rt   s      r&   %test_import_private_pkcs8_encrypted_1;TestImport_Curve25519.test_import_private_pkcs8_encrypted_1   sY    89ooh1))3/nnXx0))3/r)   c                     [        S5      n[        R                  " US5      nU R                  U R                  U5        g )Nzecc_x25519_private_p8.pemr~   r'   r   rP   rr   rg   rt   s      r&   %test_import_private_pkcs8_encrypted_2;TestImport_Curve25519.test_import_private_pkcs8_encrypted_2   s3    89nnXx0))3/r)   c                     [        S5      n[        R                  " US5      nU R                  U R                  U5        [        R
                  " US5      nU R                  U R                  U5        g )Nzecc_x25519_private_p8_2.derr~   rz   rt   s      r&   %test_import_private_pkcs8_encrypted_3;TestImport_Curve25519.test_import_private_pkcs8_encrypted_3   sY    :;ooh1))3/nnXx0))3/r)   c                     [        S5      n[        R                  " US 5      nU R                  U R                  U5        [        R
                  " U5      nU R                  U R                  U5        g )Nzecc_x25519_x509.der)r'   r   rs   rr   rh   rP   rt   s      r&   test_import_x509_der*TestImport_Curve25519.test_import_x509_der   sS    23ooh-#.nnX&#.r)   c                 ~    [        S5      n[        R                  " U5      nU R                  U R                  U5        g )Necc_x25519_public.pemr'   r   rP   rr   rh   rt   s      r&   test_import_public_pem,TestImport_Curve25519.test_import_public_pem   s/    45nnX&#.r)   c                 ~    [        S5      n[        R                  " U5      nU R                  U R                  U5        g )Necc_x25519_private.pemr   rt   s      r&   test_import_private_pem-TestImport_Curve25519.test_import_private_pem   s1    56nnX&))3/r)   c                    S H  n[        SU-  5      n[        R                  " US5      nU R                  U R                  U5        [        R                  " [        U5      S5      nU R                  U R                  U5        M     g )N)des3aes128aes192aes256zecc_x25519_private_enc_%s.pemr~      secret)r'   r   rP   rr   rg   r   )rR   algoru   r;   s       r&   !test_import_private_pem_encrypted7TestImport_Curve25519.test_import_private_pem_encrypted   sl    8D !@4!GHH..84CT--s3..x)<CT--s3 9r)   c                 ~    [        S5      n[        R                  " U5      nU R                  U R                  U5        g )Nzecc_x25519_x509.pemr   rt   s      r&   test_import_x509_pem*TestImport_Curve25519.test_import_x509_pem   s/    23nnX&#.r)   rg   rh   )r[   r\   r]   r^   rf   rv   r{   r   r   r   r   r   r   r   r   r_   __classcell__rl   s   @r&   ra   ra   r   s@    E
/0000//04/ /r)   ra   c                   d   ^  \ rS rSrU 4S jrS rS rS rS rS r	S r
S	 rS
 rS rS rSrU =r$ )TestExport_Curve25519   c                 \   > [         [        U ]
  " U0 UD6  [        5       u  U l        U l        g rd   )re   r   rf   r<   rg   rh   ri   s      r&   rf   TestExport_Curve25519.__init__   rn   r)   c                    [        S5      nU R                  R                  S5      nU R                  X5        U R                  R	                  SS9nU R                  X5        U R                  R	                  SSS9nU R                  X5        g )Nrp   TDERformatF)r   compress)r'   rh   _export_subjectPublicKeyInforr   
export_keyrR   ru   encodeds      r&   test_export_public_der,TestExport_Curve25519.test_export_public_der   s{    45//>>tD+//,,E,:+//,,EE,J+r)   c                    [        S5      nU R                  R                  5       nU R                  X5        U R                  R	                  SS9nU R                  X5        U R                  [        U R                  R                  SSS9  g )Nry   r   r   F)r   	use_pkcs8)r'   rg   _export_pkcs8rr   r   rN   rO   r   s      r&   test_export_private_pkcs8_clear5TestExport_Curve25519.test_export_private_pkcs8_clear   s    56""002+ ""--U-;+*d&6&6&A&A!&% 	 	9r)   c                 (   U R                   R                  SSS9nU R                  [        [        R
                  US 5        [        R
                  " US5      nU R                  U R                   U5        U R                   R                  SSSS9n[        R                  " US5      nU R                  U R                   U5        U R                   R                  SSSSS0S	9n[        R                  " US5      nU R                  U R                   U5        g )
Nr~    PBKDF2WithHMAC-SHA1AndAES128-CBC)
passphrase
protectionr   r   r   r   z"PBKDF2WithHMAC-SHA256AndAES128-CBCiteration_count{   )r   r   r   prot_params)	rg   r   rN   rO   r   _import_pkcs8rr   r   rP   rR   r   decodeds      r&   #test_export_private_pkcs8_encrypted9TestExport_Curve25519.test_export_private_pkcs8_encrypted   s   ""00H<^ 1 ` 	*c&7&7$G##GX6))73 ""--U9A9[ . ] ..(3))73 ""--U9A9];Lc:R . T ..(3))73r)   c                     [        SS5      R                  5       nU R                  R                  SS9R                  5       nU R	                  X5        g )Nr   rtPEMr   )r'   striprh   r   rr   )rR   key_file_refru   s      r&   test_export_public_pem,TestExport_Curve25519.test_export_public_pem  sF     !8$?EEG??--U-;AAC0r)   c                     [        SS5      R                  5       nU R                  R                  SS9R                  5       nU R	                  X5        g )Nr   r   r   r   )r'   r   rg   r   rr   r   s      r&   test_export_private_pem_clear3TestExport_Curve25519.test_export_private_pem_clear  sH    5t<BBD""--U-;AAC+r)   c                     U R                   R                  SSSS9nU R                  [        [        R
                  U5        SU;   d   e[        R
                  " US5      nU R                  U R                   U5        g )Nr   r   r   r   zENCRYPTED PRIVATE KEYr~   )rg   r   rN   rO   r   rP   rr   r   s      r&   !test_export_private_pem_encrypted7TestExport_Curve25519.test_export_private_pem_encrypted  sr    ""--U9B9[ . ]
 	*cnng>&'111..(3))73r)   c                     U R                   R                  SS9nU R                  [        U5      S5        U R                  U[	        S5      5        g )Nrawr       s@   ff7561ef60c9c8a757f6d6372ec14142c9be208d0e719136d8d3c715dfcf7e15)rh   r   rr   lenr   )rR   r   s     r&   test_export_raw%TestExport_Curve25519.test_export_raw  sC    //,,E,:Wr*),o"pqr)   c                     U R                   R                  SSS[        5       S9nU R                   R                  SSS[        5       S9nU R                  X5        g )Nr   r~   r   r   r   r   randfuncrg   r   rA   rr   rR   encoded1encoded2s      r&   	test_prngTestExport_Curve25519.test_prng"  sh    ##..e:B:\8F8H / J ##..e:B:\8F8H / J 	,r)   c                     U R                   R                  SSS[        5       S9nU R                   R                  SSS[        5       S9nU R                  X5        g )Nr   r~   r   r   r   r   r   s      r&   test_byte_or_string_passphrase4TestExport_Curve25519.test_byte_or_string_passphrase.  sh    ##..e:B:\8F8H / J ##..e:C:\8F8H / J 	,r)   c                    U R                  [        U R                  R                  SS9  U R                  [        U R                  R                  SSS9  U R                  [        U R                  R                  SSSS9  U R                  [        U R                  R                  SSS	S
9  U R                  [        U R                  R                  SSS9  g )NXXXr   r   r~   )r   r   r+   F)r   r   r   r   r   OpenSSH)rN   rO   rg   r   rQ   s    r&   test_error_params1(TestExport_Curve25519.test_error_params19  s    *d&6&6&A&A%P 	***55!&%- 	 	/ 	***55!&%'$)	 	 	+
 	***55!&%'%G	 	 	I 	***55!*%- 	 	/r)   r   )r[   r\   r]   r^   rf   r   r   r   r   r   r   r   r   r   r   r_   r   r   s   @r&   r   r      sA    E
,9461
,
4r

-	-/ /r)   r   c                       \ rS rSrS rSrg)TestImport_Curve25519_WeakiV  c                 8   SS-  S-
  nSSSSUS-
  UUS-   US-   US-   US-  S-
  US-  US-  S-   4nU Hc  n[         R                  " US5      n[         R                  " USS	9nUR                  S
S9nU R	                  [
        [         R                  U5        Me     g )Nr         r   rC   l   kxujaj\~|ObjZs	oP,E$ l   _+yBb$:6gw[8cph[DS7OW
curve25519)pointr5   r   r   )r   	EccXPointEccKeyr   rN   rO   rP   )rR   pweak_xxlow_order_pointweak_keyr   s          r&   test_weak_pem(TestImport_Curve25519_Weak.test_weak_pemX  s    sFRK]_a%a%aacca%!)a%a%!) A!mmA|<Ozz|LH)))7Gj!nn%' r)   r@   N)r[   r\   r]   r^   r   r_   r@   r)   r&   r   r   V  s    'r)   r   c                     / n U[        [        5      -  nU[        [        5      -  nU[        [        5      -  nU[        [        5      -  nU$ ! [
         a     U$ f = frd   )r   rK   ra   r   r   r   )configtestss     r&   	get_testsr   r  sk    E,,!677!677!;<< L  Ls   AA 
AA__main__c                  >    [         R                  " [        5       5      $ rd   )unittest	TestSuiter   r@   r)   r&   suitr    s    !!)+..r)   suite)defaultTest)rb)$r   r   r   r   binasciir   r   Crypto.SelfTest.st_commonr   Crypto.Util.py3compatr   r   Crypto.Util.asn1r   r	   Crypto.Hashr
   Crypto.PublicKeyr   r   r   ImportErrorr'   r0   r<   rA   rI   TestCaserK   ra   r   r   r   r[   r  mainr@   r)   r&   <module>r     s   > 
      5 : 6    #$!
4C
#/	@"" 	@V/H-- V/rH/H-- H/V'!2!2 '8  	 z/MMg& ]
  #"#s    C CC