GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-40791: Make compare_digest more constant-time. by ssbr · Pull Request #20444 · python/cpython

Conversation

@ssbr

@ssbr ssbr commented May 27, 2020 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The existing volatile left/right pointers guarantee that the reads will all occur, but does not guarantee that they will be used. So a compiler can still short-circuit the loop, saving e.g. the overhead of doing the xors and especially the overhead of the data dependency between result and the reads. That would change performance depending on where the first unequal byte occurs. This change removes that optimization.

(This is change 1 from https://bugs.python.org/issue40791 .)

https://bugs.python.org/issue40791

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label May 27, 2020
@bedevere-bot bedevere-bot added the awaiting review label May 27, 2020
@ssbr
bpo-40791: Make compare_digest more constant-time.
3423012
The existing volatile `left`/`right` pointers guarantee that the reads will all occur, but does not guarantee that they will be _used_. So a compiler can still short-circuit the loop, saving e.g. the overhead of doing the xors and especially the overhead of the data dependency between `result` and the reads. That would change performance depending on where the first unequal byte occurs. This change removes that optimization.

(This is change python#1 from https://bugs.python.org/issue40791 .)
@ssbr
ssbr force-pushed the patch-2 branch from 97f81e6 to 3423012 Compare May 27, 2020 13:55
gpshead
gpshead approved these changes May 27, 2020
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels May 27, 2020
@gpshead gpshead added needs backport to 3.7 type-bug An unexpected behavior, bug, or error type-security A security issue labels May 27, 2020
@gpshead

gpshead commented May 27, 2020

Copy link
Copy Markdown
Member

Can you add a NEWS entry (https://blurb-it.herokuapp.com/ can do it for you)?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gpshead gpshead self-assigned this May 27, 2020
tiran
tiran approved these changes May 27, 2020
View reviewed changes

@tiran tiran left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@blurb-it
📜🤖 Added by blurb_it.
f4c395e
@ssbr

ssbr commented May 28, 2020

Copy link
Copy Markdown
Contributor Author

OK, wasn't sure if this would deserve a news entry. Used the blurb tool -- really nice! Thanks for the recommendation. :)

(Feel free to tweak the exact wording of the news entry, committers should have edit access to my PR if I understand it right.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ned-deily

ned-deily commented Jun 16, 2020

Copy link
Copy Markdown
Member

@gpshead, @tiran ping! Any reason not to merge this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gpshead
gpshead merged commit 3172936 into python:master Nov 21, 2020
@miss-islington

miss-islington commented Nov 21, 2020

Copy link
Copy Markdown
Contributor

Thanks @ssbr for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8, 3.9.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label Nov 21, 2020
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 21, 2020
@ssbr @miss-islington
bpo-40791: Make compare_digest more constant-time. (pythonGH-20444)
0e4ccb3
* bpo-40791: Make compare_digest more constant-time.

The existing volatile `left`/`right` pointers guarantee that the reads will all occur, but does not guarantee that they will be _used_. So a compiler can still short-circuit the loop, saving e.g. the overhead of doing the xors and especially the overhead of the data dependency between `result` and the reads. That would change performance depending on where the first unequal byte occurs. This change removes that optimization.

(This is change GH-1 from https://bugs.python.org/issue40791 .)
(cherry picked from commit 3172936)

Co-authored-by: Devin Jeanpierre <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.9 label Nov 21, 2020
@bedevere-bot

bedevere-bot commented Nov 21, 2020

Copy link
Copy Markdown

GH-23436 is a backport of this pull request to the 3.9 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 21, 2020
@ssbr @miss-islington
bpo-40791: Make compare_digest more constant-time. (pythonGH-20444)
d823614
* bpo-40791: Make compare_digest more constant-time.

The existing volatile `left`/`right` pointers guarantee that the reads will all occur, but does not guarantee that they will be _used_. So a compiler can still short-circuit the loop, saving e.g. the overhead of doing the xors and especially the overhead of the data dependency between `result` and the reads. That would change performance depending on where the first unequal byte occurs. This change removes that optimization.

(This is change GH-1 from https://bugs.python.org/issue40791 .)
(cherry picked from commit 3172936)

Co-authored-by: Devin Jeanpierre <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.8 label Nov 21, 2020
@bedevere-bot

bedevere-bot commented Nov 21, 2020

Copy link
Copy Markdown

GH-23437 is a backport of this pull request to the 3.8 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Nov 21, 2020

Copy link
Copy Markdown

GH-23438 is a backport of this pull request to the 3.7 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.7 label Nov 21, 2020
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 21, 2020
@ssbr @miss-islington
bpo-40791: Make compare_digest more constant-time. (pythonGH-20444)
4229ad0
* bpo-40791: Make compare_digest more constant-time.

The existing volatile `left`/`right` pointers guarantee that the reads will all occur, but does not guarantee that they will be _used_. So a compiler can still short-circuit the loop, saving e.g. the overhead of doing the xors and especially the overhead of the data dependency between `result` and the reads. That would change performance depending on where the first unequal byte occurs. This change removes that optimization.

(This is change GH-1 from https://bugs.python.org/issue40791 .)
(cherry picked from commit 3172936)

Co-authored-by: Devin Jeanpierre <[email protected]>
miss-islington added a commit that referenced this pull request Nov 21, 2020
@miss-islington @ssbr
bpo-40791: Make compare_digest more constant-time. (GH-20444)
97136d7
* bpo-40791: Make compare_digest more constant-time.

The existing volatile `left`/`right` pointers guarantee that the reads will all occur, but does not guarantee that they will be _used_. So a compiler can still short-circuit the loop, saving e.g. the overhead of doing the xors and especially the overhead of the data dependency between `result` and the reads. That would change performance depending on where the first unequal byte occurs. This change removes that optimization.

(This is change GH-1 from https://bugs.python.org/issue40791 .)
(cherry picked from commit 3172936)

Co-authored-by: Devin Jeanpierre <[email protected]>
miss-islington added a commit that referenced this pull request Nov 21, 2020
@miss-islington @ssbr
bpo-40791: Make compare_digest more constant-time. (GH-20444)
c1bbca5
* bpo-40791: Make compare_digest more constant-time.

The existing volatile `left`/`right` pointers guarantee that the reads will all occur, but does not guarantee that they will be _used_. So a compiler can still short-circuit the loop, saving e.g. the overhead of doing the xors and especially the overhead of the data dependency between `result` and the reads. That would change performance depending on where the first unequal byte occurs. This change removes that optimization.

(This is change GH-1 from https://bugs.python.org/issue40791 .)
(cherry picked from commit 3172936)

Co-authored-by: Devin Jeanpierre <[email protected]>
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
@ssbr @adorilson
bpo-40791: Make compare_digest more constant-time. (pythonGH-20444)
d5c3448
* bpo-40791: Make compare_digest more constant-time.

The existing volatile `left`/`right` pointers guarantee that the reads will all occur, but does not guarantee that they will be _used_. So a compiler can still short-circuit the loop, saving e.g. the overhead of doing the xors and especially the overhead of the data dependency between `result` and the reads. That would change performance depending on where the first unequal byte occurs. This change removes that optimization.

(This is change #1 from https://bugs.python.org/issue40791 .)
@ssbr ssbr mannequin mentioned this pull request Aug 24, 2023
hmac.compare_digest could try harder to be constant-time. #84968
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gpshead gpshead gpshead approved these changes
+1 more reviewer
@tiran tiran tiran approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gpshead gpshead

Labels

type-bug An unexpected behavior, bug, or error type-security A security issue

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@ssbr @gpshead @ned-deily @miss-islington @bedevere-bot @tiran @the-knights-who-say-ni
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.