MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / scramble_caching_sha2

Function scramble_caching_sha2

pymysql/_auth.py:191–208  ·  view source on GitHub ↗

Scramble algorithm used in cached_sha2_password fast path. XOR(SHA256(password), SHA256(SHA256(SHA256(password)), nonce))

(password, nonce)

Source from the content-addressed store, hash-verified

189
190
191def scramble_caching_sha2(password, nonce):
192 # (bytes, bytes) -> bytes
193 """Scramble algorithm used in cached_sha2_password fast path.
194
195 XOR(SHA256(password), SHA256(SHA256(SHA256(password)), nonce))
196 """
197 if not password:
198 return b""
199
200 p1 = hashlib.sha256(password).digest()
201 p2 = hashlib.sha256(p1).digest()
202 p3 = hashlib.sha256(p2 + nonce).digest()
203
204 res = bytearray(p1)
205 for i in range(len(p3)):
206 res[i] ^= p3[i]
207
208 return bytes(res)
209
210
211def caching_sha2_password_auth(conn, pkt):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected