관리-도구
편집 파일: test_ChaCha20.cpython-311.pyc
� O�Dg\O � � � d dl Z d dlZd dlZd dlmZmZ d dlmZmZm Z d dl mZ d dlm Z d dlmZ G d� dej � � Z G d � d ej � � Z G d� dej � � Z G d � dej � � Z G d� dej � � Z G d� dej � � Zi fd�Zedk rd dlZd� Z ej d�� � dS dS )� N)�hexlify� unhexlify)�b�tobytes�bchr)�strxor_c)�list_test_cases)�ChaCha20c �J � e Zd Zd� Zd� Zd� Zd� Zd� Zd� Zd� Z d� Z d � Zd � ZdS )�ChaCha20Testc � � t j t d� � dz d�� � }| � |j d� � t j t d� � dz d�� � }| � |j d� � d S )N�0� s 00000000��key�nonces 000000000000)r �newr �assertEqualr )�self�ciphers ��/builddir/build/BUILD/imunify360-venv-2.4.0/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/SelfTest/Cipher/test_ChaCha20.py�test_new_positivezChaCha20Test.test_new_positive- st � ���!�C�&�&��)�6�:�:�:�������x�0�0�0���!�C�&�&��)�7�;�;�;�������y�1�1�1�1�1� c � � t j }| � t |� � | � t |t d� � �� � | � t |t d� � dz t d� � �� � | � t |t d� � t d� � dz �� � d S )Nr )r � )r r r )r r �assertRaises� TypeErrorr � ValueError)r r s r �test_new_negativezChaCha20Test.test_new_negative3 s� � ��l�����)�S�)�)�)����)�S��#����7�7�7����*�c��3�����q��v�v��F�F�F����*�c��3���Q�s�V�V�B�Y��G�G�G�G�Gr c �* � t j t d� � dz �� � }t j t d� � dz �� � }| � t |j � � d� � | � |j |j � � d S )N� r )r r )r r r r �lenr �assertNotEqual)r �cipher1�cipher2s r �test_default_noncezChaCha20Test.test_default_nonce: sz � ��,�4��7�7�R�<�0�0�0���,�4��7�7�R�<�0�0�0������W�]�+�+�Q�/�/�/����G�M�7�=�9�9�9�9�9r c �� � d}d}t j ||�� � }| � ||j � � d}t j ||�� � }| � ||j � � d S )N� AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAs PPPPPPPPr s QQQQQQQQQQQQ�r r r r )r r �nonce1r$ �nonce2r% s r � test_noncezChaCha20Test.test_nonce@ so � ������,�3�f�5�5�5��������/�/�/����,�3�f�5�5�5��������/�/�/�/�/r c � � t j t d� � dz t d� � dz �� � }|� t d� � � � | � t |j t d� � � � t j t d� � dz t d� � dz �� � }|� t d� � � � | � t |j t d� � � � dS ) zFVerify that a cipher cannot be used for both decrypting and encrypting�5r �6r r �8�9N)r r r �encryptr r �decrypt)r �c1�c2s r �test_eiter_encrypt_or_decryptz*ChaCha20Test.test_eiter_encrypt_or_decryptK s� � � �\�a��f�f�r�k��3���!�� <� <� <�� � � �1�S�6�6�������)�R�Z��3���8�8�8� �\�a��f�f�r�k��3���!�� <� <� <�� � � �1�S�6�6�������)�R�Z��3���8�8�8�8�8r c � � t d� � dz }t j t d� � dz t d� � dz �� � }t j t d� � dz t d� � dz �� � }|� |� � }| � |� |� � |� � | � |� t d� � � � t d� � � � | � |� t d� � � � t d� � � � d S ) N�Ai r. r r/ r r � )r r r r2 r r3 )r �ptr4 r5 �cts r �test_round_tripzChaCha20Test.test_round_tripV s� � � �s�V�V�d�]�� �\�a��f�f�r�k��3���!�� <� <� <�� �\�a��f�f�r�k��3���!�� <� <� <�� �Z�Z��^�^��������B����,�,�,�������A�b�E�E�*�*�A�b�E�E�2�2�2�������A�b�E�E�*�*�A�b�E�E�2�2�2�2�2r c �t � ddl m} d}t |� � }t d� � }t |� � |k r=||� |� � � � � z }t |� � |k �=t j t d� � dz t d� � dz � � � }|� |� � }t j t d� � dz t d� � dz � � � }t j t d� � dz t d� � dz � � � }d} |D ]�} | � |� || | | z � � � || | | z � � � | � |� || | | z � � � || | | z � � � | | z } ��d S )zCVerify that an arbitrary number of bytes can be encrypted/decryptedr )�SHA1)r! � � � � � � r9 �7r �tr r N)�Crypto.Hashr>