nacl and bbs98

pull/15/head
Michael Egorov 2017-08-19 11:27:55 -07:00
parent e35ce6d366
commit 60c939a021
6 changed files with 41 additions and 2 deletions

30
nkms/crypto/__init__.py Normal file
View File

@ -0,0 +1,30 @@
import base64
import importlib
from nacl.utils import random # noqa
# hashMerkleRoot for Bitcoin genesis block
_bitcoin_genesis = base64.encodebytes(bytes.fromhex(
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b')).strip()
default_algorithm = dict(
symmetric=dict(
cipher='nacl'),
pre=dict(
cipher='bbs98',
curve=714, # secp256k1 in OpenSSL
g=b'1:' + _bitcoin_genesis,
m=None, n=None))
def symmetric_from_algorithm(algorithm):
module = importlib('nkms.crypto.block.' + algorithm['symmetric']['cipher'])
# TODO need to cache this
return module.Cipher
def pre_from_algorithm(algorithm):
kw = {k: v for k, v in algorithm['pre'].items()
if k != 'cipher' and v is not None}
module = importlib('nkms.crypto.block.' + algorithm['pre']['cipher'])
# TODO need to cache this
return module.PRE(**kw)

View File

View File

@ -0,0 +1,3 @@
from nacl.secret import SecretBox as Cipher # noqa
# NaCl interface is convenient enough by itself (see tests)

View File

3
nkms/crypto/pre/bbs98.py Normal file
View File

@ -0,0 +1,3 @@
from npre.bbs98 import PRE # noqa
# This is just to develop the interface, some more secure algos should be used

View File

@ -3,7 +3,9 @@ from distutils.core import setup
INSTALL_REQUIRES = [
'kademlia>=1.0',
'rpcudp>=3.0',
'ZODB>=5.0']
'ZODB>=5.0',
'pynacl',
'npre']
TESTS_REQUIRE = [
'pytest',
@ -16,7 +18,8 @@ TESTS_REQUIRE = [
# should add --process-dependency-links to pip
LINKS = [
'https://github.com/bmuller/kademlia/archive/python3.5.tar.gz#egg=kademlia-1.0',
'https://github.com/bmuller/rpcudp/archive/python3.5.tar.gz#egg=rpcudp-3.0.0']
'https://github.com/bmuller/rpcudp/archive/python3.5.tar.gz#egg=rpcudp-3.0.0',
'https://github.com/nucypher/nucypher-pre-python/archive/master.tar.gz#egg=npre-0.1']
setup(name='nkms',
version='0.1',