Skip to content

Commit

Permalink
use "hkdf" from PyPI instead of wormhole.hkdf
Browse files Browse the repository at this point in the history
  • Loading branch information
warner committed Apr 18, 2016
1 parent 0edb64b commit 3b215c1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 189 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"wormhole-server = wormhole_server.runner:entry",
]},
install_requires=["spake2==0.3", "pynacl", "requests", "argparse",
"six", "twisted >= 16.1.0"],
"six", "twisted >= 16.1.0", "hkdf"],
extras_require={"tor": ["txtorcon", "ipaddr"]},
test_suite="wormhole.test",
cmdclass=commands,
Expand Down
5 changes: 4 additions & 1 deletion src/txwormhole/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
from wormhole import codes
from wormhole.errors import ServerError, Timeout, WrongPasswordError, UsageError
from wormhole.timing import DebugTiming
from wormhole.hkdf import HKDF
from hkdf import Hkdf
from wormhole.channel_monitor import monitor

def HKDF(skm, outlen, salt=None, CTXinfo=b""):
return Hkdf(salt, skm).expand(CTXinfo, outlen)

CONFMSG_NONCE_LENGTH = 128//8
CONFMSG_MAC_LENGTH = 256//8
def make_confmsg(confkey, nonce):
Expand Down
5 changes: 4 additions & 1 deletion src/txwormhole/transit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.protocols import policies
from nacl.secret import SecretBox
from wormhole.hkdf import HKDF
from hkdf import Hkdf
from wormhole.errors import UsageError
from wormhole.timing import DebugTiming
from . import ipaddrs

def HKDF(skm, outlen, salt=None, CTXinfo=b""):
return Hkdf(salt, skm).expand(CTXinfo, outlen)

def debug(msg):
if False:
print(msg)
Expand Down
5 changes: 4 additions & 1 deletion src/wormhole/blocking/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
from .. import codes
from ..errors import ServerError, Timeout, WrongPasswordError, UsageError
from ..timing import DebugTiming
from ..hkdf import HKDF
from hkdf import Hkdf
from ..channel_monitor import monitor

def HKDF(skm, outlen, salt=None, CTXinfo=b""):
return Hkdf(salt, skm).expand(CTXinfo, outlen)

SECOND = 1
MINUTE = 60*SECOND

Expand Down
161 changes: 0 additions & 161 deletions src/wormhole/hkdf.py

This file was deleted.

41 changes: 17 additions & 24 deletions tests/test_hkdf.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
from __future__ import print_function
import unittest
from binascii import hexlify, unhexlify
from wormhole.hkdf import HKDF
#from hkdf import Hkdf
from binascii import unhexlify #, hexlify
from hkdf import Hkdf

def generate_KAT():
print("KAT = [")
for salt in (None, b"", b"salt"):
for context in (b"", b"context"):
skm = b"secret"
out = HKDF(skm, 64, XTS=salt, CTXinfo=context)
hexout = " '%s' +\n '%s'" % (hexlify(out[:32]),
hexlify(out[32:]))
print(" (%r, %r, %r,\n%s)," % (salt, context, skm, hexout))
print("]")
#def generate_KAT():
# print("KAT = [")
# for salt in (b"", b"salt"):
# for context in (b"", b"context"):
# skm = b"secret"
# out = HKDF(skm, 64, XTS=salt, CTXinfo=context)
# hexout = " '%s' +\n '%s'" % (hexlify(out[:32]),
# hexlify(out[32:]))
# print(" (%r, %r, %r,\n%s)," % (salt, context, skm, hexout))
# print("]")

KAT = [
(None, '', 'secret',
'2f34e5ff91ec85d53ca9b543683174d0cf550b60d5f52b24c97b386cfcf6cbbf' +
'9cfd42fd37e1e5a214d15f03058d7fee63dc28f564b7b9fe3da514f80daad4bf'),
(None, 'context', 'secret',
'c24c303a1adfb4c3e2b092e6254ed481c41d8955ba8ec3f6a1473493a60c957b' +
'31b723018ca75557214d3d5c61c0c7a5315b103b21ff00cb03ebe023dc347a47'),
('', '', 'secret',
'2f34e5ff91ec85d53ca9b543683174d0cf550b60d5f52b24c97b386cfcf6cbbf' +
'9cfd42fd37e1e5a214d15f03058d7fee63dc28f564b7b9fe3da514f80daad4bf'),
Expand All @@ -42,11 +35,11 @@ def test_kat(self):
for (salt, context, skm, expected_hexout) in KAT:
expected_out = unhexlify(expected_hexout)
for outlen in range(0, len(expected_out)):
out = HKDF(skm, outlen, XTS=salt, CTXinfo=context)
out = Hkdf(salt.encode("ascii"),
skm.encode("ascii")).expand(context.encode("ascii"),
outlen)
self.assertEqual(out, expected_out[:outlen])
#out = Hkdf(salt, skm).expand(context, outlen)
#self.assertEqual(out, expected_out[:outlen])

if __name__ == '__main__':
generate_KAT()
#if __name__ == '__main__':
# generate_KAT()

0 comments on commit 3b215c1

Please sign in to comment.