Scramble algorithm used in cached_sha2_password fast path. XOR(SHA256(password), SHA256(SHA256(SHA256(password)), nonce))
(password, nonce)
| 189 | |
| 190 | |
| 191 | def 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 | |
| 211 | def caching_sha2_password_auth(conn, pkt): |
no outgoing calls
no test coverage detected