add monocypher module

This commit is contained in:
xenia 2021-06-14 05:14:43 -04:00
parent d064dd93d4
commit 325cd3126a
7 changed files with 80 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "leylines-monocypher/monocypher-git"]
path = leylines-monocypher/monocypher-git
url = https://github.com/LoupVaillant/Monocypher

11
leylines-monocypher/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
.venv
*.pyc
*.pyo
*.pyd
__pycache__
*.egg-info
.env
.vimrc
.ycm_extra_conf.py
/build
*.so

View File

@ -0,0 +1,9 @@
.PHONY: check install
check:
@mypy . || true
@flake8 . || true
@pyflakes . || true
install:
pip install --user -e .

@ -0,0 +1 @@
Subproject commit baca5d31259c598540e4d1284bc8d8f793abf83a

View File

@ -0,0 +1,25 @@
import ctypes
import pathlib
import secrets
_lib = ctypes.CDLL(pathlib.Path(__file__).parent / "ext.so")
# crypto_key_exchange
x25519_ty = ctypes.c_uint8 * 32
_lib.crypto_x25519_public_key.restype = None
_lib.crypto_x25519_public_key.argtypes = [x25519_ty, x25519_ty]
def crypto_key_exchange_make_key() -> bytes:
secret = bytearray(secrets.token_bytes(32))
secret[0] &= 248
secret[31] = (secret[31] & 127) | 64
return bytes(secret)
def crypto_key_exchange_public_key(secret: bytes) -> bytes:
public = x25519_ty()
_lib.crypto_x25519_public_key(public, x25519_ty(*secret))
return bytes(public)
# and.... that's all for now

View File

View File

@ -0,0 +1,31 @@
from setuptools import setup, Distribution, Extension
from setuptools.command.build_ext import build_ext as build_ext_orig
class CTypesExtension(Extension):
pass
class build_ext(build_ext_orig):
def get_export_symbols(self, ext):
return ext.export_symbols
def get_ext_filename(self, ext_name):
return ext_name.replace(".", "/") + '.so'
setup(name='leylines-monocypher',
version='0.1',
description='Sample text',
url='https://awoo.systems',
author='haskal',
author_email='haskal@awoo.systems',
license='AGPLv3',
packages=['monocypher'],
package_data={"monocypher": ["py.typed"]},
ext_modules=[
CTypesExtension("monocypher.ext",
include_dirs=["monocypher-git/src/"],
sources=["monocypher-git/src/monocypher.c",
"monocypher-git/src/optional/monocypher-ed25519.c"])
],
cmdclass={"build_ext": build_ext},
include_package_data=True,
zip_safe=False)