Skip to content

Use constant-time comparison for MAC and hash verification#27

Open
kodareef5 wants to merge 2 commits intontp-project:stablefrom
kodareef5:fix-mac-timing
Open

Use constant-time comparison for MAC and hash verification#27
kodareef5 wants to merge 2 commits intontp-project:stablefrom
kodareef5:fix-mac-timing

Conversation

@kodareef5
Copy link
Copy Markdown

Two locations use memcmp() for cryptographic verification:

  • sntp/crypto.c:181 — NTP packet MAC verification. The developer comment at line 177 acknowledges isc_tsmemcmp will be better when its easy to link with but the fix was never applied.

  • ntpd/ntp_leapsec.c:1144 — SHA1 digest comparison for leap second file integrity verification in the long-running ntpd daemon.

Replace both with constant-time XOR accumulation loops that examine all bytes regardless of match position.

Four sprintf calls write formatted GPS receiver data into a
1024-byte logbuf without bounds checking. The C1 format string
at line 1677 has 17 format specifiers including floating-point
values that can produce long output. Replace with snprintf
bounded by sizeof(logbuf).
Two locations use memcmp() for cryptographic verification:

- sntp/crypto.c:181: NTP packet MAC verification. The developer
  comment at line 177 acknowledges "isc_tsmemcmp will be better"
  but the fix was never applied.

- ntpd/ntp_leapsec.c:1144: SHA1 digest comparison for leap second
  file integrity in the long-running ntpd daemon.

Replace both with constant-time XOR accumulation loops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant