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