
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
ybD                 @   sp   d dl mZmZ ddlmZmZmZmZmZm	Z	 ddlm
Z
mZmZ ddlmZ ddlmZ G dd	 d	eZd
S )    )hexlify	unhexlify   )AESbytes_to_longbytes_to_intlong_to_byteshmac_sha256blake2b_256)increment_ivbytes16_to_intint_to_bytes16)hkdf_hmac_sha512   )BaseTestCasec               @   sl   e Z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S )CryptoTestCasec             C   s   | j tdd d S )Ns      r   )assert_equalr   )self r   /usr/lib64/python3.6/crypto.pytest_bytes_to_int   s    z CryptoTestCase.test_bytes_to_intc             C   s$   | j tdd | j tdd d S )Ns          r   )r   r   r   )r   r   r   r   test_bytes_to_long   s    z!CryptoTestCase.test_bytes_to_longc             C   sD   | j tdd | j tdd | j tdd | j tdd d S )Ns                  r   s                  r   @   l            l            )r   r   r   )r   r   r   r   test_bytes16_to_int   s    z"CryptoTestCase.test_bytes16_to_intc             C   s   d}d}d}| j t|d| | j t|d| | j t|d| d}d}d	}| j t|d| | j t|d| | j t|d| | j t|d| d S )Ns                   s                  s                  r   r   r   s           s                  s                 r   l            )r   r   )r   Ziv0Ziv1Ziv2ZivaZivbZivcr   r   r   test_increment_iv   s    z CryptoTestCase.test_increment_ivc             C   s   dd }dd }t d|d}| jt|jdd |j|}| jt|d	 | jt|jdd
 t d|d}| jt|jdd |j|}| j|| | jt|jdd
 d S )N   X    s   foo
   T)Z
is_encryptkey   r   s<   c6efb702de12498f34a2c2bbc8149e759996d08bf6dc5c610aefc0c3a466r   F)r   r   r   ZivZencryptr   Zdecrypt)r   r   dataZaesZcdataZpdatar   r   r   test_aes'   s    

zCryptoTestCase.test_aesc             C   s`   d}t td}td}td}td}td}d}d	d
 }td}td}dd
 }td}d S )N      Z4869205468657265Z@b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7Z4a656665Z87768617420646f2079612077616e7420666f72206e6f7468696e673fZ@5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843      2   Z@773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565feZ20102030405060708090a0b0c0d0e0f10111213141516171819   Z@82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665bs   s   )
memoryviewr   )r   r   r    Zhmacr   r   r   test_hmac_sha2567   s    zCryptoTestCase.test_hmac_sha256c             C   s   t d}tdd }d S )NZ@e944973af2256d4d670c12dd75304c319f58f4e40df6fb18ef996cb47e063676s
   1234567890d   )r   r(   )r   r   r    r   r   r   test_blake2b_256Q   s    zCryptoTestCase.test_blake2b_256c             C   s2   dd }t jd}t jd}d}t||||}d S )Nr"      000102030405060708090a0b0cf0f1f2f3f4f5f6f7f8f9*   )bytesfromhexr   )r   ikmsaltinfolokmr   r   r   test_hkdf_hmac_sha512d   s    

z$CryptoTestCase.test_hkdf_hmac_sha512c             C   s4   t jd}t jd}t jd}d}t||||}d S )NZ000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4fZ606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafZb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeffR   )r0   r1   r   )r   r2   r3   r4   r5   r6   r   r   r   test_hkdf_hmac_sha512_2m   s    


z&CryptoTestCase.test_hkdf_hmac_sha512_2c             C   s(   t jd}d }d}d}t||||}d S )NZ,0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b    r/   )r0   r1   r   )r   r2   r3   r4   r5   r6   r   r   r   test_hkdf_hmac_sha512_3z   s    
z&CryptoTestCase.test_hkdf_hmac_sha512_3c             C   s4   t jd}t jd}t jd}d}t||||}d S )NZ0b0b0b0b0b0b0b0b0b0b0br-   r.   r/   )r0   r1   r   )r   r2   r3   r4   r5   r6   r   r   r   test_hkdf_hmac_sha512_4   s    


z&CryptoTestCase.test_hkdf_hmac_sha512_4c             C   s(   t jd}d }d}d}t||||}d S )NZ,0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0cr:   r/   )r0   r1   r   )r   r2   r3   r4   r5   r6   r   r   r   test_hkdf_hmac_sha512_5   s    
z&CryptoTestCase.test_hkdf_hmac_sha512_5N)__name__
__module____qualname__r   r   r   r   r!   r)   r+   r7   r9   r;   r<   r=   r   r   r   r   r   	   s   			r   N)Zbinasciir   r   Zcrypto.low_levelr   r   r   r   r	   r
   r   r   r   r    r   r   r   r   r   r   <module>   s
    