Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyc


pZc@s-dZdZddlZddlZddlmZmZddlTejdkr_dZ	ne	Z	ddd	YZ
e
d
ZdejfdYZ
d
e
fdYZdejfdYZdejfdYZdejfdYZdejfdYZdZdZdS(s&Self-testing for PyCrypto hash moduless$Id$iN(ta2b_hextb2a_hex(t*icKs
|jS(N(tcopy(tkwargs((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pytdict&st
_NoDefaultcBseZRS((t__name__t
__module__(((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR+scCs@y||}Wn$tk
r4|tkr0n|SX||=|S(sAGet an item from a dictionary, and remove it from the dictionary.(tKeyErrorR(tdtktdefaulttretval((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyt_extract,s
tCipherSelfTestcBs,eZdZdZdZdZRS(cCs5tjj|||_|j}t|d|_tt|d|_tt|d|_	tt|d|_
t|dd|_t|dd}t
||_|dk	rt|jd||_t|dd|_|jdk	r(t|j|_q(nd|_d|_||_dS(	Ntdescriptiontkeyt	plaintextt
ciphertexttmodule_nametmodetMODE_tiv(tunittesttTestCaset__init__tmoduleRRRtbRRRtNoneRtstrt	mode_nametgetattrRRtextra_params(tselfRtparamsR((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR:s$			cCs|jS(N(R(R"((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pytshortDescriptionTscCs|jj}t|jdr0|j|jjkr0ddlm}t|d|j	}t|dij}|j
drtt|d|d<n|j
drtt|d|d<n|j
dsd	|jj
t|jdd
t|jdd
|d<n|||d<n|jdkr[|jj	t|j|S|jdkr|jj	t|j|j|S|jj	t|j|jt|j|SdS(NtMODE_CTRi(tCountert	ctr_classt
ctr_paramstprefixtsuffixtnbitsittcounter(R!RthasattrRRR%tCrypto.UtilR&Rtnewthas_keyRRt
block_sizetlentgetRRR(R"R#R&R'R(((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyt_newWs"'C"cCst|j}t|j}t|jj|}t|jj|}t|jj|}t|jj|}|j|j||j|j||j|j||j|j|dS(N(RRRRR5tencrypttdecrypttassertEqual(R"RRtct1tpt1tct2tpt2((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pytrunTestos(RRRR$R5R=(((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR8s			tCipherStreamingSelfTestcBseZdZdZRS(cCs:|j}|jdk	r/|d|jf7}nd|fS(Ns in %s modes%%s should behave like a stream cipher(RRRR(R"tdesc((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR$s	cCs*t|j}t|j}g}|j}xAtdt|dD]'}|j|j|||d!qIWtt	dj
|}|j|j|g}|j}xAtdt|dD]'}|j|j|||d!qWtt	dj
|}|j|j|dS(NiiR,(RRRR5trangeR3tappendR6RRtjoinR8(R"RRtct3tciphertitpt3((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR=s%%(RRR$R=(((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR>}s	tCTRSegfaultTestcBs#eZdZdZdZRS(cCsEtjj|||_t|d|_|jdd|_dS(NRR(	RRRRRRR4RR(R"RR#((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyRs	cCsd|j|jfS(NsNRegression test: %s.new(key, %s.MODE_CTR) should raise TypeError, not segfault(R(R"((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR$scCs/|jt|jjt|j|jjdS(N(tassertRaisest	TypeErrorRR0RRR%(R"((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR=s(RRRR$R=(((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyRGs		tCTRWraparoundTestcBs#eZdZdZdZRS(cCsEtjj|||_t|d|_|jdd|_dS(NRR(	RRRRRRR4RR(R"RR#((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyRs	cCsd|jfS(Ns]Regression test: %s with MODE_CTR should raise OverflowError on wraparound when shortcut used(R(R"((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR$sc
Csddlm}xdD]}xd
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(R/R&R0RR2RRR%RR6RHt
OverflowError(R"R&RMRLtctrRDtblock((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR=s

=*
(RRRR$R=(((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyRJs		tCFBSegmentSizeTestcBs#eZdZdZdZRS(cCs=tjj|||_t|d|_|d|_dS(NRR(RRRRRRR(R"RR#((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyRs	cCs|jS(N(R(R"((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR$scCswxHtddD]7}|jt|jjt|j|jjd|qW|jjt|j|jjdddS(snRegression test: m.new(key, m.MODE_CFB, segment_size=N) should require segment_size to be a multiple of 8 bitsiitsegment_sizeN(R@RHt
ValueErrorRR0RRtMODE_CFB(R"RE((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR=s5(RRRR$R=(((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyRRs		t
RoundtripTestcBs#eZdZdZdZRS(cCsddlm}tjj|||_|j|j|_t	|d|_
dt	|d|_|jdd|_dS(Ni(tRandomRidRR(tCryptoRWRRRRtget_random_bytesR2RRRRR4RR(R"RR#RW((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyRs	cCsd|jfS(Ns8%s .decrypt() output of .encrypt() should not be garbled(R(R"((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR$scCs(|jj}|jjt|j|}|j|j}|jjt|j|}|j|}|j|j|x|jj	|jj
|jjfD]}|jjt|j||j}|jjt|j||j}|j|j}|j|}|j|j|qWdS(N(
RtMODE_ECBR0RRR6RR7R8tMODE_CBCRUtMODE_OFBR(R"Rtencryption_cipherRtdecryption_ciphertdecrypted_plaintext((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyR=s($$(RRRR$R=(((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyRVs			c	Csg}d}xtt|D]}||}idd6}t|dkrl|\|d<|d<|d<nt|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|	ddn|
dk	r|
}n9|dkr|	rd||
f}nd
||
|	f}d||d|f}||d	<||d<|sA|t||t	||t
||t||g7}d}n|jt
|||dkr||jt||n|dkr|jdr|j}|d	cd7<|jdij}||d<|djdsd|dd<n|jt
||qqW|S(NitECBRiRRRiRisUnsupported tuple size %ds
p=%s, k=%ssp=%s, k=%s, %rs
%s #%d: %siRtCTRR's (shortcut disabled)R(RM(R@R3tupdatetAssertionErrorRRRR4RGRJRRRVRARR>R1(RRt	test_datatteststextra_tests_addedREtrowR#R!tp2tp_keytp_plaintexttp_ciphertextt
p_descriptiontp_modeRtnametparams2tctr_params2((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pytmake_block_testss`

%%	

	
cCsg}xtt|D]}||}i}t|dkr_|\|d<|d<|d<nt|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(
R@R3RbRcRRRRARR>(RRRdReRERgR#R!RhRiRjRkRlRRn((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pytmake_stream_tests2s8
%%	

((t__doc__t__revision__tsysRtbinasciiRRtCrypto.Util.py3compatt
hexversionRRRRRR>RGRJRRRVRqRr(((sA/usr/lib/python2.7/dist-packages/Crypto/SelfTest/Cipher/common.pyt<module>s$
E	B