Last active
October 7, 2021 18:22
-
-
Save fionn/ee8669294912640a3931f8002f72e67e to your computer and use it in GitHub Desktop.
Dumb idea for intrinsic timing-attack-resistant Python object comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import hmac | |
class SecureObject(bytes): | |
"""Bytes that can be compared safely""" | |
def __eq__(self, other: object) -> bool: | |
return hmac.compare_digest(self, other) # type: ignore | |
def main() -> None: | |
"""Entry point""" | |
a = SecureObject([12, 33]) | |
b = SecureObject([12, 33]) | |
print(a == b) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment