B
    _e                @   sP  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 yd dlZd	ZW n ek
r   d
ZY nX G dd deZdIddZdd Zdd Zdd Zdd Zdd Zdd Z dd Z!dd Z"d d! Z#d"d# Z$G d$d% d%ej%Z&G d&d' d'ej%Z'G d(d) d)ej%Z(G d*d+ d+ej%Z)G d,d- d-ej%Z*G d.d/ d/ej%Z+G d0d1 d1ej%Z,G d2d3 d3ej%Z-G d4d5 d5ej%Z.G d6d7 d7ej%Z/G d8d9 d9ej%Z0G d:d; d;ej%Z1G d<d= d=ej%Z2G d>d? d?ej%Z3G d@dA dAej%Z4i fdBdCZ5e6dDkrLdEdF Z7ej8dGdH dS )J    N)	unhexlify)list_test_cases)bordtostrFileNotFoundError)DerSequenceDerBitString)bytes_to_long)SHAKE128)ECCTFc               @   s   e Zd ZdS )MissingTestVectorExceptionN)__name__
__module____qualname__ r   r   l/var/www/html/afkarena_new/venv/lib/python3.7/site-packages/Cryptodome/SelfTest/PublicKey/test_import_ECC.pyr   4   s   r   rbc          	   C   s   d }yjt s ttjttj| d}tjtj	}tj
tjj
|f| | }t||}| }W d Q R X W n$ tk
r   tjdtdd Y nX |d krtd|  |S )N)Z	PublicKeyr   z(Warning: skipping extended tests for ECC   )
stacklevelz
Missing %s)test_vectors_availabler   errnoENOENTosstrerrorpathdirnamepycryptodome_test_vectors__file__joinopenreadwarningswarnUserWarningr   )	file_namemoderesultsZ	dir_compsZinit_dirZfull_file_nameZfile_inr   r   r   	load_file8   s$    
r'   c             C   s&   d | }tt|ddddS )N      :)r   r   r   replace)linesextr   r   r   compactR   s    
r/   c              C   s   d} t d }tt|dd }t|dd }t|d dksHtt|d| d  }t|| d d  }tjd	|d
tjd	||dfS )N   zecc_p192.txtr         	   r      zP-192)curved)r5   point_xpoint_y)r'   
splitlinesr	   r/   r   AssertionErrorr   	construct)key_len	key_linesprivate_key_dpublic_key_xypublic_key_xpublic_key_yr   r   r   create_ref_keys_p192W   s    rB   c              C   s   d} t d }tt|dd }t|dd }t|d dksHtt|d| d  }t|| d d  }tjd	|d
tjd	||dfS )N   zecc_p224.txtr   r1   r2   r3   r   r4   zP-224)r5   r6   )r5   r7   r8   )r'   r9   r	   r/   r   r:   r   r;   )r<   r=   r>   r?   r@   rA   r   r   r   create_ref_keys_p224d   s    rD   c              C   s   d} t d }tt|dd }t|dd }t|d dksHtt|d	| d	  }t|| d	 d  }tjd
|dtjd
||dfS )N    zecc_p256.txtr   r2         r   r1   r4   zP-256)r5   r6   )r5   r7   r8   )r'   r9   r	   r/   r   r:   r   r;   )r<   r=   r>   r?   r@   rA   r   r   r   create_ref_keys_p256q   s    rH   c              C   s   d} t d }tt|dd }t|dd }t|d dksHtt|d	| d	  }t|| d	 d  }tjd
|dtjd
||dfS )N0   zecc_p384.txtr   rF         r   r1   r4   zP-384)r5   r6   )r5   r7   r8   )r'   r9   r	   r/   r   r:   r   r;   )r<   r=   r>   r?   r@   rA   r   r   r   create_ref_keys_p384~   s    rL   c              C   s   d} t d }tt|dd }t|dd }t|d dksHtt|d	| d	  }t|| d	 d  }tjd
|dtjd
||dfS )NB   zecc_p521.txtr   rJ         r   r1   r4   zP-521)r5   r6   )r5   r7   r8   )r'   r9   r	   r/   r   r:   r   r;   )r<   r=   r>   r?   r@   rA   r   r   r   create_ref_keys_p521   s    rP   c              C   s6   t d } t| dd }tjd|d}|| fS )Nzecc_ed25519.txtr2   rN   ZEd25519)r5   seed)r'   r9   r/   r   r;   
public_key)r=   rQ   keyr   r   r   create_ref_keys_ed25519   s    rT   c              C   s6   t d } t| dd }tjd|d}|| fS )Nzecc_ed448.txtrF   
   ZEd448)r5   rQ   )r'   r9   r/   r   r;   rR   )r=   rQ   rS   r   r   r   create_ref_keys_ed448   s    rV   c               C   s   t  djS )Ns   SEED)r
   newupdater    r   r   r   r   get_fixed_prng   s    rY   c             C   s*   t  }||  t }||d  |jS )Nr4   )r   decoder   value)dataseqbsr   r   r   extract_bitstring_from_spki   s
    
r_   c               @   s   e Zd Zdd Zdd ZdS )
TestImportc             C   s   |  ttjd d S )Nr(   )assertRaises
ValueErrorr   
import_key)selfr   r   r   
test_empty   s    zTestImport.test_emptyc             C   s   d}|  ttj| d S )Na1  -----BEGIN PRIVATE KEY-----
MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJChZANiAAQarFRaqflo
I+d61SRvU8Za2EurxtW20eZzca7dnNYMYf3boIkDuAUU7FfO7l0/4iGzzvfUinng
o4N+LZfQYcTxmdwlkWOrfzCjtHDix6EznPO/LlxTsV+zfTJ/ijTjeXk=
-----END PRIVATE KEY-----)ra   rb   r   rc   )rd   Zmismatchr   r   r   test_mismatch   s    zTestImport.test_mismatchN)r   r   r   re   rf   r   r   r   r   r`      s   r`   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Z  ZS )TestImport_P192c                s$   t t| j|| t \| _| _d S )N)superrg   __init__rB   ref_private
ref_public)rd   argskwargs)	__class__r   r   ri      s    zTestImport_P192.__init__c             C   sV   t d}t|}| | j| t|d }| | j| t|}| | j| d S )Nzecc_p192_public.der)r'   r   _import_subjectPublicKeyInfoassertEqualrk   _import_derrc   )rd   key_filerS   r   r   r   test_import_public_der   s    

z&TestImport_P192.test_import_public_derc             C   s0   t d}t|}tj|dd}| | j| d S )Nzecc_p192_public.derP192)
curve_name)r'   r_   r   rc   rp   rk   )rd   rr   r[   rS   r   r   r   test_import_sec1_uncompressed   s    z-TestImport_P192.test_import_sec1_uncompressedc             C   s0   t d}t|}tj|dd}| | j| d S )Nzecc_p192_public_compressed.derrt   )ru   )r'   r_   r   rc   rp   rk   )rd   rr   r[   rS   r   r   r   test_import_sec1_compressed   s    z+TestImport_P192.test_import_sec1_compressedc             C   sX   t d}t|d }| | j| t|d }| | j| t|}| | j| d S )Nzecc_p192_private.der)r'   r   _import_rfc5915_derrp   rj   rq   rc   )rd   rr   rS   r   r   r   test_import_rfc5915_der   s    
z'TestImport_P192.test_import_rfc5915_derc             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_p192_private_p8_clear.der)r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   test_import_private_pkcs8_clear   s
    
z/TestImport_P192.test_import_private_pkcs8_clearc             C   s$   t d}t|}| | j| d S )Nzecc_p192_private_p8_clear.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   &test_import_private_pkcs8_in_pem_clear   s    
z6TestImport_P192.test_import_private_pkcs8_in_pem_clearc             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_p192_private_p8.dersecret)r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   %test_import_private_pkcs8_encrypted_1   s
    z5TestImport_P192.test_import_private_pkcs8_encrypted_1c             C   s&   t d}t|d}| | j| d S )Nzecc_p192_private_p8.pemr|   )r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   %test_import_private_pkcs8_encrypted_2  s    z5TestImport_P192.test_import_private_pkcs8_encrypted_2c             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_p192_x509.der)r'   r   rq   rp   rk   rc   )rd   rr   rS   r   r   r   test_import_x509_der  s
    
z$TestImport_P192.test_import_x509_derc             C   s$   t d}t|}| | j| d S )Nzecc_p192_public.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   test_import_public_pem  s    
z&TestImport_P192.test_import_public_pemc             C   s$   t d}t|}| | j| d S )Nzecc_p192_private.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   test_import_private_pem  s    
z'TestImport_P192.test_import_private_pemc             C   sV   xPdD ]H}t d| }t|d}| | j| tt|d}| | j| qW d S )N)des3aes128aes192aes256
aes256_gcmzecc_p192_private_enc_%s.pemr|   s   secret)r'   r   rc   rp   rj   r   )rd   algorr   rS   r   r   r   !test_import_private_pem_encrypted"  s    
z1TestImport_P192.test_import_private_pem_encryptedc             C   s$   t d}t|}| | j| d S )Nzecc_p192_x509.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   test_import_x509_pem,  s    
z$TestImport_P192.test_import_x509_pem)r   r   r   ri   rs   rv   rw   ry   rz   r{   r}   r~   r   r   r   r   r   __classcell__r   r   )rn   r   rg      s   			
rg   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Z  ZS )TestImport_P224c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rD   rj   rk   )rd   rl   rm   )rn   r   r   ri   5  s    zTestImport_P224.__init__c             C   sV   t d}t|}| | j| t|d }| | j| t|}| | j| d S )Nzecc_p224_public.der)r'   r   ro   rp   rk   rq   rc   )rd   rr   rS   r   r   r   rs   9  s    

z&TestImport_P224.test_import_public_derc             C   s0   t d}t|}tj|dd}| | j| d S )Nzecc_p224_public.derP224)ru   )r'   r_   r   rc   rp   rk   )rd   rr   r[   rS   r   r   r   rv   E  s    z-TestImport_P224.test_import_sec1_uncompressedc             C   s0   t d}t|}tj|dd}| | j| d S )Nzecc_p224_public_compressed.derr   )ru   )r'   r_   r   rc   rp   rk   )rd   rr   r[   rS   r   r   r   rw   K  s    z+TestImport_P224.test_import_sec1_compressedc             C   sX   t d}t|d }| | j| t|d }| | j| t|}| | j| d S )Nzecc_p224_private.der)r'   r   rx   rp   rj   rq   rc   )rd   rr   rS   r   r   r   ry   Q  s    
z'TestImport_P224.test_import_rfc5915_derc             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_p224_private_p8_clear.der)r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   rz   ]  s
    
z/TestImport_P224.test_import_private_pkcs8_clearc             C   s$   t d}t|}| | j| d S )Nzecc_p224_private_p8_clear.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r{   f  s    
z6TestImport_P224.test_import_private_pkcs8_in_pem_clearc             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_p224_private_p8.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r}   l  s
    z5TestImport_P224.test_import_private_pkcs8_encrypted_1c             C   s&   t d}t|d}| | j| d S )Nzecc_p224_private_p8.pemr|   )r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r~   u  s    z5TestImport_P224.test_import_private_pkcs8_encrypted_2c             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_p224_private_p8_2.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   %test_import_private_pkcs8_encrypted_3{  s
    z5TestImport_P224.test_import_private_pkcs8_encrypted_3c             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_p224_x509.der)r'   r   rq   rp   rk   rc   )rd   rr   rS   r   r   r   r     s
    
z$TestImport_P224.test_import_x509_derc             C   s$   t d}t|}| | j| d S )Nzecc_p224_public.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r     s    
z&TestImport_P224.test_import_public_pemc             C   s$   t d}t|}| | j| d S )Nzecc_p224_private.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r     s    
z'TestImport_P224.test_import_private_pemc             C   sV   xPdD ]H}t d| }t|d}| | j| tt|d}| | j| qW d S )N)r   r   r   r   r   zecc_p224_private_enc_%s.pemr|   s   secret)r'   r   rc   rp   rj   r   )rd   r   rr   rS   r   r   r   r     s    
z1TestImport_P224.test_import_private_pem_encryptedc             C   s$   t d}t|}| | j| d S )Nzecc_p224_x509.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r     s    
z$TestImport_P224.test_import_x509_pem)r   r   r   ri   rs   rv   rw   ry   rz   r{   r}   r~   r   r   r   r   r   r   r   r   r   )rn   r   r   3  s   				
r   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Z  ZS )'TestImport_P256c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rH   rj   rk   )rd   rl   rm   )rn   r   r   ri     s    zTestImport_P256.__init__c             C   sV   t d}t|}| | j| t|d }| | j| t|}| | j| d S )Nzecc_p256_public.der)r'   r   ro   rp   rk   rq   rc   )rd   rr   rS   r   r   r   rs     s    

z&TestImport_P256.test_import_public_derc             C   s0   t d}t|}tj|dd}| | j| d S )Nzecc_p256_public.derP256)ru   )r'   r_   r   rc   rp   rk   )rd   rr   r[   rS   r   r   r   rv     s    z-TestImport_P256.test_import_sec1_uncompressedc             C   s0   t d}t|}tj|dd}| | j| d S )Nzecc_p256_public_compressed.derr   )ru   )r'   r_   r   rc   rp   rk   )rd   rr   r[   rS   r   r   r   rw     s    z+TestImport_P256.test_import_sec1_compressedc             C   sX   t d}t|d }| | j| t|d }| | j| t|}| | j| d S )Nzecc_p256_private.der)r'   r   rx   rp   rj   rq   rc   )rd   rr   rS   r   r   r   ry     s    
z'TestImport_P256.test_import_rfc5915_derc             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_p256_private_p8_clear.der)r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   rz     s
    
z/TestImport_P256.test_import_private_pkcs8_clearc             C   s$   t d}t|}| | j| d S )Nzecc_p256_private_p8_clear.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r{     s    
z6TestImport_P256.test_import_private_pkcs8_in_pem_clearc             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_p256_private_p8.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r}     s
    z5TestImport_P256.test_import_private_pkcs8_encrypted_1c             C   s&   t d}t|d}| | j| d S )Nzecc_p256_private_p8.pemr|   )r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r~     s    z5TestImport_P256.test_import_private_pkcs8_encrypted_2c             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_p256_private_p8_2.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r     s
    z5TestImport_P256.test_import_private_pkcs8_encrypted_3c             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_p256_x509.der)r'   r   rq   rp   rk   rc   )rd   rr   rS   r   r   r   r     s
    
z$TestImport_P256.test_import_x509_derc             C   s$   t d}t|}| | j| d S )Nzecc_p256_public.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r     s    
z&TestImport_P256.test_import_public_pemc             C   s$   t d}t|}| | j| d S )Nzecc_p256_private.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r   
  s    
z'TestImport_P256.test_import_private_pemc             C   s   t d}t|}d S )Nzecc_p256_private_ecparams.pem)r'   r   rc   )rd   rr   rS   r   r   r   %test_import_private_pem_with_ecparams  s    z5TestImport_P256.test_import_private_pem_with_ecparamsc             C   sV   xPdD ]H}t d| }t|d}| | j| tt|d}| | j| qW d S )N)r   r   r   r   r   zecc_p256_private_enc_%s.pemr|   s   secret)r'   r   rc   rp   rj   r   )rd   r   rr   rS   r   r   r   r     s    
z1TestImport_P256.test_import_private_pem_encryptedc             C   s$   t d}t|}| | j| d S )Nzecc_p256_x509.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r     s    
z$TestImport_P256.test_import_x509_pemc             C   s<   t d}t|}| | j| t|}| | j| d S )Nzecc_p256_public_openssh.txt)r'   r   _import_openssh_publicrp   rk   rc   )rd   rr   rS   r   r   r   test_import_openssh_public%  s
    

z*TestImport_P256.test_import_openssh_publicc             C   s4   t d}t d}t|}t|}| || d S )Nzecc_p256_private_openssh.pemz ecc_p256_private_openssh_old.pem)r'   r   rc   rp   )rd   rr   key_file_oldrS   key_oldr   r   r   !test_import_openssh_private_clear.  s
    

z1TestImport_P256.test_import_openssh_private_clearc             C   s6   t d}t d}t|d}t|}| || d S )Nz ecc_p256_private_openssh_pwd.pemz$ecc_p256_private_openssh_pwd_old.pems   password)r'   r   rc   rp   )rd   rr   r   rS   r   r   r   r   $test_import_openssh_private_password6  s
    
z4TestImport_P256.test_import_openssh_private_password)r   r   r   ri   rs   rv   rw   ry   rz   r{   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r     s&   				
	r   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Z  ZS )%TestImport_P384c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rL   rj   rk   )rd   rl   rm   )rn   r   r   ri   A  s    zTestImport_P384.__init__c             C   sV   t d}t|}| | j| t|d }| | j| t|}| | j| d S )Nzecc_p384_public.der)r'   r   ro   rp   rk   rq   rc   )rd   rr   rS   r   r   r   rs   E  s    

z&TestImport_P384.test_import_public_derc             C   s0   t d}t|}tj|dd}| | j| d S )Nzecc_p384_public.derP384)ru   )r'   r_   r   rc   rp   rk   )rd   rr   r[   rS   r   r   r   rv   Q  s    z-TestImport_P384.test_import_sec1_uncompressedc             C   s0   t d}t|}tj|dd}| | j| d S )Nzecc_p384_public_compressed.derr   )ru   )r'   r_   r   rc   rp   rk   )rd   rr   r[   rS   r   r   r   rw   W  s    z+TestImport_P384.test_import_sec1_compressedc             C   sX   t d}t|d }| | j| t|d }| | j| t|}| | j| d S )Nzecc_p384_private.der)r'   r   rx   rp   rj   rq   rc   )rd   rr   rS   r   r   r   ry   ]  s    
z'TestImport_P384.test_import_rfc5915_derc             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_p384_private_p8_clear.der)r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   rz   i  s
    
z/TestImport_P384.test_import_private_pkcs8_clearc             C   s$   t d}t|}| | j| d S )Nzecc_p384_private_p8_clear.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r{   r  s    
z6TestImport_P384.test_import_private_pkcs8_in_pem_clearc             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_p384_private_p8.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r}   x  s
    z5TestImport_P384.test_import_private_pkcs8_encrypted_1c             C   s&   t d}t|d}| | j| d S )Nzecc_p384_private_p8.pemr|   )r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r~     s    z5TestImport_P384.test_import_private_pkcs8_encrypted_2c             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_p384_private_p8_2.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r     s
    z5TestImport_P384.test_import_private_pkcs8_encrypted_3c             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_p384_x509.der)r'   r   rq   rp   rk   rc   )rd   rr   rS   r   r   r   r     s
    
z$TestImport_P384.test_import_x509_derc             C   s$   t d}t|}| | j| d S )Nzecc_p384_public.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r     s    
z&TestImport_P384.test_import_public_pemc             C   s$   t d}t|}| | j| d S )Nzecc_p384_private.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r     s    
z'TestImport_P384.test_import_private_pemc             C   sV   xPdD ]H}t d| }t|d}| | j| tt|d}| | j| qW d S )N)r   r   r   r   r   zecc_p384_private_enc_%s.pemr|   s   secret)r'   r   rc   rp   rj   r   )rd   r   rr   rS   r   r   r   r     s    
z1TestImport_P384.test_import_private_pem_encryptedc             C   s$   t d}t|}| | j| d S )Nzecc_p384_x509.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r     s    
z$TestImport_P384.test_import_x509_pemc             C   s<   t d}t|}| | j| t|}| | j| d S )Nzecc_p384_public_openssh.txt)r'   r   r   rp   rk   rc   )rd   rr   rS   r   r   r   r     s
    

z*TestImport_P384.test_import_openssh_publicc             C   s4   t d}t d}t|}t|}| || d S )Nzecc_p384_private_openssh.pemz ecc_p384_private_openssh_old.pem)r'   r   rc   rp   )rd   rr   r   rS   r   r   r   r   r     s
    

z1TestImport_P384.test_import_openssh_private_clearc             C   s6   t d}t d}t|d}t|}| || d S )Nz ecc_p384_private_openssh_pwd.pemz$ecc_p384_private_openssh_pwd_old.pems   password)r'   r   rc   rp   )rd   rr   r   rS   r   r   r   r   r     s
    
z4TestImport_P384.test_import_openssh_private_password)r   r   r   ri   rs   rv   rw   ry   rz   r{   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r   ?  s$   				
	r   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Z  ZS )%TestImport_P521c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rP   rj   rk   )rd   rl   rm   )rn   r   r   ri     s    zTestImport_P521.__init__c             C   sV   t d}t|}| | j| t|d }| | j| t|}| | j| d S )Nzecc_p521_public.der)r'   r   ro   rp   rk   rq   rc   )rd   rr   rS   r   r   r   rs     s    

z&TestImport_P521.test_import_public_derc             C   s0   t d}t|}tj|dd}| | j| d S )Nzecc_p521_public.derP521)ru   )r'   r_   r   rc   rp   rk   )rd   rr   r[   rS   r   r   r   rv     s    z-TestImport_P521.test_import_sec1_uncompressedc             C   s0   t d}t|}tj|dd}| | j| d S )Nzecc_p521_public_compressed.derr   )ru   )r'   r_   r   rc   rp   rk   )rd   rr   r[   rS   r   r   r   rw     s    z+TestImport_P521.test_import_sec1_compressedc             C   sX   t d}t|d }| | j| t|d }| | j| t|}| | j| d S )Nzecc_p521_private.der)r'   r   rx   rp   rj   rq   rc   )rd   rr   rS   r   r   r   ry     s    
z'TestImport_P521.test_import_rfc5915_derc             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_p521_private_p8_clear.der)r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   rz     s
    
z/TestImport_P521.test_import_private_pkcs8_clearc             C   s$   t d}t|}| | j| d S )Nzecc_p521_private_p8_clear.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r{     s    
z6TestImport_P521.test_import_private_pkcs8_in_pem_clearc             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_p521_private_p8.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r}     s
    z5TestImport_P521.test_import_private_pkcs8_encrypted_1c             C   s&   t d}t|d}| | j| d S )Nzecc_p521_private_p8.pemr|   )r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r~     s    z5TestImport_P521.test_import_private_pkcs8_encrypted_2c             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_p521_private_p8_2.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r     s
    z5TestImport_P521.test_import_private_pkcs8_encrypted_3c             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_p521_x509.der)r'   r   rq   rp   rk   rc   )rd   rr   rS   r   r   r   r      s
    
z$TestImport_P521.test_import_x509_derc             C   s$   t d}t|}| | j| d S )Nzecc_p521_public.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r   )  s    
z&TestImport_P521.test_import_public_pemc             C   s$   t d}t|}| | j| d S )Nzecc_p521_private.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r   /  s    
z'TestImport_P521.test_import_private_pemc             C   sV   xPdD ]H}t d| }t|d}| | j| tt|d}| | j| qW d S )N)r   r   r   r   r   zecc_p521_private_enc_%s.pemr|   s   secret)r'   r   rc   rp   rj   r   )rd   r   rr   rS   r   r   r   r   5  s    
z1TestImport_P521.test_import_private_pem_encryptedc             C   s$   t d}t|}| | j| d S )Nzecc_p521_x509.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r   ?  s    
z$TestImport_P521.test_import_x509_pemc             C   s<   t d}t|}| | j| t|}| | j| d S )Nzecc_p521_public_openssh.txt)r'   r   r   rp   rk   rc   )rd   rr   rS   r   r   r   r   E  s
    

z*TestImport_P521.test_import_openssh_publicc             C   s4   t d}t d}t|}t|}| || d S )Nzecc_p521_private_openssh.pemz ecc_p521_private_openssh_old.pem)r'   r   rc   rp   )rd   rr   r   rS   r   r   r   r   r   N  s
    

z1TestImport_P521.test_import_openssh_private_clearc             C   s6   t d}t d}t|d}t|}| || d S )Nz ecc_p521_private_openssh_pwd.pemz$ecc_p521_private_openssh_pwd_old.pems   password)r'   r   rc   rp   )rd   rr   r   rS   r   r   r   r   r   V  s
    
z4TestImport_P521.test_import_openssh_private_password)r   r   r   ri   rs   rv   rw   ry   rz   r{   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r     s$   				
	r   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Z  ZS )%TestExport_P192c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rB   rj   rk   )rd   rl   rm   )rn   r   r   ri   a  s    zTestExport_P192.__init__c             C   sZ   t d}| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p192_public.derFDER)format)r   compress)r'   rk   _export_subjectPublicKeyInforp   
export_key)rd   rr   encodedr   r   r   #test_export_public_der_uncompressede  s    z3TestExport_P192.test_export_public_der_uncompressedc             C   s8   t d}t|}|jddd}t d}| || d S )Nzecc_p192_public.derr   T)r   r   zecc_p192_public_compressed.der)r'   r   rc   r   rp   )rd   rr   pub_keykey_file_compressedkey_file_compressed_refr   r   r   !test_export_public_der_compressedq  s
    
z1TestExport_P192.test_export_public_der_compressedc             C   s.   t d}t|}| jjdd}| || d S )Nzecc_p192_public.derSEC1)r   )r'   r_   rk   r   rp   )rd   rr   r[   r   r   r   r   $test_export_public_sec1_uncompressedy  s    z4TestExport_P192.test_export_public_sec1_uncompressedc             C   s8   t d}| jjddd}t d}t|}| || d S )Nzecc_p192_public.derr   T)r   r   zecc_p192_public_compressed.der)r'   rk   r   r_   rp   )rd   rr   r   r   r[   r   r   r   "test_export_public_sec1_compressed  s
    z2TestExport_P192.test_export_public_sec1_compressedc             C   s>   t d}| j }| || | jjddd}| || d S )Nzecc_p192_private.derr   F)r   	use_pkcs8)r'   rj   _export_rfc5915_private_derrp   r   )rd   rr   r   r   r   r   test_export_rfc5915_private_der  s
    
z/TestExport_P192.test_export_rfc5915_private_derc             C   s<   t d}| j }| || | jjdd}| || d S )Nzecc_p192_private_p8_clear.derr   )r   )r'   rj   _export_pkcs8rp   r   )rd   rr   r   r   r   r   test_export_private_pkcs8_clear  s
    
z/TestExport_P192.test_export_private_pkcs8_clearc             C   s   | j jddd}| ttj|d  t|d}| | j | | j jdddd}t|d}| | j | | j jdddddid	}t|d}| | j | d S )
Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)
passphrase
protectionr   )r   r   r   z"PBKDF2WithHMAC-SHA224AndAES192-CBCiteration_count{   )r   r   r   prot_params)	rj   r   ra   rb   r   _import_pkcs8rp   r   rc   )rd   r   decodedr   r   r   #test_export_private_pkcs8_encrypted  s     z3TestExport_P192.test_export_private_pkcs8_encryptedc             C   s`   t dd }| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p192_public.pemrtFPEM)r   )r   r   )r'   striprj   _export_public_pemrp   rk   r   )rd   rr   r   r   r   r   #test_export_public_pem_uncompressed  s    z3TestExport_P192.test_export_public_pem_uncompressedc             C   sD   t dd }t|}|jddd}t dd }| || d S )Nzecc_p192_public.pemr   r   T)r   r   zecc_p192_public_compressed.pem)r'   r   r   rc   r   rp   )rd   rr   r   r   r   r   r   r   !test_export_public_pem_compressed  s
    
z1TestExport_P192.test_export_public_pem_compressedc             C   sF   t dd }| jd }| || | jjddd}| || d S )Nzecc_p192_private.pemr   r   F)r   r   )r'   r   rj   _export_private_pemrp   r   )rd   rr   r   r   r   r   test_export_private_pem_clear  s
    z-TestExport_P192.test_export_private_pem_clearc             C   st   | j jdd}| ttj| d|ks*tt|d}| | j | | j jdddd}t|d}| | j | d S )Ns   secret)r   zEC PRIVATE KEYr|   r   F)r   r   r   )	rj   r   ra   rb   r   rc   r:   rp   r   )rd   r   r   r   r   r   !test_export_private_pem_encrypted  s    z1TestExport_P192.test_export_private_pem_encryptedc             C   sB   t dd }| j }| || | jjdd}| || d S )Nzecc_p192_private_p8_clear.pemr   r   )r   )r'   r   rj   (_export_private_clear_pkcs8_in_clear_pemrp   r   )rd   rr   r   r   r   r   #test_export_private_pkcs8_and_pem_1  s
    
z3TestExport_P192.test_export_private_pkcs8_and_pem_1c             C   sv   | j jddd}| ttj| d|ks,tt|d}| | j | | j jdddd}t|d}| | j | d S )Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   zENCRYPTED PRIVATE KEYr   )r   r   r   )	rj   ,_export_private_encrypted_pkcs8_in_clear_pemra   rb   r   rc   r:   rp   r   )rd   r   r   r   r   r   #test_export_private_pkcs8_and_pem_2  s    z3TestExport_P192.test_export_private_pkcs8_and_pem_2c             C   st   | j jdddt d}| j jdddt d}| || | j jdddt d}| j jdddt d}| || d S )Nr   r|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   randfuncF)r   r   r   r   )rj   r   rY   rp   )rd   encoded1encoded2r   r   r   	test_prng  s$    



zTestExport_P192.test_prngc             C   s<   | j jdddt d}| j jdddt d}| || d S )Nr   Fr|   )r   r   r   r   s   secret)rj   r   rY   rp   )rd   r   r   r   r   r   test_byte_or_string_passphrase'  s    

z.TestExport_P192.test_byte_or_string_passphrasec             C   s   | j t| jjdd | jjdddd | j t| jjddd | j t| jjdddd	d
 | j t| jjddd | j t| jjdddd | j t| jjddd	d d S )NXXX)r   r   r|   F)r   r   r   )r   r   r   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   )r   r   r*   )r   r   r   )ra   rb   rj   r   rk   )rd   r   r   r   test_error_params12  s     

z"TestExport_P192.test_error_params1c             C   sX   d}d}t |}t|jjd }| |d t |}t|jjd }| |d d S )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  i  )r   rc   intpointQyrp   )rd   pem1pem2key1low16key2r   r   r   test_compressed_curveM  s    

z%TestExport_P192.test_compressed_curve)r   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r   _  s$   	r   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Z  ZS )%TestExport_P224c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rD   rj   rk   )rd   rl   rm   )rn   r   r   ri   h  s    zTestExport_P224.__init__c             C   sZ   t d}| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p224_public.derFr   )r   )r   r   )r'   rk   r   rp   r   )rd   rr   r   r   r   r   r   l  s    z3TestExport_P224.test_export_public_der_uncompressedc             C   s8   t d}t|}|jddd}t d}| || d S )Nzecc_p224_public.derr   T)r   r   zecc_p224_public_compressed.der)r'   r   rc   r   rp   )rd   rr   r   r   r   r   r   r   r   x  s
    
z1TestExport_P224.test_export_public_der_compressedc             C   s.   t d}t|}| jjdd}| || d S )Nzecc_p224_public.derr   )r   )r'   r_   rk   r   rp   )rd   rr   r[   r   r   r   r   r     s    z4TestExport_P224.test_export_public_sec1_uncompressedc             C   s8   t d}| jjddd}t d}t|}| || d S )Nzecc_p224_public.derr   T)r   r   zecc_p224_public_compressed.der)r'   rk   r   r_   rp   )rd   rr   r   r   r[   r   r   r   r     s
    z2TestExport_P224.test_export_public_sec1_compressedc             C   s>   t d}| j }| || | jjddd}| || d S )Nzecc_p224_private.derr   F)r   r   )r'   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z/TestExport_P224.test_export_rfc5915_private_derc             C   s<   t d}| j }| || | jjdd}| || d S )Nzecc_p224_private_p8_clear.derr   )r   )r'   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z/TestExport_P224.test_export_private_pkcs8_clearc             C   sr   | j jddd}| ttj|d  t|d}| | j | | j jdddddid}t|d}| | j | d S )	Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   z&PBKDF2WithHMAC-SHA512-224AndAES128-CBCr   r   )r   r   r   r   )	rj   r   ra   rb   r   r   rp   r   rc   )rd   r   r   r   r   r   r     s    z3TestExport_P224.test_export_private_pkcs8_encryptedc             C   s`   t dd }| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p224_public.pemr   Fr   )r   )r   r   )r'   r   rj   r   rp   rk   r   )rd   rr   r   r   r   r   r     s    z3TestExport_P224.test_export_public_pem_uncompressedc             C   sD   t dd }t|}|jddd}t dd }| || d S )Nzecc_p224_public.pemr   r   T)r   r   zecc_p224_public_compressed.pem)r'   r   r   rc   r   rp   )rd   rr   r   r   r   r   r   r   r     s
    
z1TestExport_P224.test_export_public_pem_compressedc             C   sF   t dd }| jd }| || | jjddd}| || d S )Nzecc_p224_private.pemr   r   F)r   r   )r'   r   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    z-TestExport_P224.test_export_private_pem_clearc             C   st   | j jdd}| ttj| d|ks*tt|d}| | j | | j jdddd}t|d}| | j | d S )Ns   secret)r   zEC PRIVATE KEYr|   r   F)r   r   r   )	rj   r   ra   rb   r   rc   r:   rp   r   )rd   r   r   r   r   r   r     s    z1TestExport_P224.test_export_private_pem_encryptedc             C   sB   t dd }| j }| || | jjdd}| || d S )Nzecc_p224_private_p8_clear.pemr   r   )r   )r'   r   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z3TestExport_P224.test_export_private_pkcs8_and_pem_1c             C   sv   | j jddd}| ttj| d|ks,tt|d}| | j | | j jdddd}t|d}| | j | d S )Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   zENCRYPTED PRIVATE KEYr   )r   r   r   )	rj   r   ra   rb   r   rc   r:   rp   r   )rd   r   r   r   r   r   r     s    z3TestExport_P224.test_export_private_pkcs8_and_pem_2c             C   st   | j jdddt d}| j jdddt d}| || | j jdddt d}| j jdddt d}| || d S )Nr   r|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   F)r   r   r   r   )rj   r   rY   rp   )rd   r   r   r   r   r   r     s$    



zTestExport_P224.test_prngc             C   s<   | j jdddt d}| j jdddt d}| || d S )Nr   Fr|   )r   r   r   r   s   secret)rj   r   rY   rp   )rd   r   r   r   r   r   r   &  s    

z.TestExport_P224.test_byte_or_string_passphrasec             C   s   | j t| jjdd | jjdddd | j t| jjddd | j t| jjdddd	d
 | j t| jjddd | j t| jjdddd | j t| jjddd	d d S )Nr   )r   r   r|   F)r   r   r   )r   r   r   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   )r   r   r*   )r   r   r   )ra   rb   rj   r   rk   )rd   r   r   r   r   1  s     

z"TestExport_P224.test_error_params1c             C   sX   d}d}t |}t|jjd }| |d t |}t|jjd }| |d d S )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-----i   ijF  i/  )r   rc   r   r   r   rp   )rd   r   r   r   r   r   r   r   r   r   L  s    

z%TestExport_P224.test_compressed_curve)r   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r   f  s$   	r   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Z  ZS ))TestExport_P256c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rH   rj   rk   )rd   rl   rm   )rn   r   r   ri   g  s    zTestExport_P256.__init__c             C   sZ   t d}| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p256_public.derFr   )r   )r   r   )r'   rk   r   rp   r   )rd   rr   r   r   r   r   r   k  s    z3TestExport_P256.test_export_public_der_uncompressedc             C   s8   t d}t|}|jddd}t d}| || d S )Nzecc_p256_public.derr   T)r   r   zecc_p256_public_compressed.der)r'   r   rc   r   rp   )rd   rr   r   r   r   r   r   r   r   w  s
    
z1TestExport_P256.test_export_public_der_compressedc             C   s.   t d}t|}| jjdd}| || d S )Nzecc_p256_public.derr   )r   )r'   r_   rk   r   rp   )rd   rr   r[   r   r   r   r   r     s    z4TestExport_P256.test_export_public_sec1_uncompressedc             C   s8   t d}| jjddd}t d}t|}| || d S )Nzecc_p256_public.derr   T)r   r   zecc_p256_public_compressed.der)r'   rk   r   r_   rp   )rd   rr   r   r   r[   r   r   r   r     s
    z2TestExport_P256.test_export_public_sec1_compressedc             C   s>   t d}| j }| || | jjddd}| || d S )Nzecc_p256_private.derr   F)r   r   )r'   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z/TestExport_P256.test_export_rfc5915_private_derc             C   s<   t d}| j }| || | jjdd}| || d S )Nzecc_p256_private_p8_clear.derr   )r   )r'   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z/TestExport_P256.test_export_private_pkcs8_clearc             C   s   | j jddd}| ttj|d  t|d}| | j | | j jdddd}t|d}| | j | | j jdddddid	}t|d}| | j | d S )
Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   )r   r   r   z&PBKDF2WithHMAC-SHA512-256AndAES128-CBCr   r   )r   r   r   r   )	rj   r   ra   rb   r   r   rp   r   rc   )rd   r   r   r   r   r   r     s     z3TestExport_P256.test_export_private_pkcs8_encryptedc             C   s`   t dd }| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p256_public.pemr   Fr   )r   )r   r   )r'   r   rj   r   rp   rk   r   )rd   rr   r   r   r   r   r     s    z3TestExport_P256.test_export_public_pem_uncompressedc             C   sD   t dd }t|}|jddd}t dd }| || d S )Nzecc_p256_public.pemr   r   T)r   r   zecc_p256_public_compressed.pem)r'   r   r   rc   r   rp   )rd   rr   r   r   r   r   r   r   r     s
    
z1TestExport_P256.test_export_public_pem_compressedc             C   sF   t dd }| jd }| || | jjddd}| || d S )Nzecc_p256_private.pemr   r   F)r   r   )r'   r   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    z-TestExport_P256.test_export_private_pem_clearc             C   st   | j jdd}| ttj| d|ks*tt|d}| | j | | j jdddd}t|d}| | j | d S )Ns   secret)r   zEC PRIVATE KEYr|   r   F)r   r   r   )	rj   r   ra   rb   r   rc   r:   rp   r   )rd   r   r   r   r   r   r     s    z1TestExport_P256.test_export_private_pem_encryptedc             C   sB   t dd }| j }| || | jjdd}| || d S )Nzecc_p256_private_p8_clear.pemr   r   )r   )r'   r   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z3TestExport_P256.test_export_private_pkcs8_and_pem_1c             C   sv   | j jddd}| ttj| d|ks,tt|d}| | j | | j jdddd}t|d}| | j | d S )Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   zENCRYPTED PRIVATE KEYr   )r   r   r   )	rj   r   ra   rb   r   rc   r:   rp   r   )rd   r   r   r   r   r   r      s    z3TestExport_P256.test_export_private_pkcs8_and_pem_2c             C   s\   t dd}| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p256_public_openssh.txtr   FOpenSSH)r   )r   r   )r'   rk   _export_opensshrp   r   )rd   rr   r   r   r   r    test_export_openssh_uncompressed  s    
z0TestExport_P256.test_export_openssh_uncompressedc             C   sL   t dd}t|}|jddd}t|t|ks6t| |t| d S )Nzecc_p256_public_openssh.txtr   r   T)r   r   )r'   r   rc   r   lenr:   rp   )rd   rr   r   r   r   r   r   test_export_openssh_compressed#  s
    

z.TestExport_P256.test_export_openssh_compressedc             C   st   | j jdddt d}| j jdddt d}| || | j jdddt d}| j jdddt d}| || d S )Nr   r|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   F)r   r   r   r   )rj   r   rY   rp   )rd   r   r   r   r   r   r   +  s$    



zTestExport_P256.test_prngc             C   s<   | j jdddt d}| j jdddt d}| || d S )Nr   Fr|   )r   r   r   r   s   secret)rj   r   rY   rp   )rd   r   r   r   r   r   r   C  s    

z.TestExport_P256.test_byte_or_string_passphrasec             C   s   | j t| jjdd | jjdddd | j t| jjddd | j t| jjdddd	d
 | j t| jjddd | j t| jjdddd | j t| jjddd	d | j t| jjddd d S )Nr   )r   r   r|   F)r   r   r   )r   r   r   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   )r   r   r*   )r   r   r   r   )ra   rb   rj   r   rk   )rd   r   r   r   r   N  s$    

z"TestExport_P256.test_error_params1c             C   sX   d}d}t |}t|jjd }| |d t |}t|jjd }| |d d S )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-----i   i  iWn  )r   rc   r   r   r   rp   )rd   r   r   r   r   r   r   r   r   r   n  s    

z%TestExport_P256.test_compressed_curve)r   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r   e  s(   	 r   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Z  ZS ))TestExport_P384c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rL   rj   rk   )rd   rl   rm   )rn   r   r   ri     s    zTestExport_P384.__init__c             C   sZ   t d}| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p384_public.derFr   )r   )r   r   )r'   rk   r   rp   r   )rd   rr   r   r   r   r   r     s    z3TestExport_P384.test_export_public_der_uncompressedc             C   s8   t d}t|}|jddd}t d}| || d S )Nzecc_p384_public.derr   T)r   r   zecc_p384_public_compressed.der)r'   r   rc   r   rp   )rd   rr   r   r   r   r   r   r   r     s
    
z1TestExport_P384.test_export_public_der_compressedc             C   s.   t d}t|}| jjdd}| || d S )Nzecc_p384_public.derr   )r   )r'   r_   rk   r   rp   )rd   rr   r[   r   r   r   r   r     s    z4TestExport_P384.test_export_public_sec1_uncompressedc             C   s8   t d}| jjddd}t d}t|}| || d S )Nzecc_p384_public.derr   T)r   r   zecc_p384_public_compressed.der)r'   rk   r   r_   rp   )rd   rr   r   r   r[   r   r   r   r     s
    z2TestExport_P384.test_export_public_sec1_compressedc             C   s>   t d}| j }| || | jjddd}| || d S )Nzecc_p384_private.derr   F)r   r   )r'   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z/TestExport_P384.test_export_rfc5915_private_derc             C   s<   t d}| j }| || | jjdd}| || d S )Nzecc_p384_private_p8_clear.derr   )r   )r'   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z/TestExport_P384.test_export_private_pkcs8_clearc             C   s   | j jddd}| ttj|d  t|d}| | j | | j jdddd}t|d}| | j | | j jdddddid	}t|d}| | j | d S )
Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   )r   r   r   z"PBKDF2WithHMAC-SHA384AndAES128-CBCr   r   )r   r   r   r   )	rj   r   ra   rb   r   r   rp   r   rc   )rd   r   r   r   r   r   r     s     z3TestExport_P384.test_export_private_pkcs8_encryptedc             C   s`   t dd }| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p384_public.pemr   Fr   )r   )r   r   )r'   r   rj   r   rp   rk   r   )rd   rr   r   r   r   r   r     s    z3TestExport_P384.test_export_public_pem_uncompressedc             C   sD   t dd }t|}|jddd}t dd }| || d S )Nzecc_p384_public.pemr   r   T)r   r   zecc_p384_public_compressed.pem)r'   r   r   rc   r   rp   )rd   rr   r   r   r   r   r   r   r     s
    
z1TestExport_P384.test_export_public_pem_compressedc             C   sF   t dd }| jd }| || | jjddd}| || d S )Nzecc_p384_private.pemr   r   F)r   r   )r'   r   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    z-TestExport_P384.test_export_private_pem_clearc             C   st   | j jdd}| ttj| d|ks*tt|d}| | j | | j jdddd}t|d}| | j | d S )Ns   secret)r   zEC PRIVATE KEYr|   r   F)r   r   r   )	rj   r   ra   rb   r   rc   r:   rp   r   )rd   r   r   r   r   r   r     s    z1TestExport_P384.test_export_private_pem_encryptedc             C   sB   t dd }| j }| || | jjdd}| || d S )Nzecc_p384_private_p8_clear.pemr   r   )r   )r'   r   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z3TestExport_P384.test_export_private_pkcs8_and_pem_1c             C   sv   | j jddd}| ttj| d|ks,tt|d}| | j | | j jdddd}t|d}| | j | d S )Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   zENCRYPTED PRIVATE KEYr   )r   r   r   )	rj   r   ra   rb   r   rc   r:   rp   r   )rd   r   r   r   r   r   r      s    z3TestExport_P384.test_export_private_pkcs8_and_pem_2c             C   s\   t dd}| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p384_public_openssh.txtr   Fr   )r   )r   r   )r'   rk   r   rp   r   )rd   rr   r   r   r   r   r   5  s    
z0TestExport_P384.test_export_openssh_uncompressedc             C   sL   t dd}t|}|jddd}t|t|ks6t| |t| d S )Nzecc_p384_public_openssh.txtr   r   T)r   r   )r'   r   rc   r   r   r:   rp   )rd   rr   r   r   r   r   r   r   C  s
    

z.TestExport_P384.test_export_openssh_compressedc             C   st   | j jdddt d}| j jdddt d}| || | j jdddt d}| j jdddt d}| || d S )Nr   r|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   F)r   r   r   r   )rj   r   rY   rp   )rd   r   r   r   r   r   r   K  s$    



zTestExport_P384.test_prngc             C   s<   | j jdddt d}| j jdddt d}| || d S )Nr   Fr|   )r   r   r   r   s   secret)rj   r   rY   rp   )rd   r   r   r   r   r   r   c  s    

z.TestExport_P384.test_byte_or_string_passphrasec             C   s   | j t| jjdd | jjdddd | j t| jjddd | j t| jjdddd	d
 | j t| jjddd | j t| jjdddd | j t| jjddd	d | j t| jjddd d S )Nr   )r   r   r|   F)r   r   r   )r   r   r   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   )r   r   r*   )r   r   r   r   )ra   rb   rj   r   rk   )rd   r   r   r   r   n  s$    

z"TestExport_P384.test_error_params1c             C   sX   d}d}t |}t|jjd }| |d t |}t|jjd }| |d d S )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-----i   i  i  )r   rc   r   r   r   rp   )rd   r   r   r   r   r   r   r   r   r     s    


z%TestExport_P384.test_compressed_curve)r   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r     s(   	r   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Z  ZS ))TestExport_P521c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rP   rj   rk   )rd   rl   rm   )rn   r   r   ri     s    zTestExport_P521.__init__c             C   sZ   t d}| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p521_public.derFr   )r   )r   r   )r'   rk   r   rp   r   )rd   rr   r   r   r   r   r     s    z3TestExport_P521.test_export_public_der_uncompressedc             C   s8   t d}t|}|jddd}t d}| || d S )Nzecc_p521_public.derr   T)r   r   zecc_p521_public_compressed.der)r'   r   rc   r   rp   )rd   rr   r   r   r   r   r   r   r     s
    
z1TestExport_P521.test_export_public_der_compressedc             C   sH   t d}t|}| jjdd}| || | jjdd}| || d S )Nzecc_p521_public.derr   )r   raw)r'   r_   rk   r   rp   )rd   rr   r[   r   r   r   r   r     s    z4TestExport_P521.test_export_public_sec1_uncompressedc             C   sT   t d}| jjddd}t d}t|}| || | jjddd}| || d S )Nzecc_p521_public.derr   T)r   r   zecc_p521_public_compressed.derr   )r'   rk   r   r_   rp   )rd   rr   r   r   r[   r   r   r   r     s    z2TestExport_P521.test_export_public_sec1_compressedc             C   s>   t d}| j }| || | jjddd}| || d S )Nzecc_p521_private.derr   F)r   r   )r'   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z/TestExport_P521.test_export_rfc5915_private_derc             C   s<   t d}| j }| || | jjdd}| || d S )Nzecc_p521_private_p8_clear.derr   )r   )r'   rj   r   rp   r   )rd   rr   r   r   r   r   r     s
    
z/TestExport_P521.test_export_private_pkcs8_clearc             C   s   | j jddd}| ttj|d  t|d}| | j | | j jdddd}t|d}| | j | | j jdddddid}t|d}| | j | d S )	Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   )r   r   r   r   r   )r   r   r   r   )	rj   r   ra   rb   r   r   rp   r   rc   )rd   r   r   r   r   r   r     s     z3TestExport_P521.test_export_private_pkcs8_encryptedc             C   s`   t dd }| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p521_public.pemr   Fr   )r   )r   r   )r'   r   rj   r   rp   rk   r   )rd   rr   r   r   r   r   r   
  s    z3TestExport_P521.test_export_public_pem_uncompressedc             C   sD   t dd }t|}|jddd}t dd }| || d S )Nzecc_p521_public.pemr   r   T)r   r   zecc_p521_public_compressed.pem)r'   r   r   rc   r   rp   )rd   rr   r   r   r   r   r   r   r     s
    
z1TestExport_P521.test_export_public_pem_compressedc             C   sF   t dd }| jd }| || | jjddd}| || d S )Nzecc_p521_private.pemr   r   F)r   r   )r'   r   rj   r   rp   r   )rd   rr   r   r   r   r   r   !  s
    z-TestExport_P521.test_export_private_pem_clearc             C   st   | j jdd}| ttj| d|ks*tt|d}| | j | | j jdddd}t|d}| | j | d S )Ns   secret)r   zEC PRIVATE KEYr|   r   F)r   r   r   )	rj   r   ra   rb   r   rc   r:   rp   r   )rd   r   r   r   r   r   r   ,  s    z1TestExport_P521.test_export_private_pem_encryptedc             C   sB   t dd }| j }| || | jjdd}| || d S )Nzecc_p521_private_p8_clear.pemr   r   )r   )r'   r   rj   r   rp   r   )rd   rr   r   r   r   r   r   ?  s
    
z3TestExport_P521.test_export_private_pkcs8_and_pem_1c             C   sv   | j jddd}| ttj| d|ks,tt|d}| | j | | j jdddd}t|d}| | j | d S )Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   zENCRYPTED PRIVATE KEYr   )r   r   r   )	rj   r   ra   rb   r   rc   r:   rp   r   )rd   r   r   r   r   r   r   K  s    z3TestExport_P521.test_export_private_pkcs8_and_pem_2c             C   s\   t dd}| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_p521_public_openssh.txtr   Fr   )r   )r   r   )r'   rk   r   rp   r   )rd   rr   r   r   r   r   r   `  s    
z0TestExport_P521.test_export_openssh_uncompressedc             C   sL   t dd}t|}|jddd}t|t|ks6t| |t| d S )Nzecc_p521_public_openssh.txtr   r   T)r   r   )r'   r   rc   r   r   r:   rp   )rd   rr   r   r   r   r   r   r   n  s
    

z.TestExport_P521.test_export_openssh_compressedc             C   st   | j jdddt d}| j jdddt d}| || | j jdddt d}| j jdddt d}| || d S )Nr   r|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   F)r   r   r   r   )rj   r   rY   rp   )rd   r   r   r   r   r   r   v  s$    



zTestExport_P521.test_prngc             C   s<   | j jdddt d}| j jdddt d}| || d S )Nr   Fr|   )r   r   r   r   s   secret)rj   r   rY   rp   )rd   r   r   r   r   r   r     s    

z.TestExport_P521.test_byte_or_string_passphrasec             C   s   | j t| jjdd | jjdddd | j t| jjddd | j t| jjdddd	d
 | j t| jjddd | j t| jjdddd | j t| jjddd	d | j t| jjddd d S )Nr   )r   r   r|   F)r   r   r   )r   r   r   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   )r   r   r*   )r   r   r   r   )ra   rb   rj   r   rk   )rd   r   r   r   r     s$    

z"TestExport_P521.test_error_params1c             C   sX   d}d}t |}t|jjd }| |d t |}t|jjd }| |d d S )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-----i   i8  iC  )r   rc   r   r   r   rp   )rd   r   r   r   r   r   r   r   r   r     s    	

z%TestExport_P521.test_compressed_curve)r   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r     s(   
	r   c                   s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Z  ZS )TestImport_Ed25519c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rT   rj   rk   )rd   rl   rm   )rn   r   r   ri     s    zTestImport_Ed25519.__init__c             C   sV   t d}t|}| | j| t|d }| | j| t|}| | j| d S )Nzecc_ed25519_public.der)r'   r   ro   rp   rk   rq   rc   )rd   rr   rS   r   r   r   rs     s    

z)TestImport_Ed25519.test_import_public_derc             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_ed25519_private.der)r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   test_import_pkcs8_der  s
    
z(TestImport_Ed25519.test_import_pkcs8_derc             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_ed25519_private_p8.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r}     s
    z8TestImport_Ed25519.test_import_private_pkcs8_encrypted_1c             C   s&   t d}t|d}| | j| d S )Nzecc_ed25519_private_p8.pemr|   )r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r~     s    z8TestImport_Ed25519.test_import_private_pkcs8_encrypted_2c             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_ed25519_private_p8_2.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r   	  s
    z8TestImport_Ed25519.test_import_private_pkcs8_encrypted_3c             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_ed25519_x509.der)r'   r   rq   rp   rk   rc   )rd   rr   rS   r   r   r   r   
	  s
    
z'TestImport_Ed25519.test_import_x509_derc             C   s$   t d}t|}| | j| d S )Nzecc_ed25519_public.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r   	  s    
z)TestImport_Ed25519.test_import_public_pemc             C   s$   t d}t|}| | j| d S )Nzecc_ed25519_private.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r   	  s    
z*TestImport_Ed25519.test_import_private_pemc             C   sV   xPdD ]H}t d| }t|d}| | j| tt|d}| | j| qW d S )N)r   r   r   r   zecc_ed25519_private_enc_%s.pemr|   s   secret)r'   r   rc   rp   rj   r   )rd   r   rr   rS   r   r   r   r   	  s    
z4TestImport_Ed25519.test_import_private_pem_encryptedc             C   s$   t d}t|}| | j| d S )Nzecc_ed25519_x509.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r   )	  s    
z'TestImport_Ed25519.test_import_x509_pemc             C   s<   t d}t|}| |  t|}| |  d S )Nzecc_ed25519_public_openssh.txt)r'   r   r   ZassertFalseZhas_privaterc   )rd   rr   rS   r   r   r   r   /	  s
    

z-TestImport_Ed25519.test_import_openssh_publicc             C   s   t d}t|}d S )Nzecc_ed25519_private_openssh.pem)r'   r   rc   )rd   rr   rS   r   r   r   r   6	  s    z4TestImport_Ed25519.test_import_openssh_private_clearc             C   s   t d}t|d}d S )Nz#ecc_ed25519_private_openssh_pwd.pems   password)r'   r   rc   )rd   rr   rS   r   r   r   r   :	  s    z7TestImport_Ed25519.test_import_openssh_private_password)r   r   r   ri   rs   r   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r     s   				
r   c                   s|   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Z  ZS )TestExport_Ed25519c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rT   rj   rk   )rd   rl   rm   )rn   r   r   ri   A	  s    zTestExport_Ed25519.__init__c             C   sZ   t d}| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_ed25519_public.derTr   )r   F)r   r   )r'   rk   r   rp   r   )rd   rr   r   r   r   r   test_export_public_derE	  s    z)TestExport_Ed25519.test_export_public_derc             C   s   | j t| jjdd d S )Nr   )r   )ra   rb   rk   r   )rd   r   r   r   test_export_public_sec1Q	  s    z*TestExport_Ed25519.test_export_public_sec1c             C   sR   t d}| j }| || | jjdd}| || | jt| jjddd d S )Nzecc_ed25519_private.derr   )r   F)r   r   )r'   rj   r   rp   r   ra   rb   )rd   rr   r   r   r   r   r   T	  s    
z2TestExport_Ed25519.test_export_private_pkcs8_clearc             C   s   | j jddd}| ttj|d  t|d}| | j | | j jdddd}t|d}| | j | | j jdddddid	}t|d}| | j | d S )
Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   )r   r   r   z"PBKDF2WithHMAC-SHA256AndAES128-CBCr   r   )r   r   r   r   )	rj   r   ra   rb   r   r   rp   r   rc   )rd   r   r   r   r   r   r   b	  s     z6TestExport_Ed25519.test_export_private_pkcs8_encryptedc             C   s0   t dd }| jjdd }| || d S )Nzecc_ed25519_public.pemr   r   )r   )r'   r   rk   r   rp   )rd   key_file_refrr   r   r   r   test_export_public_pem}	  s    z)TestExport_Ed25519.test_export_public_pemc             C   s0   t dd }| jjdd }| || d S )Nzecc_ed25519_private.pemr   r   )r   )r'   r   rj   r   rp   )rd   rr   r   r   r   r   r   	  s    z0TestExport_Ed25519.test_export_private_pem_clearc             C   sL   | j jdddd}| ttj| d|ks.tt|d}| | j | d S )Nr   s   secretz PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   zENCRYPTED PRIVATE KEYr|   )rj   r   ra   rb   r   rc   r:   rp   )rd   r   r   r   r   r   r   	  s    z4TestExport_Ed25519.test_export_private_pem_encryptedc             C   sf   t dd}t|}d|dd d }|d}| ||  |jdd}| ||  d S )Nzecc_ed25519_public_openssh.txtr   r)   r   Fr   )r   )	r'   r   rc   r   splitr   rp   r   r   )rd   rr   rR   r   r   r   r   test_export_openssh	  s    


z&TestExport_Ed25519.test_export_opensshc             C   s"   | j jdd}| |td d S )Nr   )r   s@   bc85b8cf585d20a4de47e84d1cb6183f63d9ba96223fcbc886e363ffdea20cff)rk   r   rp   r   )rd   r   r   r   r   test_export_raw	  s    z"TestExport_Ed25519.test_export_rawc             C   s<   | j jdddt d}| j jdddt d}| || d S )Nr   r|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   )rj   r   rY   rp   )rd   r   r   r   r   r   r   	  s    

zTestExport_Ed25519.test_prngc             C   s<   | j jdddt d}| j jdddt d}| || d S )Nr   r|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   s   secret)rj   r   rY   rp   )rd   r   r   r   r   r   r   	  s    

z1TestExport_Ed25519.test_byte_or_string_passphrasec             C   st   | j t| jjdd | j t| jjddd | j t| jjdddd | j t| jjddd	d
 | j t| jjddd d S )Nr   )r   r   r|   )r   r   r*   F)r   r   r   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   )ra   rb   rj   r   )rd   r   r   r   r   	  s    
z%TestExport_Ed25519.test_error_params1)r   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r   ?	  s   r   c                   sl   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Z  ZS )TestImport_Ed448c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rV   rj   rk   )rd   rl   rm   )rn   r   r   ri   	  s    zTestImport_Ed448.__init__c             C   sV   t d}t|}| | j| t|d }| | j| t|}| | j| d S )Nzecc_ed448_public.der)r'   r   ro   rp   rk   rq   rc   )rd   rr   rS   r   r   r   rs   	  s    

z'TestImport_Ed448.test_import_public_derc             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_ed448_private.der)r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r   	  s
    
z&TestImport_Ed448.test_import_pkcs8_derc             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_ed448_private_p8.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r}   	  s
    z6TestImport_Ed448.test_import_private_pkcs8_encrypted_1c             C   s&   t d}t|d}| | j| d S )Nzecc_ed448_private_p8.pemr|   )r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r~   	  s    z6TestImport_Ed448.test_import_private_pkcs8_encrypted_2c             C   s@   t d}t|d}| | j| t|d}| | j| d S )Nzecc_ed448_private_p8_2.derr|   )r'   r   rq   rp   rj   rc   )rd   rr   rS   r   r   r   r   	  s
    z6TestImport_Ed448.test_import_private_pkcs8_encrypted_3c             C   s>   t d}t|d }| | j| t|}| | j| d S )Nzecc_ed448_x509.der)r'   r   rq   rp   rk   rc   )rd   rr   rS   r   r   r   r   
  s
    
z%TestImport_Ed448.test_import_x509_derc             C   s$   t d}t|}| | j| d S )Nzecc_ed448_public.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r   

  s    
z'TestImport_Ed448.test_import_public_pemc             C   s$   t d}t|}| | j| d S )Nzecc_ed448_private.pem)r'   r   rc   rp   rj   )rd   rr   rS   r   r   r   r   
  s    
z(TestImport_Ed448.test_import_private_pemc             C   sV   xPdD ]H}t d| }t|d}| | j| tt|d}| | j| qW d S )N)r   r   r   r   zecc_ed448_private_enc_%s.pemr|   s   secret)r'   r   rc   rp   rj   r   )rd   r   rr   rS   r   r   r   r   
  s    
z2TestImport_Ed448.test_import_private_pem_encryptedc             C   s$   t d}t|}| | j| d S )Nzecc_ed448_x509.pem)r'   r   rc   rp   rk   )rd   rr   rS   r   r   r   r    
  s    
z%TestImport_Ed448.test_import_x509_pem)r   r   r   ri   rs   r   r}   r~   r   r   r   r   r   r   r   r   r   )rn   r   r   	  s   				
r   c                   s|   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Z  ZS )TestExport_Ed448c                s$   t t| j|| t \| _| _d S )N)rh   r   ri   rV   rj   rk   )rd   rl   rm   )rn   r   r   ri   )
  s    zTestExport_Ed448.__init__c             C   sZ   t d}| jd}| || | jjdd}| || | jjddd}| || d S )Nzecc_ed448_public.derTr   )r   F)r   r   )r'   rk   r   rp   r   )rd   rr   r   r   r   r   r   -
  s    z'TestExport_Ed448.test_export_public_derc             C   s   | j t| jjdd d S )Nr   )r   )ra   rb   rk   r   )rd   r   r   r   r   9
  s    z(TestExport_Ed448.test_export_public_sec1c             C   sR   t d}| j }| || | jjdd}| || | jt| jjddd d S )Nzecc_ed448_private.derr   )r   F)r   r   )r'   rj   r   rp   r   ra   rb   )rd   rr   r   r   r   r   r   <
  s    
z0TestExport_Ed448.test_export_private_pkcs8_clearc             C   s   | j jddd}| ttj|d  t|d}| | j | | j jdddd}t|d}| | j | | j jdddddid	}t|d}| | j | d S )
Nr|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   )r   r   r   z"PBKDF2WithHMAC-SHA384AndAES128-CBCr   r   )r   r   r   r   )	rj   r   ra   rb   r   r   rp   r   rc   )rd   r   r   r   r   r   r   J
  s     z4TestExport_Ed448.test_export_private_pkcs8_encryptedc             C   s0   t dd }| jjdd }| || d S )Nzecc_ed448_public.pemr   r   )r   )r'   r   rk   r   rp   )rd   r   rr   r   r   r   r   f
  s    z'TestExport_Ed448.test_export_public_pemc             C   s0   t dd }| jjdd }| || d S )Nzecc_ed448_private.pemr   r   )r   )r'   r   rj   r   rp   )rd   rr   r   r   r   r   r   k
  s    z.TestExport_Ed448.test_export_private_pem_clearc             C   sL   | j jdddd}| ttj| d|ks.tt|d}| | j | d S )Nr   s   secretz PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   zENCRYPTED PRIVATE KEYr|   )rj   r   ra   rb   r   rc   r:   rp   )rd   r   r   r   r   r   r   p
  s    z2TestExport_Ed448.test_export_private_pem_encryptedc             C   s   | j t| jjdd d S )Nr   )r   )ra   rb   rk   r   )rd   r   r   r   r   }
  s    z$TestExport_Ed448.test_export_opensshc             C   s"   | j jdd}| |td d S )Nr   )r   sr   899014ddc0a0e1260cfc1085afdf952019e9fd63372e3e366e26dad32b176624884330a14617237e3081febd9d1a15069e7499433d2f55dd80)rk   r   rp   r   )rd   r   r   r   r   r   
  s    z TestExport_Ed448.test_export_rawc             C   s<   | j jdddt d}| j jdddt d}| || d S )Nr   r|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   )rj   r   rY   rp   )rd   r   r   r   r   r   r   
  s    

zTestExport_Ed448.test_prngc             C   s<   | j jdddt d}| j jdddt d}| || d S )Nr   r|   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   s   secret)rj   r   rY   rp   )rd   r   r   r   r   r   r   
  s    

z/TestExport_Ed448.test_byte_or_string_passphrasec             C   st   | j t| jjdd | j t| jjddd | j t| jjdddd | j t| jjddd	d
 | j t| jjddd d S )Nr   )r   r   r|   )r   r   r*   F)r   r   r   z PBKDF2WithHMAC-SHA1AndAES128-CBC)r   r   r   r   )ra   rb   rj   r   )rd   r   r   r   r   
  s    
z#TestExport_Ed448.test_error_params1)r   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rn   r   r   '
  s   r   c             C   s   g }|t t7 }y|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t	7 }|t t
7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }W n tk
r   Y nX |S )N)r   r`   rg   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )configtestsr   r   r   	get_tests
  s(    r   __main__c               C   s   t t S )N)unittestZ	TestSuiter   r   r   r   r   <lambda>
  r(   r   suite)ZdefaultTest)r   )9r   r   r!   r   binasciir   ZCryptodome.SelfTest.st_commonr   ZCryptodome.Util.py3compatr   r   r   ZCryptodome.Util.asn1r   r   ZCryptodome.Util.numberr	   ZCryptodome.Hashr
   ZCryptodome.PublicKeyr   r   r   ImportErrorrb   r   r'   r/   rB   rD   rH   rL   rP   rT   rV   rY   r_   ZTestCaser`   rg   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mainr   r   r   r   <module>   sz   


nw     	    "  '  /h Y 

