1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
From: Justin Turner Arthur <justinarthur@gmail.com>
Date: Mon, 9 Apr 2018 03:20:00 -0500
Origin: https://github.com/dlitz/python-pbkdf2/pull/5/commits/d9b45bcedd4ce414bfb9403fda3e6868a791b717
Forwarded: no (PR in Github)
Subject: [PATCH] Use faster all-at-once xor on Python 3.2+.
---
pbkdf2.py | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/pbkdf2.py b/pbkdf2.py
index 937a99a..6adc96f 100644
--- a/pbkdf2.py
+++ b/pbkdf2.py
@@ -101,8 +101,16 @@ def callable(obj):
return hasattr(obj, '__call__')
def b(s):
return s.encode("latin-1")
- def binxor(a, b):
- return bytes([x ^ y for (x, y) in zip(a, b)])
+ if hasattr(int, 'to_bytes') and hasattr(int, 'from_bytes'):
+ _sys_byteorder = sys.byteorder
+ _b2i = int.from_bytes
+ def binxor(a, b):
+ a_int = _b2i(a, _sys_byteorder)
+ b_int = _b2i(b, _sys_byteorder)
+ return (a_int ^ b_int).to_bytes(len(a), _sys_byteorder)
+ else:
+ def binxor(a, b):
+ return bytes([x ^ y for (x, y) in zip(a, b)])
from base64 import b64encode as _b64encode
def b64encode(data, chars="+/"):
if isunicode(chars):
|