Skip to content
This repository was archived by the owner on Jun 9, 2022. It is now read-only.

Commit fd01168

Browse files
committed
Remove H().
1 parent d1efd26 commit fd01168

5 files changed

Lines changed: 13 additions & 33 deletions

File tree

NEWS

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
* Version 3.0.0 (unreleased)
2-
** Added support for Python 3.3+
3-
** utils.rand_bytes() now sources bytes from os.urandom()
2+
** Added support for Python 3.3+.
3+
** utils.rand_bytes() now sources bytes from os.urandom().
44
** utils.websafe_encode() now returns text strings (unicode() on Python 2.x,
5-
str() on Python 3.x)
5+
str() on Python 3.x).
6+
** utils.H() has been removed (just use hashlib.sha256() directly instead).
67
** soft.SoftU2FDevice() now stores keys, key handles and app params as text
7-
strings
8-
9-
* Version 2.3.0 (unreleased)
8+
strings.
109
** Replace M2Crypto with Cryptography.
1110

1211
* Version 2.2.1 (released 2015-09-08)

test/test_utils.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from u2flib_host.utils import (
66
u2str,
77
websafe_encode,
8-
websafe_decode,
9-
H,
8+
websafe_decode
109
)
1110

1211

@@ -56,14 +55,3 @@ def test_websafe_encode(self):
5655
def test_websafe_encode_unicode(self):
5756
self.assertEqual(websafe_encode(u''), u'')
5857
self.assertEqual(websafe_encode(u'foobar'), u'Zm9vYmFy')
59-
60-
61-
class TestH(unittest.TestCase):
62-
# SHA-256 vectors adapted from http://www.nsrl.nist.gov/testdata/
63-
64-
def test_H(self):
65-
self.assertEqual(H(b'abc'),
66-
b'\xbax\x16\xbf\x8f\x01\xcf\xeaAA@\xde]\xae"#\xb0'
67-
b'\x03a\xa3\x96\x17z\x9c\xb4\x10\xffa\xf2\x00\x15\xad'
68-
)
69-

u2flib_host/soft.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
print("The soft U2F token requires cryptography.")
3636
raise
3737

38-
from u2flib_host.utils import H
3938
from u2flib_host.device import U2FDevice
4039
from u2flib_host.constants import INS_ENROLL, INS_SIGN
4140
from u2flib_host.yubicommon.compat import byte2int, int2byte

u2flib_host/u2f_v2.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
# POSSIBILITY OF SUCH DAMAGE.
2727

2828
from u2flib_host.constants import INS_ENROLL, INS_SIGN
29-
from u2flib_host.utils import websafe_decode, websafe_encode, H
29+
from u2flib_host.utils import websafe_decode, websafe_encode
3030
from u2flib_host.appid import verify_facet
3131
from u2flib_host.yubicommon.compat import string_types
3232

33+
from hashlib import sha256
3334
import json
3435

3536
VERSION = 'U2F_V2'
@@ -55,15 +56,15 @@ def register(device, data, facet):
5556

5657
app_id = data.get('appId', facet)
5758
verify_facet(app_id, facet)
58-
app_param = H(app_id)
59+
app_param = sha256(app_id).digest()
5960

6061
client_data = {
6162
'typ': 'navigator.id.finishEnrollment',
6263
'challenge': data['challenge'],
6364
'origin': facet
6465
}
6566
client_data = json.dumps(client_data)
66-
client_param = H(client_data)
67+
client_param = sha256(client_data).digest()
6768

6869
request = client_param + app_param
6970

@@ -98,7 +99,7 @@ def authenticate(device, data, facet, check_only=False):
9899

99100
app_id = data.get('appId', facet)
100101
verify_facet(app_id, facet)
101-
app_param = H(app_id)
102+
app_param = sha256(app_id).digest()
102103

103104
key_handle = websafe_decode(data['keyHandle'])
104105

@@ -109,7 +110,7 @@ def authenticate(device, data, facet, check_only=False):
109110
'origin': facet
110111
}
111112
client_data = json.dumps(client_data)
112-
client_param = H(client_data)
113+
client_param = sha256(client_data).digest()
113114

114115
request = client_param + app_param + chr(
115116
len(key_handle)) + key_handle

u2flib_host/utils.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
__all__ = [
3434
'u2str',
3535
'websafe_encode',
36-
'websafe_decode',
37-
'H'
36+
'websafe_decode'
3837
]
3938

4039

@@ -61,9 +60,3 @@ def websafe_encode(data):
6160
if isinstance(data, text_type):
6261
data = data.encode('ascii')
6362
return urlsafe_b64encode(data).replace(b'=', b'').decode('ascii')
64-
65-
66-
def H(data):
67-
f = sha256()
68-
f.update(data)
69-
return f.digest()

0 commit comments

Comments
 (0)