Current File : //usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyc
�
���\c@s_dZdZddlZddlZddlmZmZddlTejdkr_d�Z	ne	Z	ddd	��YZ
e
d
�Zdejfd��YZ
d
e
fd��YZdejfd��YZdejfd��YZdejfd��YZdejfd��YZdejfd��YZdejfd��YZd�Zd�ZdS(s&Self-testing for PyCrypto hash moduless$Id$i����N(ta2b_hextb2a_hex(t*icKs
|j�S(N(tcopy(tkwargs((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pytdict&st
_NoDefaultcBseZRS((t__name__t
__module__(((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR+scCs@y||}Wn$tk
r4|tkr0�n|SX||=|S(sAGet an item from a dictionary, and remove it from the dictionary.(tKeyErrorR(tdtktdefaulttretval((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyt_extract,s
tCipherSelfTestcBs/eZd�Zd�Zdd�Zd�ZRS(cCsntjj|�||_|j�}t|d�|_tt|d��|_tt|d��|_	tt|d��|_
t|dd�|_t|dd�}t
|�|_|dk	rOt|jd|�|_t|dd�|_|jdk	rt|j�|_nt|d	d�|_|jdk	rat|j�|_qand|_d|_||_dS(
Ntdescriptiontkeyt	plaintextt
ciphertexttmodule_nametmodetMODE_tivtencrypted_iv(tunittesttTestCaset__init__tmoduleRRRtbRRRtNoneRtstrt	mode_nametgetattrRRRtextra_params(tselfRtparamsR((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR:s*			cCs|jS(N(R(R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pytshortDescriptionYsicCs|jj�}t|jd�r0|j|jjkr0ddlm}t|d|j	�}t|di�j�}|j
d�r�tt|d��|d<n|j
d�r�tt|d��|d<n|j
d�sd	|jj
t|jdd
��t|jdd
��|d<n||�|d<n|jdkr[|jj	t|j�|�S|jdkr�|jj	t|j�|j|�S|r�|j|jjkr�|jj	t|j�|jt|j�|�S|jj	t|j�|jt|j�|�SdS(NtMODE_CTRi����(tCountert	ctr_classt
ctr_paramstprefixtsuffixtnbitsittcounter(R"RthasattrRRR&tCrypto.UtilR'Rtnewthas_keyRRt
block_sizetlentgetRRRtMODE_OPENPGPR(R#t
do_decryptionR$R'R(R)((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyt_new\s&'C".cCs[t|j�}t|j�}t|j�j|��}t|jd�j|��}t|j�j|��}t|jd�j|��}t|jd�r|j	|jj
krt|j�}|j
|j|| �|j
|j|| �||}||}n|j
|j|�|j
|j|�|j
|j|�|j
|j|�dS(NiR6(RRRRR8tencrypttdecryptR/RRR6R4RtassertEqual(R#RRtct1tpt1tct2tpt2teilen((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pytrunTestxs '

(RRRR%R8RA(((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR8s		tCipherStreamingSelfTestcBseZd�Zd�ZRS(cCs:|j}|jdk	r/|d|jf7}nd|fS(Ns in %s modes%%s should behave like a stream cipher(RRRR (R#tdesc((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR%�s	cCs*t|j�}t|j�}g}|j�}xAtdt|�d�D]'}|j|j|||d!��qIWtt	d�j
|��}|j|j|�g}|j�}xAtdt|�d�D]'}|j|j|||d!��q�Wtt	d�j
|��}|j|j|�dS(NiiR-(RRRR8trangeR4tappendR9RRtjoinR;(R#RRtct3tciphertitpt3((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRA�s%%(RRR%RA(((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRB�s	tCTRSegfaultTestcBs#eZd�Zd�Zd�ZRS(cCsEtjj|�||_t|d�|_|jdd�|_dS(NRR(	RRRRRRR5RR(R#RR$((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR�s	cCsd|j|jfS(NsNRegression test: %s.new(key, %s.MODE_CTR) should raise TypeError, not segfault(R(R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR%�scCs/|jt|jjt|j�|jj�dS(N(tassertRaisest	TypeErrorRR1RRR&(R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRA�s(RRRR%RA(((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRK�s		tCTRWraparoundTestcBs#eZd�Zd�Zd�ZRS(cCsEtjj|�||_t|d�|_|jdd�|_dS(NRR(	RRRRRRR5RR(R#RR$((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR�s	cCsd|jfS(Ns]Regression test: %s with MODE_CTR should raise OverflowError on wraparound when shortcut used(R(R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR%�sc
Cs�ddlm}x�dD]�}x�d
D]�}|jd|jjddd|jjdd|d	|�}|jjt|j�|jjd
|�}td�|jj}|j	|�|j
t|j	|�q$WqWdS(Ni����(R'iiit
initial_valuelt
little_endiantdisable_shortcutR.t(ii(ii(R0R'R1RR3RRR&RR9RLt
OverflowError(R#R'RQRPtctrRHtblock((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRA�s

=*
(RRRR%RA(((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRN�s		tCFBSegmentSizeTestcBs#eZd�Zd�Zd�ZRS(cCs=tjj|�||_t|d�|_|d|_dS(NRR(RRRRRRR(R#RR$((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR�s	cCs|jS(N(R(R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR%�scCs�xHtdd�D]7}|jt|jjt|j�|jjd|�qW|jjt|j�|jjd|jjdd�dS(snRegression test: m.new(key, m.MODE_CFB, segment_size=N) should require segment_size to be a multiple of 8 bitsiitsegment_sizeRRN(	RDRLt
ValueErrorRR1RRtMODE_CFBR3(R#RI((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRA�s5(RRRR%RA(((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRV�s		t
RoundtripTestcBs#eZd�Zd�Zd�ZRS(cCs�ddlm}tjj|�||_|j|j�|_t	|d�|_
dt	|d�|_|jdd�|_dS(Ni����(tRandomRidRR(tCryptoR[RRRRtget_random_bytesR3RRRRR5RR(R#RR$R[((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR�s	cCsd|jfS(Ns8%s .decrypt() output of .encrypt() should not be garbled(R(R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR%�scCs�|jj}|jjt|j�|�}|j|j�}|jjt|j�|�}|j|�}|j|j|�|jj	}|jjt|j�||j
�}|j|j�}||jjd }||jjd}|jjt|j�||�}|j|�}|j|j|�x�|jj|jj
|jjfD]�}|jjt|j�||j
�}|j|j�}|jjt|j�||j
�}|j|�}|j|j|�qKWdS(Ni(RtMODE_ECBR1RRR9RR:R;R6RR3tMODE_CBCRYtMODE_OFB(R#Rtencryption_cipherRtdecryption_ciphertdecrypted_plaintextteiv_ciphertextteiv((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRA�s($!($$(RRRR%RA(((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRZ�s			tPGPTestcBs#eZd�Zd�Zd�ZRS(cCs0tjj|�||_t|d�|_dS(NR(RRRRRR(R#RR$((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRs	cCsdS(NsRMODE_PGP was implemented incorrectly and insecurely. It's completely banished now.((R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR%scCs/|jt|jjt|j�|jj�dS(N(RLRXRR1RRtMODE_PGP(R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRAs(RRRR%RA(((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRf
s		tIVLengthTestcBs,eZd�Zd�Zd�Zd�ZRS(cCs0tjj|�||_t|d�|_dS(NR(RRRRRR(R#RR$((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRs	cCsdS(NsTCheck that all modes except MODE_ECB and MODE_CTR require an IV of the proper length((R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyR% scCs|jt|jjt|j�|jjd�|jt|jjt|j�|jjd�|jt|jjt|j�|jjd�|jt|jjt|j�|jj	d�|jjt|j�|jj
d�|jjt|j�|jjdd|j�dS(NR-R.(
RLRXRR1RRR_RYR`R6R^R&t_dummy_counter(R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRA#s%cCsd|jjS(NRR(RR3(R#((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRi/s(RRRR%RARi(((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyRhs			cCs3g}d}x tt|��D]}||}idd6}t|�dkrl|\|d<|d<|d<n�t|�dkr�|\|d<|d<|d<|d	<n`t|�d
kr�|\|d<|d<|d<|d	<}|j|�ntdt|�f��|j�}	t|	d�}
t|	d�}t|	d�}t|	d	d�}
|	jdd�}|dkrt|	dd�n|
dk	r�|
}n9|dkr�|	r�d||
f}nd
||
|	f}d||d|f}||d	<||d<|sY|t||�t	||�t
||�t||�t||�t
||�g7}d}n|jt||��|dkr�|jt||��n|dkr|jd�r|j�}|d	cd7<|jdi�j�}||d<|djd�sd|dd<n|jt||��qqW|S(NitECBRiRRRiRisUnsupported tuple size %ds
p=%s, k=%ssp=%s, k=%s, %rs
%s #%d: %siRtCTRR(s (shortcut disabled)R)RQ(RDR4tupdatetAssertionErrorRRRR5RKRNRVRZRfRhRERRBR2(RRt	test_datatteststextra_tests_addedRItrowR$R"tp2tp_keytp_plaintexttp_ciphertextt
p_descriptiontp_modeRtnametparams2tctr_params2((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pytmake_block_tests2sd

%%	

	
cCs�g}x�tt|��D]�}||}i}t|�dkr_|\|d<|d<|d<n�t|�dkr�|\|d<|d<|d<|d<n`t|�dkr�|\|d<|d<|d<|d<}|j|�ntdt|�f��|j�}t|d�}	t|d�}
t|d�}t|dd�}|dk	rV|}
n,|sod	|
|	f}
nd
|
|	|f}
d||d|
f}||d<||d
<|jt||��|jt	||��qW|S(NiRRRiRisUnsupported tuple size %ds
p=%s, k=%ssp=%s, k=%s, %rs
%s #%d: %siR(
RDR4RlRmRRRRERRB(RRRnRoRIRqR$R"RrRsRtRuRvRRx((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pytmake_stream_testsvs8
%%	

((t__doc__t__revision__tsysRtbinasciiRRtCrypto.Util.py3compatt
hexversionRRRRRRBRKRNRVRZRfRhR{R|(((sC/usr/lib64/python2.7/site-packages/Crypto/SelfTest/Cipher/common.pyt<module>s(
X)
	D