
    uh[                       d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZmZ d dlmZ d dlmZ d dlmZ d d	lmZ 	 d dlZd
Z G d de      Zd<dZd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z& G d dejN                        Z( G d dejN                        Z) G d dejN                        Z* G d d ejN                        Z+ G d! d"ejN                        Z, G d# d$ejN                        Z- G d% d&ejN                        Z. G d' d(ejN                        Z/ G d) d*ejN                        Z0 G d+ d,ejN                        Z1 G d- d.ejN                        Z2 G d/ d0ejN                        Z3 G d1 d2ejN                        Z4 G d3 d4ejN                        Z5 G d5 d6ejN                        Z6i fd7Z7e8d8k(  rd9 Z9 ejt                  d:;       yy# e$ r dZY w xY w)=    N)	unhexlify)list_test_cases)bordtostrFileNotFoundError)DerSequenceDerBitString)bytes_to_long)SHAKE128)ECC)_import_rfc5915_derTFc                       e Zd Zy)MissingTestVectorExceptionN)__name__
__module____qualname__     _/home/hoppernj/.local/lib/python3.12/site-packages/Crypto/SelfTest/PublicKey/test_import_ECC.pyr   r   6   s    r   r   c                 B   d }	 t         s<t        t        j                  t	        j
                  t        j                        |       d}t        j                  j                  t        j                        }t        j                  j                  t	        j                  j                  |g| |       }t        ||      5 }|j                         }d d d        |t!        d| z        |S # 1 sw Y   xY w# t        $ r t        j                  dt        d       Y Ew xY w)N)	PublicKeyr   z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          r   	load_filer0   :   s    G$%#ELL$&KK$=$-/ / )	77??#<#E#EFbggll8&Hi&H)T.$' 	%7llnG	% (	)ABBN	% 	%  $7!!"	$$s*   B;C6 ?C*C6 *C3/C6 6%DDc                     dj                  |       }t        t        |      j                  dd      j                  dd            S )Nr     :)r#   r   r   replace)linesexts     r   compactr8   T   s8    
((5/CU3Z''R088bABBr   c                  J   d} t        d      j                         }t        t        |dd             }t        |dd       }t	        |d         dk(  sJ t        |d| dz          }t        || dz   d        }t        j                  d	|
      t        j                  d	||      fS )N   zecc_p192.txtr         	   r      zP-192curvedr@   point_xpoint_yr0   
splitlinesr
   r8   r   r   	constructkey_len	key_linesprivate_key_dpublic_key_xypublic_key_xpublic_key_ys         r   create_ref_keys_p192rO   Y       G.)446I!')Aa."9:MIaN+Ma !Q&&& q!;<L wqyz!:;LMM=9MM|TV Vr   c                  J   d} t        d      j                         }t        t        |dd             }t        |dd       }t	        |d         dk(  sJ t        |d| dz          }t        || dz   d        }t        j                  d	|
      t        j                  d	||      fS )N   zecc_p224.txtr   r;   r<   r=   r   r>   zP-224r?   rB   rE   rH   s         r   create_ref_keys_p224rS   f   rP   r   c                  J   d} t        d      j                         }t        t        |dd             }t        |dd       }t	        |d         dk(  sJ t        |d	| d	z          }t        || d	z   d        }t        j                  d
|      t        j                  d
||      fS )N    zecc_p256.txtr   r<         r   r;   r>   zP-256r?   rB   rE   rH   s         r   create_ref_keys_p256rX   s       G.)446I!')Aa."9:MIaO,Ma !Q&&& q!;<L wqyz!:;LMM=9MM|TV Vr   c                  J   d} t        d      j                         }t        t        |dd             }t        |dd       }t	        |d         dk(  sJ t        |d	| d	z          }t        || d	z   d        }t        j                  d
|      t        j                  d
||      fS )N0   zecc_p384.txtr   rV         r   r;   r>   zP-384r?   rB   rE   rH   s         r   create_ref_keys_p384r^      rY   r   c                  J   d} t        d      j                         }t        t        |dd             }t        |dd       }t	        |d         dk(  sJ t        |d	| d	z          }t        || d	z   d        }t        j                  d
|      t        j                  d
||      fS )NB   zecc_p521.txtr   r\         r   r;   r>   zP-521r?   rB   rE   rH   s         r   create_ref_keys_p521rc      rY   r   c                      t        d      j                         } t        | dd       }t        j                  d|      }||j                         fS )Nzecc_ed25519.txtr<   ra   Ed25519r@   seedr0   rF   r8   r   rG   
public_keyrJ   rg   keys      r   create_ref_keys_ed25519rl      sH    +,779I9Qq>"D
--id
3C!""r   c                      t        d      j                         } t        | dd       }t        j                  d|      }||j                         fS )Nzecc_ed448.txtrV   
   Ed448rf   rh   rj   s      r   create_ref_keys_ed448rp      sG    /*557I9Qr?#D
--gD
1C!""r   c                  \    t        j                         j                  d      j                  S )Ns   SEED)r   newupdater%   r   r   r   get_fixed_prngrt      s    <<>  )...r   c                     t               }|j                  |        t               }|j                  |d          |j                  S )Nr>   )r   decoder	   value)dataseqbss      r   extract_bitstring_from_spkir{      s5    m

4^
		#a&xxr   c                   *    e Zd Zd Zd Zd Zd Zd Zy)
TestImportc                 N    | j                  t        t        j                  d       y )Nr   assertRaises
ValueErrorr   
import_keyselfs    r   
test_emptyzTestImport.test_empty   s    *cnnc:r   c                 R    d}| j                  t        t        j                  |       y )Na1  -----BEGIN PRIVATE KEY-----
MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJChZANiAAQarFRaqflo
I+d61SRvU8Za2EurxtW20eZzca7dnNYMYf3boIkDuAUU7FfO7l0/4iGzzvfUinng
o4N+LZfQYcTxmdwlkWOrfzCjtHDix6EznPO/LlxTsV+zfTJ/ijTjeXk=
-----END PRIVATE KEY-----r   )r   mismatchs     r   test_mismatchzTestImport.test_mismatch   s!     	*cnnh?r   c                 l    d}t        t        |      d d      }| j                  |j                  d       y )NN302502010104205c4e4320ef260f91ed9fc597aee98c8236b60e0ced692cc7a057d5e45798a0521.2.840.10045.3.1.7   R 1/WzL%-;[6S^,~A;!N\r   r   assertEqualrA   r   data_hexrk   s      r    test_import_private_rfc5915_nonez+TestImport.test_import_private_rfc5915_none   s0    c!)H"5t=RS bcr   c                 j    d}t        t        |      d       }| j                  |j                  d       y )Nf303102010104205c4e4320ef260f91ed9fc597aee98c8236b60e0ced692cc7a057d5e45798a052a00a06082a8648ce3d030107r   r   r   s      r   "test_import_private_rfc5915_only_0z-TestImport.test_import_private_rfc5915_only_0   s-    {!)H"5t< bcr   c                 l    d}t        t        |      d d      }| j                  |j                  d       y )N306b02010104205c4e4320ef260f91ed9fc597aee98c8236b60e0ced692cc7a057d5e45798a052a14403420004a40ad59a2050ebe92479bd5fb16bb2e45b6465eb3cb2b1effe423fabe6cb7424db8219ef0bab80acf26fd70595b61fe4760d33eed80dd03d2fd0dfb27b8ce75cr   r   r   r   s      r   "test_import_private_rfc5915_only_1z-TestImport.test_import_private_rfc5915_only_1   s3     p!)H"5t=RS bcr   N)r   r   r   r   r   r   r   r   r   r   r   r}   r}      s    ;@dddr   r}   c                   l     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Z xZS )TestImport_P192c                 Z    t        t        | 
  |i | t               \  | _        | _        y N)superr   __init__rO   ref_private
ref_publicr   argskwargs	__class__s      r   r   zTestImport_P192.__init__   )    ot-t>v>,@,B)$/r   c                 B   t        d      }t        j                  |      }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_p192_public.derr0   r   _import_subjectPublicKeyInfor   r   _import_derr   r   key_filerk   s      r   test_import_public_derz&TestImport_P192.test_import_public_der   w    23..x8#.ooh-#.nnX&#.r   c                     t        d      }t        |      }t        j                  |d      }| j	                  | j
                  |       y )Nr   P192
curve_namer0   r{   r   r   r   r   r   r   rw   rk   s       r   test_import_sec1_uncompressedz-TestImport_P192.test_import_sec1_uncompressed   ;    23+H5nnX&9#.r   c                     t        d      }t        |      }t        j                  |d      }| j	                  | j
                  |       y )Necc_p192_public_compressed.derr   r   r   r   s       r   test_import_sec1_compressedz+TestImport_P192.test_import_sec1_compressed   ;    =>+H5nnX&9#.r   c                 D   t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_p192_private.derr0   r   r   r   r   r   r   r   s      r   test_import_rfc5915_derz'TestImport_P192.test_import_rfc5915_der       34%%h5))3/ooh-))3/nnX&))3/r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Necc_p192_private_p8_clear.derr0   r   r   r   r   r   r   s      r   test_import_private_pkcs8_clearz/TestImport_P192.test_import_private_pkcs8_clear  W    <=ooh-))3/nnX&))3/r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p192_private_p8_clear.pemr0   r   r   r   r   r   s      r   &test_import_private_pkcs8_in_pem_clearz6TestImport_P192.test_import_private_pkcs8_in_pem_clear  1    <=nnX&))3/r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_p192_private_p8.dersecretr   r   s      r   %test_import_private_pkcs8_encrypted_1z5TestImport_P192.test_import_private_pkcs8_encrypted_1  Y    67ooh1))3/nnXx0))3/r   c                 ~    t        d      }t        j                  |d      }| j                  | j                  |       y )Nzecc_p192_private_p8.pemr   r   r   s      r   %test_import_private_pkcs8_encrypted_2z5TestImport_P192.test_import_private_pkcs8_encrypted_2  3    67nnXx0))3/r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Nzecc_p192_x509.derr0   r   r   r   r   r   r   s      r   test_import_x509_derz$TestImport_P192.test_import_x509_der   S    01ooh-#.nnX&#.r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p192_public.pemr0   r   r   r   r   r   s      r   test_import_public_pemz&TestImport_P192.test_import_public_pem)  /    23nnX&#.r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p192_private.pemr   r   s      r   test_import_private_pemz'TestImport_P192.test_import_private_pem/  1    34nnX&))3/r   c                    dD ]}  }t        d|z        }t        j                  |d      }| j                  | j                  |       t        j                  t        |      d      }| j                  | j                  |        y )Ndes3aes128aes192aes256
aes256_gcmzecc_p192_private_enc_%s.pemr      secretr0   r   r   r   r   r   r   algor   rk   s       r   !test_import_private_pem_encryptedz1TestImport_P192.test_import_private_pem_encrypted5  q    F 	4D !>!EFH..84CT--s3..x)<CT--s3	4r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Nzecc_p192_x509.pemr   r   s      r   test_import_x509_pemz$TestImport_P192.test_import_x509_pem?  /    01nnX&#.r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   s   @r   r   r      sJ    C
///
00000//04/r   r   c                   r     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Z xZS )TestImport_P224c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   r   r   rS   r   r   r   s      r   r   zTestImport_P224.__init__H  r   r   c                 B   t        d      }t        j                  |      }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_p224_public.derr   r   s      r   r   z&TestImport_P224.test_import_public_derL  r   r   c                     t        d      }t        |      }t        j                  |d      }| j	                  | j
                  |       y )Nr   P224r   r   r   s       r   r   z-TestImport_P224.test_import_sec1_uncompressedX  r   r   c                     t        d      }t        |      }t        j                  |d      }| j	                  | j
                  |       y )Necc_p224_public_compressed.derr   r   r   r   s       r   r   z+TestImport_P224.test_import_sec1_compressed^  r   r   c                 D   t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_p224_private.derr   r   s      r   r   z'TestImport_P224.test_import_rfc5915_derd  r   r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Necc_p224_private_p8_clear.derr   r   s      r   r   z/TestImport_P224.test_import_private_pkcs8_clearp  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p224_private_p8_clear.pemr   r   s      r   r   z6TestImport_P224.test_import_private_pkcs8_in_pem_cleary  r   r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_p224_private_p8.derr   r   r   s      r   r   z5TestImport_P224.test_import_private_pkcs8_encrypted_1  r   r   c                 ~    t        d      }t        j                  |d      }| j                  | j                  |       y )Nzecc_p224_private_p8.pemr   r   r   s      r   r   z5TestImport_P224.test_import_private_pkcs8_encrypted_2  r   r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_p224_private_p8_2.derr   r   r   s      r   %test_import_private_pkcs8_encrypted_3z5TestImport_P224.test_import_private_pkcs8_encrypted_3  Y    89ooh1))3/nnXx0))3/r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Nzecc_p224_x509.derr   r   s      r   r   z$TestImport_P224.test_import_x509_der  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p224_public.pemr   r   s      r   r   z&TestImport_P224.test_import_public_pem  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p224_private.pemr   r   s      r   r   z'TestImport_P224.test_import_private_pem  r   r   c                    dD ]}  }t        d|z        }t        j                  |d      }| j                  | j                  |       t        j                  t        |      d      }| j                  | j                  |        y )Nr   zecc_p224_private_enc_%s.pemr   r   r   r   s       r   r   z1TestImport_P224.test_import_private_pem_encrypted  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Nzecc_p224_x509.pemr   r   s      r   r   z$TestImport_P224.test_import_x509_pem  r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   s   @r   r   r   F  sO    C
///
000000//04/r   r   c                        e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )TestImport_P256c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   r  r   rX   r   r   r   s      r   r   zTestImport_P256.__init__  r   r   c                 B   t        d      }t        j                  |      }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_p256_public.derr   r   s      r   r   z&TestImport_P256.test_import_public_der  r   r   c                     t        d      }t        |      }t        j                  |d      }| j	                  | j
                  |       y )Nr  P256r   r   r   s       r   r   z-TestImport_P256.test_import_sec1_uncompressed  r   r   c                     t        d      }t        |      }t        j                  |d      }| j	                  | j
                  |       y )Necc_p256_public_compressed.derr  r   r   r   s       r   r   z+TestImport_P256.test_import_sec1_compressed  r   r   c                 D   t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_p256_private.derr   r   s      r   r   z'TestImport_P256.test_import_rfc5915_der  r   r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Necc_p256_private_p8_clear.derr   r   s      r   r   z/TestImport_P256.test_import_private_pkcs8_clear  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p256_private_p8_clear.pemr   r   s      r   r   z6TestImport_P256.test_import_private_pkcs8_in_pem_clear  r   r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_p256_private_p8.derr   r   r   s      r   r   z5TestImport_P256.test_import_private_pkcs8_encrypted_1  r   r   c                 ~    t        d      }t        j                  |d      }| j                  | j                  |       y )Nzecc_p256_private_p8.pemr   r   r   s      r   r   z5TestImport_P256.test_import_private_pkcs8_encrypted_2  r   r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_p256_private_p8_2.derr   r   r   s      r   r  z5TestImport_P256.test_import_private_pkcs8_encrypted_3  r  r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Nzecc_p256_x509.derr   r   s      r   r   z$TestImport_P256.test_import_x509_der  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p256_public.pemr   r   s      r   r   z&TestImport_P256.test_import_public_pem  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p256_private.pemr   r   s      r   r   z'TestImport_P256.test_import_private_pem  r   r   c                 D    t        d      }t        j                  |      }y )Nzecc_p256_private_ecparams.pemr0   r   r   r   s      r   %test_import_private_pem_with_ecparamsz5TestImport_P256.test_import_private_pem_with_ecparams#  s    <=nnX&r   c                    dD ]}  }t        d|z        }t        j                  |d      }| j                  | j                  |       t        j                  t        |      d      }| j                  | j                  |        y )Nr   zecc_p256_private_enc_%s.pemr   r   r   r   s       r   r   z1TestImport_P256.test_import_private_pem_encrypted(  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Nzecc_p256_x509.pemr   r   s      r   r   z$TestImport_P256.test_import_x509_pem2  r   r   c                     t        d      }t        j                  |      }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Necc_p256_public_openssh.txtr0   r   _import_openssh_publicr   r   r   r   s      r   test_import_openssh_publicz*TestImport_P256.test_import_openssh_public8  S    :;((2#.nnX&#.r   c                     t        d      }t        d      }t        j                  |      }t        j                  |      }| j                  ||       y )Nzecc_p256_private_openssh.pemz ecc_p256_private_openssh_old.pemr0   r   r   r   r   r   key_file_oldrk   key_olds        r   !test_import_openssh_private_clearz1TestImport_P256.test_import_openssh_private_clearA  D    ;< !CDnnX&...g&r   c                     t        d      }t        d      }t        j                  |d      }t        j                  |      }| j                  ||       y )Nz ecc_p256_private_openssh_pwd.pemz$ecc_p256_private_openssh_pwd_old.pem   passwordr-  r.  s        r   $test_import_openssh_private_passwordz4TestImport_P256.test_import_openssh_private_passwordI  F    ?@ !GHnnX{3...g&r   )r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r#  r   r   r*  r1  r5  r   r   s   @r   r  r    sc    C
///
000000//0'
4//''r   r  c                        e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )TestImport_P384c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   r8  r   r^   r   r   r   s      r   r   zTestImport_P384.__init__T  r   r   c                 B   t        d      }t        j                  |      }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_p384_public.derr   r   s      r   r   z&TestImport_P384.test_import_public_derX  r   r   c                     t        d      }t        |      }t        j                  |d      }| j	                  | j
                  |       y )Nr;  P384r   r   r   s       r   r   z-TestImport_P384.test_import_sec1_uncompressedd  r   r   c                     t        d      }t        |      }t        j                  |d      }| j	                  | j
                  |       y )Necc_p384_public_compressed.derr=  r   r   r   s       r   r   z+TestImport_P384.test_import_sec1_compressedj  r   r   c                 D   t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_p384_private.derr   r   s      r   r   z'TestImport_P384.test_import_rfc5915_derp  r   r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Necc_p384_private_p8_clear.derr   r   s      r   r   z/TestImport_P384.test_import_private_pkcs8_clear|  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p384_private_p8_clear.pemr   r   s      r   r   z6TestImport_P384.test_import_private_pkcs8_in_pem_clear  r   r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_p384_private_p8.derr   r   r   s      r   r   z5TestImport_P384.test_import_private_pkcs8_encrypted_1  r   r   c                 ~    t        d      }t        j                  |d      }| j                  | j                  |       y )Nzecc_p384_private_p8.pemr   r   r   s      r   r   z5TestImport_P384.test_import_private_pkcs8_encrypted_2  r   r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_p384_private_p8_2.derr   r   r   s      r   r  z5TestImport_P384.test_import_private_pkcs8_encrypted_3  r  r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Nzecc_p384_x509.derr   r   s      r   r   z$TestImport_P384.test_import_x509_der  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p384_public.pemr   r   s      r   r   z&TestImport_P384.test_import_public_pem  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p384_private.pemr   r   s      r   r   z'TestImport_P384.test_import_private_pem  r   r   c                    dD ]}  }t        d|z        }t        j                  |d      }| j                  | j                  |       t        j                  t        |      d      }| j                  | j                  |        y )Nr   zecc_p384_private_enc_%s.pemr   r   r   r   s       r   r   z1TestImport_P384.test_import_private_pem_encrypted  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Nzecc_p384_x509.pemr   r   s      r   r   z$TestImport_P384.test_import_x509_pem  r   r   c                     t        d      }t        j                  |      }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Necc_p384_public_openssh.txtr(  r   s      r   r*  z*TestImport_P384.test_import_openssh_public  r+  r   c                     t        d      }t        d      }t        j                  |      }t        j                  |      }| j                  ||       y )Nzecc_p384_private_openssh.pemz ecc_p384_private_openssh_old.pemr-  r.  s        r   r1  z1TestImport_P384.test_import_openssh_private_clear  r2  r   c                     t        d      }t        d      }t        j                  |d      }t        j                  |      }| j                  ||       y )Nz ecc_p384_private_openssh_pwd.pemz$ecc_p384_private_openssh_pwd_old.pemr4  r-  r.  s        r   r5  z4TestImport_P384.test_import_openssh_private_password  r6  r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r*  r1  r5  r   r   s   @r   r8  r8  R  ^    C
///
000000//04//''r   r8  c                        e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )TestImport_P521c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   rW  r   rc   r   r   r   s      r   r   zTestImport_P521.__init__  r   r   c                 B   t        d      }t        j                  |      }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_p521_public.derr   r   s      r   r   z&TestImport_P521.test_import_public_der  r   r   c                     t        d      }t        |      }t        j                  |d      }| j	                  | j
                  |       y )NrZ  P521r   r   r   s       r   r   z-TestImport_P521.test_import_sec1_uncompressed  r   r   c                     t        d      }t        |      }t        j                  |d      }| j	                  | j
                  |       y )Necc_p521_public_compressed.derr\  r   r   r   s       r   r   z+TestImport_P521.test_import_sec1_compressed  r   r   c                 D   t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_p521_private.derr   r   s      r   r   z'TestImport_P521.test_import_rfc5915_der   r   r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Necc_p521_private_p8_clear.derr   r   s      r   r   z/TestImport_P521.test_import_private_pkcs8_clear  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p521_private_p8_clear.pemr   r   s      r   r   z6TestImport_P521.test_import_private_pkcs8_in_pem_clear  r   r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_p521_private_p8.derr   r   r   s      r   r   z5TestImport_P521.test_import_private_pkcs8_encrypted_1  r   r   c                 ~    t        d      }t        j                  |d      }| j                  | j                  |       y )Nzecc_p521_private_p8.pemr   r   r   s      r   r   z5TestImport_P521.test_import_private_pkcs8_encrypted_2$  r   r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_p521_private_p8_2.derr   r   r   s      r   r  z5TestImport_P521.test_import_private_pkcs8_encrypted_3*  r  r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Nzecc_p521_x509.derr   r   s      r   r   z$TestImport_P521.test_import_x509_der3  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p521_public.pemr   r   s      r   r   z&TestImport_P521.test_import_public_pem<  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_p521_private.pemr   r   s      r   r   z'TestImport_P521.test_import_private_pemB  r   r   c                    dD ]}  }t        d|z        }t        j                  |d      }| j                  | j                  |       t        j                  t        |      d      }| j                  | j                  |        y )Nr   zecc_p521_private_enc_%s.pemr   r   r   r   s       r   r   z1TestImport_P521.test_import_private_pem_encryptedH  r   r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Nzecc_p521_x509.pemr   r   s      r   r   z$TestImport_P521.test_import_x509_pemR  r   r   c                     t        d      }t        j                  |      }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Necc_p521_public_openssh.txtr(  r   s      r   r*  z*TestImport_P521.test_import_openssh_publicX  r+  r   c                     t        d      }t        d      }t        j                  |      }t        j                  |      }| j                  ||       y )Nzecc_p521_private_openssh.pemz ecc_p521_private_openssh_old.pemr-  r.  s        r   r1  z1TestImport_P521.test_import_openssh_private_cleara  r2  r   c                     t        d      }t        d      }t        j                  |d      }t        j                  |      }| j                  ||       y )Nz ecc_p521_private_openssh_pwd.pemz$ecc_p521_private_openssh_pwd_old.pemr4  r-  r.  s        r   r5  z4TestImport_P521.test_import_openssh_private_passwordi  r6  r   rT  r   s   @r   rW  rW    rU  r   rW  c                        e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )TestExport_P192c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   rt  r   rO   r   r   r   s      r   r   zTestExport_P192.__init__t  r   r   c                 .   t        d      }| j                  j                  d      }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nr   FDERformatry  compressr0   r   _export_subjectPublicKeyInfor   
export_keyr   r   encodeds      r   #test_export_public_der_uncompressedz3TestExport_P192.test_export_public_der_uncompressedx      23//>>uE7+//,,E,:7+//,,EE,J7+r   c                     t        d      }t        j                  |      }|j                  dd      }t        d      }| j	                  ||       y )Nr   rw  Trz  r   r0   r   r   r~  r   r   r   pub_keykey_file_compressedkey_file_compressed_refs        r   !test_export_public_der_compressedz1TestExport_P192.test_export_public_der_compressed  O    23..*%000M"+,L"M,.EFr   c                     t        d      }t        |      }| j                  j                  d      }| j	                  ||       y )Nr   SEC1rx  r0   r{   r   r~  r   r   r   rw   r  s       r   $test_export_public_sec1_uncompressedz4TestExport_P192.test_export_public_sec1_uncompressed  >    23+H5//,,F,;(r   c                     t        d      }| j                  j                  dd      }t        d      }t        |      }| j	                  ||       y )Nr   r  Trz  r   r0   r   r~  r{   r   r   r   r  r  rw   s        r   "test_export_public_sec1_compressedz2TestExport_P192.test_export_public_sec1_compressed  M    23//,,FT,J"+,L"M+,CD(r   c                     t        d      }| j                  j                         }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nr   rw  Fry  	use_pkcs8r0   r   _export_rfc5915_private_derr   r~  r  s      r   test_export_rfc5915_private_derz/TestExport_P192.test_export_rfc5915_private_der  ^    34"">>@7+ ""--Ue-L7+r   c                     t        d      }| j                  j                         }| j                  ||       | j                  j	                  d      }| j                  ||       y )Nr   rw  rx  r0   r   _export_pkcs8r   r~  r  s      r   test_export_private_pkcs8_clearz/TestExport_P192.test_export_private_pkcs8_clear  \    <=""0027+ ""--U-;7+r   c                 4   | j                   j                  dd      }| j                  t        t        j
                  |d        t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j                  |d      }| j                  | j                   |       | j                   j                  dddddi	      }t	        j                  |d      }| j                  | j                   |       y )
Nr    PBKDF2WithHMAC-SHA1AndAES128-CBC
passphrase
protectionrw  ry  r  r  z"PBKDF2WithHMAC-SHA224AndAES192-CBCiteration_count{   ry  r  r  prot_params	r   r  r   r   r   _import_pkcs8r   r~  r   r   r  decodeds      r   #test_export_private_pkcs8_encryptedz3TestExport_P192.test_export_private_pkcs8_encrypted  s   ""00H?a 1 c 	*c&7&7$G##GX6))73 ""--U;C;] . _ ..(3))73 ""--U;C;_=Ns<S . U ..(3))73r   c                 L   t        dd      j                         }| j                  j                  d      }| j	                  ||       | j
                  j                  d      }| j	                  ||       | j
                  j                  dd      }| j	                  ||       y )Nr   rtFPEMrx  rz  r0   stripr   _export_public_pemr   r   r~  r  s      r   #test_export_public_pem_uncompressedz3TestExport_P192.test_export_public_pem_uncompressed      2D9??A""55e<7+ //,,E,:7+//,,EE,J7+r   c                     t        dd      j                         }t        j                  |      }|j	                  dd      }t        dd      j                         }| j                  ||       y )Nr   r  r  Trz  zecc_p192_public_compressed.pemr0   r  r   r   r~  r   r  s        r   !test_export_public_pem_compressedz1TestExport_P192.test_export_public_pem_compressed  e    2D9??A..*%000M"+,Ld"S"Y"Y"[,.EFr   c                     t        dd      j                         }| j                  j                  d       }| j	                  ||       | j                  j                  dd      }| j	                  ||       y )Nr   r  r  Fr  r0   r  r   _export_private_pemr   r~  r  s      r   test_export_private_pem_clearz-TestExport_P192.test_export_private_pem_clear  k    3T:@@B""66t<7+ ""--Ue-L7+r   c                    | j                   j                  d      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j
                  |d      }| j                  | j                   |       y Nr   )r  zEC PRIVATE KEYr   r  Fry  r  r  r   r  r   r   r   r   r   r~  r  s      r   !test_export_private_pem_encryptedz1TestExport_P192.test_export_private_pem_encrypted      ""66)6L 	*cnng>7***..(3))73 ""--U4<38 . : ..(3))73r   c                     t        dd      j                         }| j                  j                         }| j	                  ||       | j                  j                  d      }| j	                  ||       y )Nr   r  r  rx  r0   r  r   (_export_private_clear_pkcs8_in_clear_pemr   r~  r  s      r   #test_export_private_pkcs8_and_pem_1z3TestExport_P192.test_export_private_pkcs8_and_pem_1  g    <dCIIK""KKM7+ ""--U-;7+r   c                    | j                   j                  dd      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j
                  |d      }| j                  | j                   |       y Nr   r  )r  ENCRYPTED PRIVATE KEYr  r  r   ,_export_private_encrypted_pkcs8_in_clear_pemr   r   r   r   r   r~  r  s      r   #test_export_private_pkcs8_and_pem_2z3TestExport_P192.test_export_private_pkcs8_and_pem_2      ""OOPX)K P M 	*cnng>&'111..(3))73 ""--U4<4V . X ..(3))73r   c                    | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y Nr  r   r  ry  r  r  randfuncFry  r  r  r  r   r~  rt   r   r   encoded1encoded2s      r   	test_prngzTestExport_P192.test_prng"      ##..e5=5W3A3C / E ##..e5=5W3A3C / E 	8, ##..e495=3A3C / E ##..e495=3A3C / E 	8,r   c                     | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y Nr  Fr   r  r   r  r  s      r   test_byte_or_string_passphrasez.TestExport_P192.test_byte_or_string_passphrase:  j    ##..e495=3A3C / E ##..e495>3A3C / E 	8,r   c                 b   | j                  t        | j                  j                  d       | j                  j                  ddd       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  dddd	
       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  ddd       | j                  t        | j                  j                  ddd	       y NXXXrx  r  r   Fr  ry  r  rw  r  ry  r  r  r  r  r3   r  r   r   r   r~  r   r   s    r   test_error_params1z"TestExport_P192.test_error_params1E     *d&6&6&A&A%P 	##5X). 	$ 	0*d&6&6&A&A%19 	 	; 	*d&6&6&A&A%19051S 	 	U 	*doo&@&@$) 	 	+ 	*d&6&6&A&A%13u 	 	F*d&6&6&A&A%131S 	 	Ur   c                 0   d}d}t        j                  |      }t        |j                  j                  dz        }| j                  |d       t        j                  |      }t        |j                  j                  dz        }| j                  |d       y )Nz-----BEGIN EC PRIVATE KEY-----
        MF8CAQEEGHvhXmIW95JxZYfd4AUPu9BwknjuvS36aqAKBggqhkjOPQMBAaE0AzIA
        BLJZCyTu35DQIlqvMlBynn3k1Ig+dWfg/brRhHecxptrbloqFSP8ITw0CwbGF+2X
        5g==
        -----END EC PRIVATE KEY-----z-----BEGIN EC PRIVATE KEY-----
        MF8CAQEEGA3rAotUaWl7d47eX6tz9JmLzOMJwl13XaAKBggqhkjOPQMBAaE0AzIA
        BG4tHlTBBBGokcWmGm2xubVB0NvPC/Ou5AYwivs+3iCxmEjsymVAj6iiuX2Lxr6g
        /Q==
        -----END EC PRIVATE KEY-----   i  i  r   r   intpointQyr   r   pem1pem2key1low16key2s         r   test_compressed_curvez%TestExport_P192.test_compressed_curve`  |    (( ~~d#DKKMME)*'~~d#DKKMME)*'r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   s   @r   rt  rt  r  sa    C
,G))	,	,46,G	,4&
,4*-0	-U6(r   rt  c                        e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )TestExport_P224c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   r  r   rS   r   r   r   s      r   r   zTestExport_P224.__init__{  r   r   c                 .   t        d      }| j                  j                  d      }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nr   Frw  rx  rz  r|  r  s      r   r  z3TestExport_P224.test_export_public_der_uncompressed  r  r   c                     t        d      }t        j                  |      }|j                  dd      }t        d      }| j	                  ||       y )Nr   rw  Trz  r   r  r  s        r   r  z1TestExport_P224.test_export_public_der_compressed  r  r   c                     t        d      }t        |      }| j                  j                  d      }| j	                  ||       y )Nr   r  rx  r  r  s       r   r  z4TestExport_P224.test_export_public_sec1_uncompressed  r  r   c                     t        d      }| j                  j                  dd      }t        d      }t        |      }| j	                  ||       y )Nr   r  Trz  r   r  r  s        r   r  z2TestExport_P224.test_export_public_sec1_compressed  r  r   c                     t        d      }| j                  j                         }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nr   rw  Fr  r  r  s      r   r  z/TestExport_P224.test_export_rfc5915_private_der  r  r   c                     t        d      }| j                  j                         }| j                  ||       | j                  j	                  d      }| j                  ||       y )Nr   rw  rx  r  r  s      r   r  z/TestExport_P224.test_export_private_pkcs8_clear  r  r   c                    | j                   j                  dd      }| j                  t        t        j
                  |d        t	        j
                  |d      }| j                  | j                   |       | j                   j                  dddddi      }t	        j                  |d      }| j                  | j                   |       y )	Nr   r  r  rw  z&PBKDF2WithHMAC-SHA512-224AndAES128-CBCr  r  r  r  r  s      r   r  z3TestExport_P224.test_export_private_pkcs8_encrypted  s    ""00H?a 1 c 	*c&7&7$G##GX6))73 ""--U;C;c=Ns<S . U ..(3))73r   c                 L   t        dd      j                         }| j                  j                  d      }| j	                  ||       | j
                  j                  d      }| j	                  ||       | j
                  j                  dd      }| j	                  ||       y )Nr  r  Fr  rx  rz  r  r  s      r   r  z3TestExport_P224.test_export_public_pem_uncompressed  r  r   c                     t        dd      j                         }t        j                  |      }|j	                  dd      }t        dd      j                         }| j                  ||       y )Nr  r  r  Trz  zecc_p224_public_compressed.pemr  r  s        r   r  z1TestExport_P224.test_export_public_pem_compressed  r  r   c                     t        dd      j                         }| j                  j                  d       }| j	                  ||       | j                  j                  dd      }| j	                  ||       y )Nr  r  r  Fr  r  r  s      r   r  z-TestExport_P224.test_export_private_pem_clear  r  r   c                    | j                   j                  d      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j
                  |d      }| j                  | j                   |       y r  r  r  s      r   r  z1TestExport_P224.test_export_private_pem_encrypted  r  r   c                     t        dd      j                         }| j                  j                         }| j	                  ||       | j                  j                  d      }| j	                  ||       y )Nr   r  r  rx  r  r  s      r   r  z3TestExport_P224.test_export_private_pkcs8_and_pem_1   r  r   c                    | j                   j                  dd      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j
                  |d      }| j                  | j                   |       y r  r  r  s      r   r  z3TestExport_P224.test_export_private_pkcs8_and_pem_2  r  r   c                    | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y r  r  r  s      r   r  zTestExport_P224.test_prng!  r  r   c                     | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y r  r  r  s      r   r  z.TestExport_P224.test_byte_or_string_passphrase9  r  r   c                 b   | j                  t        | j                  j                  d       | j                  j                  ddd       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  dddd	
       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  ddd       | j                  t        | j                  j                  ddd	       y r  r  r   s    r   r  z"TestExport_P224.test_error_params1D  r  r   c                 0   d}d}t        j                  |      }t        |j                  j                  dz        }| j                  |d       t        j                  |      }t        |j                  j                  dz        }| j                  |d       y )Nz-----BEGIN EC PRIVATE KEY-----
        MGgCAQEEHPYicBNI9nd6wDKAX2l+f3A0Q+KWUQeMqSt5GoOgBwYFK4EEACGhPAM6
        AATCL6rUIDT14zXKoS5GQUMDP/tpc+1iI/FyEZikt2roKDkhU5q08srmqaysbfJN
        eUr7Xf1lnCVGag==
        -----END EC PRIVATE KEY-----z-----BEGIN EC PRIVATE KEY-----
        MGgCAQEEHEFjbaVPLJ3ngZyCibCvT0RLUqSlHjC5Z3e0FtugBwYFK4EEACGhPAM6
        AAT5IvL2V6m48y1JLMGr6ZbnOqNKP9hMf9mxyVkk6/SaRoBoJVkXrNIpYL0P7DS7
        QF8E/OGeZRwvow==
        -----END EC PRIVATE KEY-----r  ijF  i/  r  r  s         r   r  z%TestExport_P224.test_compressed_curve_  r  r   r  r   s   @r   r  r  y  sa    C
,G))	,	,4&,G	,4&
,4*-0	-U6(r   r  c                        e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )TestExport_P256c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   r  r   rX   r   r   r   s      r   r   zTestExport_P256.__init__z  r   r   c                 .   t        d      }| j                  j                  d      }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nr  Frw  rx  rz  r|  r  s      r   r  z3TestExport_P256.test_export_public_der_uncompressed~  r  r   c                     t        d      }t        j                  |      }|j                  dd      }t        d      }| j	                  ||       y )Nr  rw  Trz  r  r  r  s        r   r  z1TestExport_P256.test_export_public_der_compressed  r  r   c                     t        d      }t        |      }| j                  j                  d      }| j	                  ||       y )Nr  r  rx  r  r  s       r   r  z4TestExport_P256.test_export_public_sec1_uncompressed  r  r   c                     t        d      }| j                  j                  dd      }t        d      }t        |      }| j	                  ||       y )Nr  r  Trz  r  r  r  s        r   r  z2TestExport_P256.test_export_public_sec1_compressed  r  r   c                     t        d      }| j                  j                         }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nr  rw  Fr  r  r  s      r   r  z/TestExport_P256.test_export_rfc5915_private_der  r  r   c                     t        d      }| j                  j                         }| j                  ||       | j                  j	                  d      }| j                  ||       y )Nr  rw  rx  r  r  s      r   r  z/TestExport_P256.test_export_private_pkcs8_clear  r  r   c                 4   | j                   j                  dd      }| j                  t        t        j
                  |d        t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j                  |d      }| j                  | j                   |       | j                   j                  dddddi	      }t	        j                  |d      }| j                  | j                   |       y )
Nr   r  r  rw  r  z&PBKDF2WithHMAC-SHA512-256AndAES128-CBCr  r  r  r  r  s      r   r  z3TestExport_P256.test_export_private_pkcs8_encrypted  s   ""00H?a 1 c 	*c&7&7$G##GX6))73 ""--U;C;] . _ ..(3))73 ""--U;C;c=Ns<S . U ..(3))73r   c                 L   t        dd      j                         }| j                  j                  d      }| j	                  ||       | j
                  j                  d      }| j	                  ||       | j
                  j                  dd      }| j	                  ||       y )Nr  r  Fr  rx  rz  r  r  s      r   r  z3TestExport_P256.test_export_public_pem_uncompressed  r  r   c                     t        dd      j                         }t        j                  |      }|j	                  dd      }t        dd      j                         }| j                  ||       y )Nr  r  r  Trz  zecc_p256_public_compressed.pemr  r  s        r   r  z1TestExport_P256.test_export_public_pem_compressed  r  r   c                     t        dd      j                         }| j                  j                  d       }| j	                  ||       | j                  j                  dd      }| j	                  ||       y )Nr   r  r  Fr  r  r  s      r   r  z-TestExport_P256.test_export_private_pem_clear  r  r   c                    | j                   j                  d      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j
                  |d      }| j                  | j                   |       y r  r  r  s      r   r  z1TestExport_P256.test_export_private_pem_encrypted  r  r   c                     t        dd      j                         }| j                  j                         }| j	                  ||       | j                  j                  d      }| j	                  ||       y )Nr  r  r  rx  r  r  s      r   r  z3TestExport_P256.test_export_private_pkcs8_and_pem_1  r  r   c                    | j                   j                  dd      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j
                  |d      }| j                  | j                   |       y r  r  r  s      r   r  z3TestExport_P256.test_export_private_pkcs8_and_pem_2  r  r   c                 0   t        dd      }| j                  j                  d      }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nr'  r  FOpenSSHrx  rz  r0   r   _export_opensshr   r~  r  s      r    test_export_openssh_uncompressedz0TestExport_P256.test_export_openssh_uncompressed(      :DA//11%87+ //,,I,>7+//,,I,N7+r   c                     t        dd      }t        j                  |      }|j                  dd      }t	        |      t	        |      kD  sJ | j                  |t        j                  |             y )Nr'  r  r  Trz  r0   r   r   r~  lenr   r   r   r  r  s       r   test_export_openssh_compressedz.TestExport_P256.test_export_openssh_compressed6  e    :DA..*%00	D0Q8}s#67777#..1D"EFr   c                    | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y r  r  r  s      r   r  zTestExport_P256.test_prng>  r  r   c                     | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y r  r  r  s      r   r  z.TestExport_P256.test_byte_or_string_passphraseV  r  r   c                    | j                  t        | j                  j                  d       | j                  j                  ddd       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  dddd	
       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  ddd       | j                  t        | j                  j                  ddd	       | j                  t        | j                  j                  dd       y Nr  rx  r  r   Fr  r  rw  r  r  r  r3   r  r  r  r   s    r   r  z"TestExport_P256.test_error_params1a  I   *d&6&6&A&A%P 	##5X). 	$ 	0*d&6&6&A&A%19 	 	; 	*d&6&6&A&A%19051S 	 	U 	*doo&@&@$) 	 	+ 	*d&6&6&A&A%13u 	 	F*d&6&6&A&A%131S 	 	U
 	*d&6&6&A&A)19 	 	;r   c                 0   d}d}t        j                  |      }t        |j                  j                  dz        }| j                  |d       t        j                  |      }t        |j                  j                  dz        }| j                  |d       y )Nz-----BEGIN EC PRIVATE KEY-----
        MFcCAQEEIHTuc09jC51xXomV6MVCDN+DpAAvSmaJWZPTEHM6D5H1oAoGCCqGSM49
        AwEHoSQDIgACWFuGbHe8yJ43rir7PMTE9w8vHz0BSpXHq90Xi7/s+a0=
        -----END EC PRIVATE KEY-----z-----BEGIN EC PRIVATE KEY-----
        MFcCAQEEIFggiPN9SQP+FAPTCPp08fRUz7rHp2qNBRcBJ1DXhb3ZoAoGCCqGSM49
        AwEHoSQDIgADLpph1trTIlVfa8NJvlMUPyWvL+wP+pW3BJITUL/wj9A=
        -----END EC PRIVATE KEY-----r  i  iWn  r  r  s         r   r  z%TestExport_P256.test_compressed_curve  s|    ((
 ~~d#DKKMME)*'~~d#DKKMME)*'r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r(  r  r  r  r  r   r   s   @r   r  r  x  sl    C
,G))	,	,46,G	,4&
,4*,G-0	-;@(r   r  c                        e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )TestExport_P384c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   r2  r   r^   r   r   r   s      r   r   zTestExport_P384.__init__  r   r   c                 .   t        d      }| j                  j                  d      }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nr;  Frw  rx  rz  r|  r  s      r   r  z3TestExport_P384.test_export_public_der_uncompressed  r  r   c                     t        d      }t        j                  |      }|j                  dd      }t        d      }| j	                  ||       y )Nr;  rw  Trz  r?  r  r  s        r   r  z1TestExport_P384.test_export_public_der_compressed  r  r   c                     t        d      }t        |      }| j                  j                  d      }| j	                  ||       y )Nr;  r  rx  r  r  s       r   r  z4TestExport_P384.test_export_public_sec1_uncompressed  r  r   c                     t        d      }| j                  j                  dd      }t        d      }t        |      }| j	                  ||       y )Nr;  r  Trz  r?  r  r  s        r   r  z2TestExport_P384.test_export_public_sec1_compressed  r  r   c                     t        d      }| j                  j                         }| j                  ||       | j                  j	                  dd      }| j                  ||       y )NrA  rw  Fr  r  r  s      r   r  z/TestExport_P384.test_export_rfc5915_private_der  r  r   c                     t        d      }| j                  j                         }| j                  ||       | j                  j	                  d      }| j                  ||       y )NrC  rw  rx  r  r  s      r   r  z/TestExport_P384.test_export_private_pkcs8_clear  r  r   c                 4   | j                   j                  dd      }| j                  t        t        j
                  |d        t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j                  |d      }| j                  | j                   |       | j                   j                  dddddi	      }t	        j                  |d      }| j                  | j                   |       y 
Nr   r  r  rw  r  z"PBKDF2WithHMAC-SHA384AndAES128-CBCr  r  r  r  r  s      r   r  z3TestExport_P384.test_export_private_pkcs8_encrypted     ""00H7Y 1 [ 	*c&7&7$G##GX6))73 ""--U4<4V . X ..(3))73 ""--U4<4X6G5L . N ..(3))73r   c                 L   t        dd      j                         }| j                  j                  d      }| j	                  ||       | j
                  j                  d      }| j	                  ||       | j
                  j                  dd      }| j	                  ||       y )NrK  r  Fr  rx  rz  r  r  s      r   r  z3TestExport_P384.test_export_public_pem_uncompressed  r  r   c                     t        dd      j                         }t        j                  |      }|j	                  dd      }t        dd      j                         }| j                  ||       y )NrK  r  r  Trz  zecc_p384_public_compressed.pemr  r  s        r   r  z1TestExport_P384.test_export_public_pem_compressed   r  r   c                     t        dd      j                         }| j                  j                  d       }| j	                  ||       | j                  j                  dd      }| j	                  ||       y )NrM  r  r  Fr  r  r  s      r   r  z-TestExport_P384.test_export_private_pem_clear	  r  r   c                    | j                   j                  d      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j
                  |d      }| j                  | j                   |       y r  r  r  s      r   r  z1TestExport_P384.test_export_private_pem_encrypted  r  r   c                     t        dd      j                         }| j                  j                         }| j	                  ||       | j                  j                  d      }| j	                  ||       y )NrE  r  r  rx  r  r  s      r   r  z3TestExport_P384.test_export_private_pkcs8_and_pem_1'  r  r   c                    | j                   j                  dd      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j
                  |d      }| j                  | j                   |       y r  r  r  s      r   r  z3TestExport_P384.test_export_private_pkcs8_and_pem_23  r  r   c                 0   t        dd      }| j                  j                  d      }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  j	                  dd      }| j                  ||       y )NrQ  r  Fr  rx  rz  r   r  s      r   r"  z0TestExport_P384.test_export_openssh_uncompressedH  r#  r   c                     t        dd      }t        j                  |      }|j                  dd      }t	        |      t	        |      kD  sJ | j                  |t        j                  |             y )NrQ  r  r  Trz  r%  r'  s       r   r(  z.TestExport_P384.test_export_openssh_compressedV  r)  r   c                    | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y r  r  r  s      r   r  zTestExport_P384.test_prng^  r  r   c                     | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y r  r  r  s      r   r  z.TestExport_P384.test_byte_or_string_passphrasev  r  r   c                    | j                  t        | j                  j                  d       | j                  j                  ddd       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  dddd	
       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  ddd       | j                  t        | j                  j                  ddd	       | j                  t        | j                  j                  dd       y r-  r  r   s    r   r  z"TestExport_P384.test_error_params1  r.  r   c                 0   d}d}t        j                  |      }t        |j                  j                  dz        }| j                  |d       t        j                  |      }t        |j                  j                  dz        }| j                  |d       y )Na  -----BEGIN EC PRIVATE KEY-----
MIGkAgEBBDAM0lEIhvXuekK2SWtdbgOcZtBaxa9TxfpO/GcDFZLCJ3JVXaTgwken
QT+C+XLtD6WgBwYFK4EEACKhZANiAATs0kZMhFDu8DoBC21jrSDPyAUn4aXZ/DM4
ylhDfWmb4LEbeszXceIzfhIUaaGs5y1xXaqf5KXTiAAYx2pKUzAAM9lcGUHCGKJG
k4AgUmVJON29XoUilcFrzjDmuye3B6Q=
-----END EC PRIVATE KEY-----a  -----BEGIN EC PRIVATE KEY-----
MIGkAgEBBDDHPFTslYLltE16fHdSDTtE/2HTmd3M8mqy5MttAm4wZ833KXiGS9oe
kFdx9sNV0KygBwYFK4EEACKhZANiAASLIE5RqVMtNhtBH/u/p/ifqOAlKnK/+RrQ
YC46ZRsnKNayw3wATdPjgja7L/DSII3nZK0G6KOOVwJBznT/e+zudUJYhZKaBLRx
/bgXyxUtYClOXxb1Y/5N7txLstYRyP0=
-----END EC PRIVATE KEY-----r  i  i  r  r  s         r   r  z%TestExport_P384.test_compressed_curve  s|    
   ~~d#DKKMME)*'~~d#DKKMME)*'r   r0  r   s   @r   r2  r2    sk    C
,G))	,	,46,G	,4&
,4*,G-0	-;>(r   r2  c                        e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )TestExport_P521c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   rJ  r   rc   r   r   r   s      r   r   zTestExport_P521.__init__  r   r   c                 .   t        d      }| j                  j                  d      }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  j	                  dd      }| j                  ||       y )NrZ  Frw  rx  rz  r|  r  s      r   r  z3TestExport_P521.test_export_public_der_uncompressed  r  r   c                     t        d      }t        j                  |      }|j                  dd      }t        d      }| j	                  ||       y )NrZ  rw  Trz  r^  r  r  s        r   r  z1TestExport_P521.test_export_public_der_compressed  r  r   c                     t        d      }t        |      }| j                  j                  d      }| j	                  ||       | j                  j                  d      }| j	                  ||       y )NrZ  r  rx  rawr  r  s       r   r  z4TestExport_P521.test_export_public_sec1_uncompressed  se    23+H5//,,F,;(//,,E,:(r   c                    t        d      }| j                  j                  dd      }t        d      }t        |      }| j	                  ||       | j                  j                  dd      }| j	                  ||       y )NrZ  r  Trz  r^  rO  r  r  s        r   r  z2TestExport_P521.test_export_public_sec1_compressed  sv    23//,,FT,J"+,L"M+,CD(//,,ED,I(r   c                     t        d      }| j                  j                         }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nr`  rw  Fr  r  r  s      r   r  z/TestExport_P521.test_export_rfc5915_private_der  r  r   c                     t        d      }| j                  j                         }| j                  ||       | j                  j	                  d      }| j                  ||       y )Nrb  rw  rx  r  r  s      r   r  z/TestExport_P521.test_export_private_pkcs8_clear  r  r   c                 4   | j                   j                  dd      }| j                  t        t        j
                  |d        t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j                  |d      }| j                  | j                   |       | j                   j                  dddddi      }t	        j                  |d      }| j                  | j                   |       y )	Nr   r  r  rw  r  r  r  r  r  r  s      r   r  z3TestExport_P521.test_export_private_pkcs8_encrypted  s   ""00H7Y 1 [ 	*c&7&7$G##GX6))73 ""--U4<4V . X ..(3))73 ""--U4<4V6G5L . N ..(3))73r   c                 L   t        dd      j                         }| j                  j                  d      }| j	                  ||       | j
                  j                  d      }| j	                  ||       | j
                  j                  dd      }| j	                  ||       y )Nrj  r  Fr  rx  rz  r  r  s      r   r  z3TestExport_P521.test_export_public_pem_uncompressed  r  r   c                     t        dd      j                         }t        j                  |      }|j	                  dd      }t        dd      j                         }| j                  ||       y )Nrj  r  r  Trz  zecc_p521_public_compressed.pemr  r  s        r   r  z1TestExport_P521.test_export_public_pem_compressed+  r  r   c                     t        dd      j                         }| j                  j                  d       }| j	                  ||       | j                  j                  dd      }| j	                  ||       y )Nrl  r  r  Fr  r  r  s      r   r  z-TestExport_P521.test_export_private_pem_clear4  r  r   c                    | j                   j                  d      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j
                  |d      }| j                  | j                   |       y r  r  r  s      r   r  z1TestExport_P521.test_export_private_pem_encrypted?  r  r   c                     t        dd      j                         }| j                  j                         }| j	                  ||       | j                  j                  d      }| j	                  ||       y )Nrd  r  r  rx  r  r  s      r   r  z3TestExport_P521.test_export_private_pkcs8_and_pem_1R  r  r   c                    | j                   j                  dd      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j
                  |d      }| j                  | j                   |       y r  r  r  s      r   r  z3TestExport_P521.test_export_private_pkcs8_and_pem_2^  r  r   c                 0   t        dd      }| j                  j                  d      }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nrp  r  Fr  rx  rz  r   r  s      r   r"  z0TestExport_P521.test_export_openssh_uncompresseds  r#  r   c                     t        dd      }t        j                  |      }|j                  dd      }t	        |      t	        |      kD  sJ | j                  |t        j                  |             y )Nrp  r  r  Trz  r%  r'  s       r   r(  z.TestExport_P521.test_export_openssh_compressed  r)  r   c                    | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y r  r  r  s      r   r  zTestExport_P521.test_prng  r  r   c                     | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y r  r  r  s      r   r  z.TestExport_P521.test_byte_or_string_passphrase  r  r   c                    | j                  t        | j                  j                  d       | j                  j                  ddd       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  dddd	
       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  ddd       | j                  t        | j                  j                  ddd	       | j                  t        | j                  j                  dd       y r-  r  r   s    r   r  z"TestExport_P521.test_error_params1  r.  r   c                 0   d}d}t        j                  |      }t        |j                  j                  dz        }| j                  |d       t        j                  |      }t        |j                  j                  dz        }| j                  |d       y )Nal  -----BEGIN EC PRIVATE KEY-----
MIHcAgEBBEIAnm1CEjVjvNfXEN730p+D6su5l+mOztdc5XmTEoti+s2R4GQ4mAv3
0zYLvyklvOHw0+yy8d0cyGEJGb8T3ZVKmg2gBwYFK4EEACOhgYkDgYYABAHzjTI1
ckxQ3Togi0LAxiG0PucdBBBs5oIy3df95xv6SInp70z+4qQ2EltEmdNMssH8eOrl
M5CYdZ6nbcHMVaJUvQEzTrYxvFjOgJiOd+E9eBWbLkbMNqsh1UKVO6HbMbW0ohCI
uGxO8tM6r3w89/qzpG2SvFM/fvv3mIR30wSZDD84qA==
-----END EC PRIVATE KEY-----al  -----BEGIN EC PRIVATE KEY-----
MIHcAgEBBEIB84OfhJluLBRLn3+cC/RQ37C2SfQVP/t0gQK2tCsTf5avRcWYRrOJ
PmX9lNnkC0Hobd75QFRmdxrB0Wd1/M4jZOWgBwYFK4EEACOhgYkDgYYABAAMZcdJ
1YLCGHt3bHCEzdidVy6+brlJIbv1aQ9fPQLF7WKNv4c8w3H8d5a2+SDZilBOsk5c
6cNJDMz2ExWQvxl4CwDJtJGt1+LHVKFGy73NANqVxMbRu+2F8lOxkNp/ziFTbVyV
vv6oYkMIIi7r5oQWAiQDrR2mlrrFDL9V7GH/r8SWQw==
-----END EC PRIVATE KEY-----r  i8  iC  r  r  s         r   r  z%TestExport_P521.test_compressed_curve  s|    
   ~~d#DKKMME)*'~~d#DKKMME)*'r   r0  r   s   @r   rJ  rJ    sk    C
,G)	)	,	,46,G	,4&
,4*,G-0	-;>(r   rJ  c                   l     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Z xZS )TestImport_Ed25519c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   ra  r   rl   r   r   r   s      r   r   zTestImport_Ed25519.__init__  *     $0$A&A,C,E)$/r   c                 B   t        d      }t        j                  |      }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_ed25519_public.derr   r   s      r   r   z)TestImport_Ed25519.test_import_public_der  sw    56..x8#.ooh-#.nnX&#.r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Necc_ed25519_private.derr   r   s      r   test_import_pkcs8_derz(TestImport_Ed25519.test_import_pkcs8_der  sW    67ooh-))3/nnX&))3/r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_ed25519_private_p8.derr   r   r   s      r   r   z8TestImport_Ed25519.test_import_private_pkcs8_encrypted_1	  Y    9:ooh1))3/nnXx0))3/r   c                 ~    t        d      }t        j                  |d      }| j                  | j                  |       y )Nzecc_ed25519_private_p8.pemr   r   r   s      r   r   z8TestImport_Ed25519.test_import_private_pkcs8_encrypted_2	  s3    9:nnXx0))3/r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_ed25519_private_p8_2.derr   r   r   s      r   r  z8TestImport_Ed25519.test_import_private_pkcs8_encrypted_3	  sY    ;<ooh1))3/nnXx0))3/r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Nzecc_ed25519_x509.derr   r   s      r   r   z'TestImport_Ed25519.test_import_x509_der	  sS    34ooh-#.nnX&#.r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_ed25519_public.pemr   r   s      r   r   z)TestImport_Ed25519.test_import_public_pem&	  s/    56nnX&#.r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_ed25519_private.pemr   r   s      r   r   z*TestImport_Ed25519.test_import_private_pem,	  s1    67nnX&))3/r   c                    dD ]}  }t        d|z        }t        j                  |d      }| j                  | j                  |       t        j                  t        |      d      }| j                  | j                  |        y )Nr   r   r   r   zecc_ed25519_private_enc_%s.pemr   r   r   r   s       r   r   z4TestImport_Ed25519.test_import_private_pem_encrypted2	  sq    8 	4D !AD!HIH..84CT--s3..x)<CT--s3	4r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Nzecc_ed25519_x509.pemr   r   s      r   r   z'TestImport_Ed25519.test_import_x509_pem<	  /    34nnX&#.r   c                     t        d      }t        j                  |      }| j                  |j	                                t        j
                  |      }| j                  |j	                                y )Necc_ed25519_public_openssh.txt)r0   r   r)  assertFalsehas_privater   r   s      r   r*  z-TestImport_Ed25519.test_import_openssh_publicB	  sU    =>((2*+nnX&*+r   c                 D    t        d      }t        j                  |      }y )Nzecc_ed25519_private_openssh.pemr"  r   s      r   r1  z4TestImport_Ed25519.test_import_openssh_private_clearI	  s    >?nnX&r   c                 F    t        d      }t        j                  |d      }y )Nz#ecc_ed25519_private_openssh_pwd.pemr4  r"  r   s      r   r5  z7TestImport_Ed25519.test_import_openssh_private_passwordM	  s    BCnnX{3r   )r   r   r   r   r   rh  r   r   r  r   r   r   r   r   r*  r1  r5  r   r   s   @r   ra  ra    sJ    F
/0000//04/,'4r   ra  c                   f     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Z xZS )TestExport_Ed25519c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   r}  r   rl   r   r   r   s      r   r   zTestExport_Ed25519.__init__T	  rc  r   c                 .   t        d      }| j                  j                  d      }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nre  Trw  rx  Frz  r|  r  s      r   test_export_public_derz)TestExport_Ed25519.test_export_public_derX	  s    56//>>tD7+//,,E,:7+//,,EE,J7+r   c                 \    | j                  t        | j                  j                  d       y Nr  rx  r   r   r   r~  r   s    r   test_export_public_sec1z*TestExport_Ed25519.test_export_public_sec1d	  !    *doo&@&@Pr   c                 (   t        d      }| j                  j                         }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  t        | j                  j                  dd       y )Nrg  rw  rx  Fr  r0   r   r  r   r~  r   r   r  s      r   r  z2TestExport_Ed25519.test_export_private_pkcs8_clearg	  s    67""0027+ ""--U-;7+*d&6&6&A&A!&% 	 	9r   c                 4   | j                   j                  dd      }| j                  t        t        j
                  |d        t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j                  |d      }| j                  | j                   |       | j                   j                  dddddi	      }t	        j                  |d      }| j                  | j                   |       y )
Nr   r  r  rw  r  z"PBKDF2WithHMAC-SHA256AndAES128-CBCr  r  r  r  r  s      r   r  z6TestExport_Ed25519.test_export_private_pkcs8_encryptedu	  r<  r   c                     t        dd      j                         }| j                  j                  d      j                         }| j	                  ||       y )Nro  r  r  rx  r0   r  r   r~  r   r   key_file_refr   s      r   test_export_public_pemz)TestExport_Ed25519.test_export_public_pem	  sH     !94@FFH??--U-;AACx0r   c                     t        dd      j                         }| j                  j                  d      j                         }| j	                  ||       y )Nrq  r  r  rx  r0   r  r   r~  r   r  s      r   r  z0TestExport_Ed25519.test_export_private_pem_clear	  sJ    6=CCE""--U-;AAC7+r   c                     | j                   j                  ddd      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       y Nr  r   r  r  r  r   r   r~  r   r   r   r   r   r  s      r   r  z4TestExport_Ed25519.test_export_private_pem_encrypted	  r    ""--U9B:\ . ^
 	*cnng>&'111..(3))73r   c                 R   t        dd      }t        j                  |      }dj                  |j	                  d      d d       }|j                  d      }| j                  ||j                                |j                  d      }| j                  ||j                                y )Nrw  r  r2   r   Fr  rx  )	r0   r   r   r#   splitr!  r   r  r~  )r   r   ri   r  s       r   test_export_opensshz&TestExport_Ed25519.test_export_openssh	  s    =tD^^H-
88HNN3/34,,U37==?3''y'97==?3r   c                 r    | j                   j                  d      }| j                  |t        d             y )NrO  rx  s@   bc85b8cf585d20a4de47e84d1cb6183f63d9ba96223fcbc886e363ffdea20cffr   r~  r   r   r   r  s     r   test_export_rawz"TestExport_Ed25519.test_export_raw	  s/    //,,E,:),o"pqr   c                     | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y Nr  r   r  r  r  r  s      r   r  zTestExport_Ed25519.test_prng	  j    ##..e5=5W3A3C / E ##..e5=5W3A3C / E 	8,r   c                     | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y Nr  r   r  r  r   r  r  s      r   r  z1TestExport_Ed25519.test_byte_or_string_passphrase	  j    ##..e5=5W3A3C / E ##..e5>5W3A3C / E 	8,r   c                    | j                  t        | j                  j                  d       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  ddd       | j                  t        | j                  j                  ddd	
       | j                  t        | j                  j                  dd       y Nr  rx  r  r   r  r3   Fr  r  r  r  r   r   r   r~  r   s    r   r  z%TestExport_Ed25519.test_error_params1	      *d&6&6&A&A%P 	*d&6&6&A&A%19 	 	; 	*d&6&6&A&A%13u 	 	F*d&6&6&A&A%131S 	 	U
 	*d&6&6&A&A)19 	 	;r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r   r   s   @r   r}  r}  R	  sG    F
,Q9461
,
4	4r
-	-;r   r}  c                   Z     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Z xZS )TestImport_Ed448c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   r  r   rp   r   r   r   s      r   r   zTestImport_Ed448.__init__	  *    .??,A,C)$/r   c                 B   t        d      }t        j                  |      }| j                  | j                  |       t        j
                  |d       }| j                  | j                  |       t        j                  |      }| j                  | j                  |       y )Necc_ed448_public.derr   r   s      r   r   z'TestImport_Ed448.test_import_public_der	  sw    34..x8#.ooh-#.nnX&#.r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Necc_ed448_private.derr   r   s      r   rh  z&TestImport_Ed448.test_import_pkcs8_der	  sW    45ooh-))3/nnX&))3/r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_ed448_private_p8.derr   r   r   s      r   r   z6TestImport_Ed448.test_import_private_pkcs8_encrypted_1	  sY    78ooh1))3/nnXx0))3/r   c                 ~    t        d      }t        j                  |d      }| j                  | j                  |       y )Nzecc_ed448_private_p8.pemr   r   r   s      r   r   z6TestImport_Ed448.test_import_private_pkcs8_encrypted_2
  s3    78nnXx0))3/r   c                     t        d      }t        j                  |d      }| j                  | j                  |       t        j
                  |d      }| j                  | j                  |       y )Nzecc_ed448_private_p8_2.derr   r   r   s      r   r  z6TestImport_Ed448.test_import_private_pkcs8_encrypted_3
  rj  r   c                     t        d      }t        j                  |d       }| j                  | j                  |       t        j
                  |      }| j                  | j                  |       y )Nzecc_ed448_x509.derr   r   s      r   r   z%TestImport_Ed448.test_import_x509_der
  sS    12ooh-#.nnX&#.r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_ed448_public.pemr   r   s      r   r   z'TestImport_Ed448.test_import_public_pem
  ru  r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Necc_ed448_private.pemr   r   s      r   r   z(TestImport_Ed448.test_import_private_pem#
  s1    45nnX&))3/r   c                    dD ]}  }t        d|z        }t        j                  |d      }| j                  | j                  |       t        j                  t        |      d      }| j                  | j                  |        y )Nrs  zecc_ed448_private_enc_%s.pemr   r   r   r   s       r   r   z2TestImport_Ed448.test_import_private_pem_encrypted)
  sq    8 	4D !?$!FGH..84CT--s3..x)<CT--s3	4r   c                 |    t        d      }t        j                  |      }| j                  | j                  |       y )Nzecc_ed448_x509.pemr   r   s      r   r   z%TestImport_Ed448.test_import_x509_pem3
  s/    12nnX&#.r   )r   r   r   r   r   rh  r   r   r  r   r   r   r   r   r   r   s   @r   r  r  	  s;    D
/0000//04/r   r  c                   f     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Z xZS )TestExport_Ed448c                 Z    t        t        | 
  |i | t               \  | _        | _        y r   )r   r  r   rp   r   r   r   s      r   r   zTestExport_Ed448.__init__<
  r  r   c                 .   t        d      }| j                  j                  d      }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  j	                  dd      }| j                  ||       y )Nr  Trw  rx  Frz  r|  r  s      r   r  z'TestExport_Ed448.test_export_public_der@
  s    34//>>tD7+//,,E,:7+//,,EE,J7+r   c                 \    | j                  t        | j                  j                  d       y r  r  r   s    r   r  z(TestExport_Ed448.test_export_public_sec1L
  r  r   c                 (   t        d      }| j                  j                         }| j                  ||       | j                  j	                  d      }| j                  ||       | j                  t        | j                  j                  dd       y )Nr  rw  rx  Fr  r  r  s      r   r  z0TestExport_Ed448.test_export_private_pkcs8_clearO
  s    45""0027+ ""--U-;7+*d&6&6&A&A!&% 	 	9r   c                 4   | j                   j                  dd      }| j                  t        t        j
                  |d        t	        j
                  |d      }| j                  | j                   |       | j                   j                  ddd      }t	        j                  |d      }| j                  | j                   |       | j                   j                  dddddi	      }t	        j                  |d      }| j                  | j                   |       y r;  r  r  s      r   r  z4TestExport_Ed448.test_export_private_pkcs8_encrypted]
  r<  r   c                     t        dd      j                         }| j                  j                  d      j                         }| j	                  ||       y )Nr  r  r  rx  r  r  s      r   r  z'TestExport_Ed448.test_export_public_pemy
  sH     !7>DDF??--U-;AACx0r   c                     t        dd      j                         }| j                  j                  d      j                         }| j	                  ||       y )Nr  r  r  rx  r  r  s      r   r  z.TestExport_Ed448.test_export_private_pem_clear~
  sJ    4d;AAC""--U-;AAC7+r   c                     | j                   j                  ddd      }| j                  t        t        j
                  |       d|v sJ t	        j
                  |d      }| j                  | j                   |       y r  r  r  s      r   r  z2TestExport_Ed448.test_export_private_pem_encrypted
  r  r   c                 \    | j                  t        | j                  j                  d       y )Nr  rx  r  r   s    r   r  z$TestExport_Ed448.test_export_openssh
  s!    *doo&@&@Sr   c                 r    | j                   j                  d      }| j                  |t        d             y )NrO  rx  sr   899014ddc0a0e1260cfc1085afdf952019e9fd63372e3e366e26dad32b176624884330a14617237e3081febd9d1a15069e7499433d2f55dd80r  r  s     r   r  z TestExport_Ed448.test_export_raw
  s8    //,,E,:)  -b  #c  	dr   c                     | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y r  r  r  s      r   r  zTestExport_Ed448.test_prng
  r  r   c                     | j                   j                  dddt                     }| j                   j                  dddt                     }| j                  ||       y r  r  r  s      r   r  z/TestExport_Ed448.test_byte_or_string_passphrase
  r  r   c                    | j                  t        | j                  j                  d       | j                  t        | j                  j                  dd       | j                  t        | j                  j                  ddd       | j                  t        | j                  j                  ddd	
       | j                  t        | j                  j                  dd       y r  r  r   s    r   r  z#TestExport_Ed448.test_error_params1
  r  r   r  r   s   @r   r  r  :
  sH    D
,Q9481
,
4Td
-	-;r   r  c                 H   g }|t        t              z  }	 |t        t              z  }|t        t              z  }|t        t              z  }|t        t
              z  }|t        t              z  }|t        t              z  }|t        t              z  }|t        t              z  }|t        t              z  }|t        t              z  }|t        t              z  }|t        t              z  }|t        t              z  }|t        t              z  }|S # t         $ r Y |S w xY wr   )r   r}   r   r   r  r8  rW  ra  r  rt  r  r  r2  rJ  r}  r  r   )configtestss     r   	get_testsr  
  s   E	_Z((E1111111111!344!1221111111111!344!122 L & Ls   C<D 	D! D!__main__c                  <    t        j                  t                     S r   )unittest	TestSuiter  r   r   r   <lambda>r  
  s    H&&y{3 r   suite)defaultTest)rb);r   r   r&   r  binasciir   Crypto.SelfTest.st_commonr   Crypto.Util.py3compatr   r   r   Crypto.Util.asn1r   r	   Crypto.Util.numberr
   Crypto.Hashr   Crypto.PublicKeyr   Crypto.PublicKey.ECCr   r!   r   ImportErrorr   r   r0   r8   rO   rS   rX   r^   rc   rl   rp   rt   r{   TestCaser}   r   r   r  r8  rW  rt  r  r  r2  rJ  ra  r}  r  r  r  r   r  mainr   r   r   <module>r     s  > 
     5 @ @ 6 ,     4#$!
	 	4C

V
V
V
V
V##/d"" dBk/h'' k/\t/h'' t/nR'h'' R'jM'h'' M'`M'h'' M'`D(h'' D(N|(h'' |(~](h'' ](@	b(h'' b(J	j(h'' j(Z	e4** e4PL;** L;^V/x(( V/rF;x(( F;R  2 z3EHMMg& UU  #"#s   G G#"G#