Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster handshake #419

Merged
merged 10 commits into from
Sep 25, 2020
Merged

Faster handshake #419

merged 10 commits into from
Sep 25, 2020

Conversation

tomato42
Copy link
Member

@tomato42 tomato42 commented Sep 17, 2020

Optimise methods and functions used heavily in a handshake.

Speeds it up by about 25%

fixes #356


This change is Reviewable

@tomato42 tomato42 added the enhancement new feature to be implemented label Sep 17, 2020
@tomato42 tomato42 self-assigned this Sep 17, 2020
@lgtm-com

This comment has been minimized.

@lgtm-com

This comment has been minimized.

@lgtm-com

This comment has been minimized.

@lgtm-com

This comment has been minimized.

every time we call a HMAC_SHA256 it needs to create a new instance
and calculate the i_key and o_key, even if the key used is the same

use one instance of the HMAC and just copy state

also use multiple update calls, don't concatenate inputs
@lgtm-com

This comment has been minimized.

@lgtm-com

This comment has been minimized.

@lgtm-com
Copy link

lgtm-com bot commented Sep 24, 2020

This pull request fixes 2 alerts when merging 7098222 into e8da6cf - view on LGTM.com

fixed alerts:

  • 1 for Testing equality to None
  • 1 for Unreachable code

Jakuje
Jakuje previously approved these changes Sep 25, 2020
Copy link
Collaborator

@Jakuje Jakuje left a comment

Choose a reason for hiding this comment

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

just minor comments. Looks good otherwise

else:
def compat26Str(x): return x

def remove_whitespace(text):
"""Removes all whitespace from passed in string"""
return re.sub(r"\s+", "", text, flags=re.UNICODE)

def bit_length(val):
"""Return number of bytes necessary to represent an integer."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/bytes/bits/

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

def skip_bytes(self, length):
"""Move the internal pointer ahead length bytes."""
if self.index + length > len(self.bytes):
raise DecodeError("Read past end of buffer")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe different exception message like "Skipped past the end of buffer"?

Copy link
Member Author

Choose a reason for hiding this comment

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

this method is used only to get to the point we want to read, so while "skipped past..." would make more sense on the level of the Parser class, for the classes higher up the stack I think "Read past end of buffer" is more understandable

@lgtm-com
Copy link

lgtm-com bot commented Sep 25, 2020

This pull request fixes 2 alerts when merging a005589 into e8da6cf - view on LGTM.com

fixed alerts:

  • 1 for Testing equality to None
  • 1 for Unreachable code

@tomato42 tomato42 merged commit 9951ec1 into master Sep 25, 2020
@tomato42
Copy link
Member Author

thanks for the review!

@tomato42 tomato42 deleted the faster-prf branch September 25, 2020 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new feature to be implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use native hmac when possible
2 participants