MCPcopy Index your code
hub / github.com/PyMySQL/PyMySQL / scramble_caching_sha2

Function scramble_caching_sha2

pymysql/_auth.py:193–210  ·  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

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

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…