Page MenuHomePhabricator

Don't use "phutil_hashes_are_identical()" to compare public keys
ClosedPublic

Authored by epriestley on Oct 29 2019, 1:31 AM.
Tags
None
Referenced Files
F20272655: D20875.id49765.diff
Tue, Jun 9, 9:33 PM
F20271452: D20875.id49765.diff
Tue, Jun 9, 9:01 PM
F20270464: D20875.id49764.diff
Tue, Jun 9, 8:37 PM
F20268229: D20875.id49764.diff
Tue, Jun 9, 7:42 PM
Unknown Object (File)
Mon, Jun 8, 6:17 AM
Unknown Object (File)
Fri, Jun 5, 4:26 AM
Unknown Object (File)
Apr 21 2026, 10:27 PM
Unknown Object (File)
Apr 14 2026, 9:02 AM
Subscribers
Tokens
"Y So Serious" token, awarded by leoluk.

Details

Summary

Ref T13436. There's no real security value to doing this comparison, it just wards off evil "security researchers" who get upset if you ever compare two strings with a non-constant-time algorithm.

In practice, SSH public keys are pretty long, pretty public, and have pretty similar lengths. This leads to a relatively large amount of work to do constant-time comparisons on them (we frequently can't abort early after identifying differing string length).

Test Plan

Ran bin/ssh-auth --sshd-key ... on secure with ~1K keys, saw runtime drop by ~50% (~400ms to ~200ms) with ===.

Diff Detail

Repository
rP Phabricator
Lint
Lint Not Applicable
Unit
Tests Not Applicable