Skip to content

Commit

Permalink
Remove usage of old curves
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram van den Heuvel committed Jun 3, 2017
1 parent f7e9b8c commit ed5edfe
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 31 deletions.
16 changes: 2 additions & 14 deletions crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,17 @@ def security_levels(self):
return _CURVES.keys()

@attach_runtime_statistics(u"{0.__class__.__name__}.{function_name}")
def generate_key(self, security_level):
def generate_key(self, security_level=u"curve25519"):
"""
Generate a new Elliptic Curve object with a new public / private key pair.
Security can be u'low', u'medium', or u'high' depending on how secure you need your Elliptic
Curve to be. Currently these values translate into:
- very-low: NID_sect163k1 ~42 byte signatures
- low: NID_sect233k1 ~60 byte signatures
- medium: NID_sect409k1 ~104 byte signatures
- high: NID_sect571r1 ~144 byte signatures
Besides these predefined curves, all other curves provided by M2Crypto are also available. For
a full list of available curves, see ec_get_curves().
@param security_level: Level of security {u'very-low', u'low', u'medium', or u'high'}.
@param security_level: Level of security, currently only u"curve25519".
@type security_level: unicode
"""
assert isinstance(security_level, unicode)
assert security_level in _CURVES

curve = _CURVES[security_level]
if curve[1] == "M2Crypto":
return M2CryptoSK(curve[0])

if curve[1] == "libnacl":
return LibNaCLSK()
Expand Down
2 changes: 1 addition & 1 deletion tests/debugcommunity/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DebugNode(object):
node.init_my_member()
"""

def __init__(self, testclass, dispersy, communityclass=DebugCommunity, c_master_member=None, curve=u"low"):
def __init__(self, testclass, dispersy, communityclass=DebugCommunity, c_master_member=None, curve=u"curve25519"):
super(DebugNode, self).__init__()
self._logger = logging.getLogger(self.__class__.__name__)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def summary(self):
candidates = [Candidate(("130.161.211.245", 6429), False)]
communities = [PingCommunity.create_community(self._dispersy, self._my_member, candidates)
for _ in xrange(COMMUNITIES)]
members = [self._dispersy.get_new_member(u"low") for _ in xrange(MEMBERS)]
members = [self._dispersy.get_new_member(u"curve25519") for _ in xrange(MEMBERS)]

for community in communities:
for member in members:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def set_timestamps(self, candidates, all_flags):

def get_member():
if not member[0]:
member[0] = self._dispersy.get_new_member(u"very-low")
member[0] = self._dispersy.get_new_member(u"curve25519")
return member[0]

if "w" in flags:
Expand Down Expand Up @@ -557,7 +557,7 @@ def test_get_introduce_candidate(self, community_create_method=DebugCommunity.cr
now = time()
got = []
for candidate in candidates:
candidate.associate(self._dispersy.get_new_member(u"very-low"))
candidate.associate(self._dispersy.get_new_member(u"curve25519"))
candidate.stumble(now)
introduce = community.dispersy_get_introduce_candidate(candidate)
got.append(introduce.sock_addr if introduce else None)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
class TestMember(DispersyTestFunc):

def test_verify(self):
self._test_verify(u"medium")
self._test_verify(u"curve25519")

@call_on_reactor_thread
Expand Down Expand Up @@ -70,7 +69,6 @@ def _test_verify(self, curve):


def test_sign(self):
self._test_sign(u"medium")
self._test_sign(u"curve25519")

@call_on_reactor_thread
Expand Down
12 changes: 2 additions & 10 deletions tool/createkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,24 @@
"""
Create one or more Elliptic Curves.
Typically the following curves are used:
- very-low: NID_sect163k1 ~42 byte signatures
- low: NID_sect233k1 ~60 byte signatures
- medium: NID_sect409k1 ~104 byte signatures
- high: NID_sect571r1 ~144 byte signatures
Typically the Curve25519 is used.
"""

import argparse
import time
from hashlib import sha1

from M2Crypto import EC
# From: http://docs.python.org/2/tutorial/modules.html#intra-package-references
# Note that both explicit and implicit relative imports are based on the name of the current
# module. Since the name of the main module is always "__main__", modules intended for use as the
# main module of a Python application should always use absolute imports.
from dispersy.crypto import ECCrypto, _CURVES


def ec_name(eccrypto, curve):
assert isinstance(curve, unicode)
curve_id = _CURVES[curve]

for name in dir(EC):
value = getattr(EC, name)
if isinstance(value, int) and value == curve_id:
return name

def create_key(eccrypto, curves):
for index, curve in enumerate(curves):
Expand Down
2 changes: 1 addition & 1 deletion twisted/plugins/tracker_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def start(self):

def _create_my_member(self):
# generate a new my-member
ec = self.crypto.generate_key(u"very-low")
ec = self.crypto.generate_key()
self._my_member = self.get_member(private_key=self.crypto.key_to_bin(ec))

@property
Expand Down

0 comments on commit ed5edfe

Please sign in to comment.