1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
Ë
ž¬`i :ãó–—dZdgZddlZddlmZddlmZmZmZddl    m
Z
ddl m Z ddl mZmZdd    lmZmZdd
lmZGd „de«Zd „Zy) z
EAX mode.
ÚEaxModeéN)Ú    unhexlify)Ú byte_stringÚbordÚ _copy_bytes)Ú    is_buffer)Ústrxor)Ú long_to_bytesÚ bytes_to_long)ÚCMACÚBLAKE2s)Úget_random_bytescóT—eZdZdZd„Zd„Zd d„Zd d„Zd„Zd„Z    d    „Z
d
„Z d d „Z d d „Z y)raç*EAX* mode.
 
    This is an Authenticated Encryption with Associated Data
    (`AEAD`_) mode. It provides both confidentiality and authenticity.
 
    The header of the message may be left in the clear, if needed,
    and it will still be subject to authentication.
 
    The decryption step tells the receiver if the message comes
    from a source that really knowns the secret key.
    Additionally, decryption detects if any part of the message -
    including the header - has been modified or corrupted.
 
    This mode requires a *nonce*.
 
    This mode is only available for ciphers that operate on 64 or
    128 bits blocks.
 
    There are no official standards defining EAX.
    The implementation is based on `a proposal`__ that
    was presented to NIST.
 
    .. _AEAD: http://blog.cryptographyengineering.com/2012/05/how-to-choose-authenticated-encryption.html
    .. __: http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/eax/eax-spec.pdf
 
    :undocumented: __init__
    c ó4—|j|_    tdd|«|_    ||_d|_gd¢|_d|jcxkr|jksnt d|jz«‚t|j«dk(r t d«‚t|«s td«‚tdd«Dcgc]B}tj|d    |jd
z
ztjd |«z||¬ «‘ŒDc}|_|jdj!|j«|jd
|_t%|jdj'««}|j||j(f|d dœ|¤Ž|_ycc}w)zEAX cipher modeN©ÚupdateÚencryptÚdecryptÚdigestÚverifyéz3'mac_len' must be at least 2 and not larger than %drz!Nonce cannot be empty in EAX modez,nonce must be bytes, bytearray or memoryviewéóéÚB)Ú    ciphermodÚ cipher_paramsó)Ú initial_valueÚnonce)Ú
block_sizerr Ú_mac_lenÚ_mac_tagÚ_nextÚ
ValueErrorÚlenrÚ    TypeErrorÚranger ÚnewÚstructÚpackÚ_omacrÚ_signerr rÚMODE_CTRÚ_cipher)ÚselfÚfactoryÚkeyr Úmac_lenrÚiÚ counter_ints        õjH:\项目\archive\测试组\脚本\Change_password\venv_build\Lib\site-packages\Crypto/Cipher/_mode_eax.pyÚ__init__zEaxMode.__init__Psx€ð"×,Ñ,ˆŒØ@ä   t¨UÓ3ˆŒ
Ø=àˆŒ ؈Œ ò*ˆŒ
ðT—]‘]Ô5 d§o¡oÔ5ÜÐRØ#Ÿ™ñ/ó0ð 0ô ˆtz‰z‹?˜aÒ ÜÐ@ÓAÐ AܘÔÜÐJÓKÐ Kô˜q !›ö ð
ô    —‘˜Ø  D§O¡O°aÑ$7Ñ8¼6¿;¹;ÀsÈAÓ;NÑNØ#*Ø'4ö6òˆŒ
ð     
‰
1‰ ×јTŸZ™ZÔ(Ø—z‘z !‘}ˆŒ ô$ D§J¡J¨q¡M×$8Ñ$8Ó$:Ó;ˆ Ø"w—{‘{ 3Ø#*×#3Ñ#3ð4à1<Ø),ñ4ð&3ñ    4ˆ ùòsÂ=AFcó€—d|jvr td«‚gd¢|_|jj|«|S)aProtect associated data
 
        If there is any associated data, the caller has to invoke
        this function one or more times, before using
        ``decrypt`` or ``encrypt``.
 
        By *associated data* it is meant any data (e.g. packet headers) that
        will not be encrypted and will be transmitted in the clear.
        However, the receiver is still able to detect any modification to it.
 
        If there is no associated data, this method must not be called.
 
        The caller may split associated data in segments of any size, and
        invoke this method multiple times, each time with the next segment.
 
        :Parameters:
          assoc_data : bytes/bytearray/memoryview
            A piece of associated data. There are no restrictions on its size.
        rz<update() can only be called immediately after initializationr)r$r'r-r)r0Ú
assoc_datas  r6rzEaxMode.updatesG€ð* ˜4Ÿ:™:Ñ %ÜðDóEð Eò*ˆŒ
ð      ‰ ×јJÔ'؈ rNcó—d|jvr td«‚ddg|_|jj||¬«}|€ |jdj |«|S|jdj |«|S)aéEncrypt data with the key and the parameters set at initialization.
 
        A cipher object is stateful: once you have encrypted a message
        you cannot encrypt (or decrypt) another message using the same
        object.
 
        The data to encrypt can be broken up in two or
        more pieces and `encrypt` can be called multiple times.
 
        That is, the statement:
 
            >>> c.encrypt(a) + c.encrypt(b)
 
        is equivalent to:
 
             >>> c.encrypt(a+b)
 
        This function does not add any padding to the plaintext.
 
        :Parameters:
          plaintext : bytes/bytearray/memoryview
            The piece of data to encrypt.
            It can be of any length.
        :Keywords:
          output : bytearray/memoryview
            The location where the ciphertext must be written to.
            If ``None``, the ciphertext is returned.
        :Return:
          If ``output`` is ``None``, the ciphertext as ``bytes``.
          Otherwise, ``None``.
        rz@encrypt() can only be called after initialization or an update()r©Úoutputr)r$r'r/rr,r)r0Ú    plaintextr<Úcts    r6rzEaxMode.encryptžs‡€ðB ˜DŸJ™JÑ &Üð=ó>ð >à Ð*ˆŒ
Ø \‰\× !Ñ ! )°FÐ !Ó ;ˆØ ˆ>Ø J‰Jq‰M×  Ñ   Ô $ðˆ    ð J‰Jq‰M×  Ñ   Ô (؈    rcó¼—d|jvr td«‚ddg|_|jdj|«|jj ||¬«S)aëDecrypt data with the key and the parameters set at initialization.
 
        A cipher object is stateful: once you have decrypted a message
        you cannot decrypt (or encrypt) another message with the same
        object.
 
        The data to decrypt can be broken up in two or
        more pieces and `decrypt` can be called multiple times.
 
        That is, the statement:
 
            >>> c.decrypt(a) + c.decrypt(b)
 
        is equivalent to:
 
             >>> c.decrypt(a+b)
 
        This function does not remove any padding from the plaintext.
 
        :Parameters:
          ciphertext : bytes/bytearray/memoryview
            The piece of data to decrypt.
            It can be of any length.
        :Keywords:
          output : bytearray/memoryview
            The location where the plaintext must be written to.
            If ``None``, the plaintext is returned.
        :Return:
          If ``output`` is ``None``, the plaintext as ``bytes``.
          Otherwise, ``None``.
        rz@decrypt() can only be called after initialization or an update()rrr;)r$r'r,rr/r)r0Ú
ciphertextr<s   r6rzEaxMode.decryptÊsb€ðB ˜DŸJ™JÑ &ÜðCóDð Dà Ð*ˆŒ
Ø 
‰
1‰ ×јZÔ(؏|‰|×#Ñ# J°vÐ#Ó>Ð>rcó(—d|jvr td«‚dg|_|jsZd|jz}t    d«D])}t ||j |j««}Œ+|d|j|_|jS)zýCompute the *binary* MAC tag.
 
        The caller invokes this function at the very end.
 
        This method returns the MAC that shall be sent to the receiver,
        together with the ciphertext.
 
        :Return: the MAC, as a byte string.
        rzAdigest() cannot be called when decrypting or validating a messagerrN)    r$r'r#r!r(r    r,rr")r0Útagr4s   r6rzEaxMode.digestòsŒ€ð ˜4Ÿ:™:Ñ %Üð;ó<ð <àZˆŒ
à}Š}ؘDŸO™OÑ+ˆCܘ1“Xò :Ü˜S $§*¡*¨Q¡-×"6Ñ"6Ó"8Ó9‘ð :à  §¡Ð/ˆDŒMà}‰}Ðrc    ó~—dj|j«Dcgc]}dt|«z‘Œc}«Scc}w)z„Compute the *printable* MAC tag.
 
        This method is like `digest`.
 
        :Return: the MAC, as a hexadecimal string.
        Úz%02x)Újoinrr)r0Úxs  r6Ú    hexdigestzEaxMode.hexdigest
s0€ðw‰w°$·+±+³-Ö@¨Q˜¤ a£Ó(Ò@ÓAÐAùÒ@sž:cóô—d|jvr td«‚dg|_|jsZd|jz}t    d«D])}t ||j |j««}Œ+|d|j|_td«}tjd||j¬«}tjd||¬«}|j«|j«k7r td    «‚y)
a.Validate the *binary* MAC tag.
 
        The caller invokes this function at the very end.
 
        This method checks if the decrypted message is indeed valid
        (that is, if the key is correct) and it has not been
        tampered with while in transit.
 
        :Parameters:
          received_mac_tag : bytes/bytearray/memoryview
            This is the *binary* MAC, as received from the sender.
        :Raises MacMismatchError:
            if the MAC does not match. The message has been tampered with
            or the key is incorrect.
        rz3verify() cannot be called when encrypting a messagerrNéé )Ú digest_bitsr2ÚdatazMAC check failed) r$r'r#r!r(r    r,rr"rr r)r%)r0Úreceived_mac_tagrBr4ÚsecretÚmac1Úmac2s       r6rzEaxMode.verifysڀð" ˜4Ÿ:™:Ñ %Üð=ó>ð >àZˆŒ
à}Š}ؘDŸO™OÑ+ˆCܘ1“Xò :Ü˜S $§*¡*¨Q¡-×"6Ñ"6Ó"8Ó9‘ð :à  §¡Ð/ˆDŒMä! "Ó%ˆä{‰{ s°¸T¿]¹]ÔKˆÜ{‰{ s°Ð=MÔNˆà ;‰;‹=˜DŸK™K›MÒ )ÜÐ/Ó0Ð 0ð *rcó8—|jt|««y)a]Validate the *printable* MAC tag.
 
        This method is like `verify`.
 
        :Parameters:
          hex_mac_tag : string
            This is the *printable* MAC, as received from the sender.
        :Raises MacMismatchError:
            if the MAC does not match. The message has been tampered with
            or the key is incorrect.
        N)rr)r0Ú hex_mac_tags  r6Ú    hexverifyzEaxMode.hexverify7s€ð      ‰ ”I˜kÓ*Õ+rcóH—|j||¬«|j«fS)a\Perform encrypt() and digest() in one step.
 
        :Parameters:
          plaintext : bytes/bytearray/memoryview
            The piece of data to encrypt.
        :Keywords:
          output : bytearray/memoryview
            The location where the ciphertext must be written to.
            If ``None``, the ciphertext is returned.
        :Return:
            a tuple with two items:
 
            - the ciphertext, as ``bytes``
            - the MAC tag, as ``bytes``
 
            The first item becomes ``None`` when the ``output`` parameter
            specified a location for the result.
        r;)rr)r0r=r<s   r6Úencrypt_and_digestzEaxMode.encrypt_and_digestFs"€ð(|‰|˜I¨fˆ|Ó5°t·{±{³}ÐDÐDrcóN—|j||¬«}|j|«|S)aéPerform decrypt() and verify() in one step.
 
        :Parameters:
          ciphertext : bytes/bytearray/memoryview
            The piece of data to decrypt.
          received_mac_tag : bytes/bytearray/memoryview
            This is the *binary* MAC, as received from the sender.
        :Keywords:
          output : bytearray/memoryview
            The location where the plaintext must be written to.
            If ``None``, the plaintext is returned.
        :Return: the plaintext as ``bytes`` or ``None`` when the ``output``
            parameter specified a location for the result.
        :Raises MacMismatchError:
            if the MAC does not match. The message has been tampered with
            or the key is incorrect.
        r;)rr)r0r@rMr<Úpts     r6Údecrypt_and_verifyzEaxMode.decrypt_and_verify\s(€ð&\‰\˜*¨Vˆ\Ó 4ˆØ  ‰ Ð$Ô%؈    r)N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r7rrrrrGrrSrUrX©rr6rr3s?„ñò8-4ò^ó>*óX&?òPò0Bò"1òH ,óEô,rc ó
—    |jd«}|jdd«}|€ td«}|jd|j«}t |||||«S#t$r}t    dt |«z«‚d}~wwxYw)aYCreate a new block cipher, configured in EAX mode.
 
    :Parameters:
      factory : module
        A symmetric cipher module from `Crypto.Cipher` (like
        `Crypto.Cipher.AES`).
 
    :Keywords:
      key : bytes/bytearray/memoryview
        The secret key to use in the symmetric cipher.
 
      nonce : bytes/bytearray/memoryview
        A value that must never be reused for any other encryption.
        There are no restrictions on its length, but it is recommended to use
        at least 16 bytes.
 
        The nonce shall never repeat for two different messages encrypted with
        the same key, but it does not need to be random.
 
        If not specified, a 16 byte long random string is used.
 
      mac_len : integer
        Length of the MAC, in bytes. It must be no larger than the cipher
        block bytes (which is the default).
    r2r NrIr3zMissing parameter: )Úpoprr!ÚKeyErrorr'Ústrr)r1Úkwargsr2r r3Úes      r6Ú_create_eax_cipherrdts†€ð68؏j‰j˜ÓˆØ—
‘
˜7 DÓ)ˆØ ˆ=Ü$ RÓ(ˆEØ—*‘*˜Y¨×(:Ñ(:Ó;ˆô 7˜C ¨°Ó 8Ð8øô ò8ÜÐ-´°A³Ñ6Ó7Ð7ûð8ús‚A AÁ    BÁ&A=Á=B)r\Ú__all__r*ÚbinasciirÚCrypto.Util.py3compatrrrÚCrypto.Util._raw_apirÚCrypto.Util.strxorr    ÚCrypto.Util.numberr
r Ú Crypto.Hashr r Ú Crypto.RandomrÚobjectrrdr]rr6ú<module>rnsBðñ>ð ˆ+€ã Ýç@Ñ@å*å%ß;ç%Ý*ô~ˆfô~óB
$9r