From 0636730b9ecdabbfd4b6012953c0e321bdbaf45f Mon Sep 17 00:00:00 2001 From: Andrew Miller Date: Thu, 23 May 2019 23:30:37 -0500 Subject: [PATCH] renames ntl files to be more systematic --- honeybadgermpc/ntl/__init__.py | 1 + .../ntl/{objectwrapper.pxd => ccobject.pxd} | 2 +- .../ntl/{ccobject.h => ccobject_impl.h} | 0 .../ntl/{helpers.pyx => hbmpc_ntl_helpers.pyx} | 15 +++++++++------ honeybadgermpc/ntl/{ctypes.pxd => ntlwrapper.pxd} | 2 +- .../ntl/{ntlwrapper.h => ntlwrapper_impl.h} | 0 honeybadgermpc/ntl/{helpers.pxd => rsdecode.pxd} | 2 +- honeybadgermpc/polynomial.py | 4 ++-- honeybadgermpc/preprocessing.py | 2 +- honeybadgermpc/progs/triple_refinement.py | 4 ++-- honeybadgermpc/reed_solomon.py | 6 +++--- setup.py | 4 ++-- tests/test_ntl.py | 2 +- tests/test_reed_solomon.py | 2 +- 14 files changed, 25 insertions(+), 21 deletions(-) rename honeybadgermpc/ntl/{objectwrapper.pxd => ccobject.pxd} (85%) rename honeybadgermpc/ntl/{ccobject.h => ccobject_impl.h} (100%) rename honeybadgermpc/ntl/{helpers.pyx => hbmpc_ntl_helpers.pyx} (95%) rename honeybadgermpc/ntl/{ctypes.pxd => ntlwrapper.pxd} (97%) rename honeybadgermpc/ntl/{ntlwrapper.h => ntlwrapper_impl.h} (100%) rename honeybadgermpc/ntl/{helpers.pxd => rsdecode.pxd} (97%) diff --git a/honeybadgermpc/ntl/__init__.py b/honeybadgermpc/ntl/__init__.py index e69de29b..fd6faef9 100644 --- a/honeybadgermpc/ntl/__init__.py +++ b/honeybadgermpc/ntl/__init__.py @@ -0,0 +1 @@ +from ._hbmpc_ntl_helpers import * # noqa F403, F401 diff --git a/honeybadgermpc/ntl/objectwrapper.pxd b/honeybadgermpc/ntl/ccobject.pxd similarity index 85% rename from honeybadgermpc/ntl/objectwrapper.pxd rename to honeybadgermpc/ntl/ccobject.pxd index 67ef3550..5646f8d7 100644 --- a/honeybadgermpc/ntl/objectwrapper.pxd +++ b/honeybadgermpc/ntl/ccobject.pxd @@ -1,5 +1,5 @@ # Code ot help help python objects to C++ objects -cdef extern from "ccobject.h": +cdef extern from "ccobject_impl.h": # Print representation of any C++ object str ccrepr[T](T x) diff --git a/honeybadgermpc/ntl/ccobject.h b/honeybadgermpc/ntl/ccobject_impl.h similarity index 100% rename from honeybadgermpc/ntl/ccobject.h rename to honeybadgermpc/ntl/ccobject_impl.h diff --git a/honeybadgermpc/ntl/helpers.pyx b/honeybadgermpc/ntl/hbmpc_ntl_helpers.pyx similarity index 95% rename from honeybadgermpc/ntl/helpers.pyx rename to honeybadgermpc/ntl/hbmpc_ntl_helpers.pyx index b4d2105c..0944eb55 100644 --- a/honeybadgermpc/ntl/helpers.pyx +++ b/honeybadgermpc/ntl/hbmpc_ntl_helpers.pyx @@ -3,17 +3,20 @@ # The data validation and checking must be done in python in all cases! # PEP8 standards are observed wherever possible but ignored in cases whether NTL # classes are used (like ZZ, mat_ZZ_p, etc) and also for NTL function names -from .ctypes cimport ZZ, ZZ_p, mat_ZZ_p, vec_ZZ_p, ZZ_pX_c -from .ctypes cimport mat_ZZ_p_mul -from .ctypes cimport ZZFromBytes, bytesFromZZ, to_ZZ_p, to_ZZ, ZZNumBytes -from .objectwrapper cimport ccrepr, ccreadstr -from .ctypes cimport SetNTLNumThreads_c, AvailableThreads, ZZ_p_init, ZZ_pX_get_coeff, \ - ZZ_pX_set_coeff, ZZ_pX_eval, SqrRootMod +from .ntlwrapper cimport ZZ, ZZ_p, mat_ZZ_p, vec_ZZ_p, ZZ_pX_c +from .ntlwrapper cimport mat_ZZ_p_mul, ZZ_p_init, SqrRootMod +from .ntlwrapper cimport ZZFromBytes, bytesFromZZ, to_ZZ_p, to_ZZ, ZZNumBytes +from .ntlwrapper cimport SetNTLNumThreads_c, AvailableThreads +from .ntlwrapper cimport ZZ_pX_get_coeff, ZZ_pX_set_coeff, ZZ_pX_eval +from .rsdecode cimport interpolate_c, vandermonde_inverse_c, set_vm_matrix_c, fft_c, fft_partial_c, fnt_decode_step1_c, fnt_decode_step2_c, gao_interpolate_c, gao_interpolate_fft_c +from .ccobject cimport ccrepr, ccreadstr from cpython.int cimport PyInt_AS_LONG from cython.parallel import parallel, prange from libc.stdlib cimport free +from libcpp.vector cimport vector cimport openmp + cdef ZZ intToZZ(x): num = (x.bit_length() + 7) // 8 return ZZFromBytes(x.to_bytes(num, 'little'), num) diff --git a/honeybadgermpc/ntl/ctypes.pxd b/honeybadgermpc/ntl/ntlwrapper.pxd similarity index 97% rename from honeybadgermpc/ntl/ctypes.pxd rename to honeybadgermpc/ntl/ntlwrapper.pxd index cec7762f..4668714f 100644 --- a/honeybadgermpc/ntl/ctypes.pxd +++ b/honeybadgermpc/ntl/ntlwrapper.pxd @@ -1,6 +1,6 @@ from libcpp.vector cimport vector -cdef extern from "ntlwrapper.h": +cdef extern from "ntlwrapper_impl.h": cdef cppclass ZZ "ZZ": ZZ() except + pass diff --git a/honeybadgermpc/ntl/ntlwrapper.h b/honeybadgermpc/ntl/ntlwrapper_impl.h similarity index 100% rename from honeybadgermpc/ntl/ntlwrapper.h rename to honeybadgermpc/ntl/ntlwrapper_impl.h diff --git a/honeybadgermpc/ntl/helpers.pxd b/honeybadgermpc/ntl/rsdecode.pxd similarity index 97% rename from honeybadgermpc/ntl/helpers.pxd rename to honeybadgermpc/ntl/rsdecode.pxd index 4242dc82..53261d48 100644 --- a/honeybadgermpc/ntl/helpers.pxd +++ b/honeybadgermpc/ntl/rsdecode.pxd @@ -1,4 +1,4 @@ -from .ctypes cimport ZZ, mat_ZZ_p, vec_ZZ_p, ZZ_p, ZZ_pX_c +from .ntlwrapper cimport ZZ, mat_ZZ_p, vec_ZZ_p, ZZ_p, ZZ_pX_c from libcpp.vector cimport vector from libcpp cimport bool diff --git a/honeybadgermpc/polynomial.py b/honeybadgermpc/polynomial.py index e98a5b7b..c8ddc541 100644 --- a/honeybadgermpc/polynomial.py +++ b/honeybadgermpc/polynomial.py @@ -3,8 +3,8 @@ from functools import reduce from itertools import zip_longest -from honeybadgermpc.ntl.helpers import fft as fft_cpp -from honeybadgermpc.ntl.helpers import fft_interpolate as fft_interpolate_cpp +from honeybadgermpc.ntl import fft as fft_cpp +from honeybadgermpc.ntl import fft_interpolate as fft_interpolate_cpp from .betterpairing import ZR from .elliptic_curve import Subgroup diff --git a/honeybadgermpc/preprocessing.py b/honeybadgermpc/preprocessing.py index b4a4e147..9c8ee5c9 100644 --- a/honeybadgermpc/preprocessing.py +++ b/honeybadgermpc/preprocessing.py @@ -6,7 +6,7 @@ from os import makedirs from .field import GF from .polynomial import polynomials_over -from .ntl.helpers import vandermonde_batch_evaluate +from .ntl import vandermonde_batch_evaluate from .elliptic_curve import Subgroup diff --git a/honeybadgermpc/progs/triple_refinement.py b/honeybadgermpc/progs/triple_refinement.py index 07cc2eb1..b3ce9529 100644 --- a/honeybadgermpc/progs/triple_refinement.py +++ b/honeybadgermpc/progs/triple_refinement.py @@ -1,6 +1,6 @@ import asyncio -from honeybadgermpc.ntl.helpers import vandermonde_batch_evaluate -from honeybadgermpc.ntl.helpers import vandermonde_batch_interpolate +from honeybadgermpc.ntl import vandermonde_batch_evaluate +from honeybadgermpc.ntl import vandermonde_batch_interpolate async def batch_beaver(context, a_, b_, x_, y_, z_): diff --git a/honeybadgermpc/reed_solomon.py b/honeybadgermpc/reed_solomon.py index 323d6d02..6a178818 100644 --- a/honeybadgermpc/reed_solomon.py +++ b/honeybadgermpc/reed_solomon.py @@ -1,7 +1,7 @@ -from honeybadgermpc.ntl.helpers import vandermonde_batch_evaluate, \ +from honeybadgermpc.ntl import vandermonde_batch_evaluate, \ vandermonde_batch_interpolate -from honeybadgermpc.ntl.helpers import gao_interpolate -from honeybadgermpc.ntl.helpers import fft, fft_interpolate, fft_batch_interpolate, \ +from honeybadgermpc.ntl import gao_interpolate +from honeybadgermpc.ntl import fft, fft_interpolate, fft_batch_interpolate, \ fft_batch_evaluate, SetNumThreads, AvailableNTLThreads from honeybadgermpc.reed_solomon_wb import make_wb_encoder_decoder from honeybadgermpc.exceptions import HoneyBadgerMPCError diff --git a/setup.py b/setup.py index ba3bcf5e..e4496008 100644 --- a/setup.py +++ b/setup.py @@ -84,8 +84,8 @@ extensions = [ Extension( - name="honeybadgermpc.ntl.helpers", - sources=["honeybadgermpc/ntl/helpers.pyx"], + name="honeybadgermpc.ntl._hbmpc_ntl_helpers", + sources=["honeybadgermpc/ntl/hbmpc_ntl_helpers.pyx"], language="c++", extra_compile_args=extra_compile_args, extra_link_args=extra_link_args diff --git a/tests/test_ntl.py b/tests/test_ntl.py index 598d9f05..3bb4ceb4 100644 --- a/tests/test_ntl.py +++ b/tests/test_ntl.py @@ -1,4 +1,4 @@ -from honeybadgermpc.ntl.helpers import lagrange_interpolate, \ +from honeybadgermpc.ntl import lagrange_interpolate, \ vandermonde_batch_interpolate, vandermonde_batch_evaluate, \ fft, fft_interpolate, fft_batch_interpolate, \ gao_interpolate, evaluate, sqrt_mod, partial_fft, fft_batch_evaluate diff --git a/tests/test_reed_solomon.py b/tests/test_reed_solomon.py index 95707142..595e52af 100644 --- a/tests/test_reed_solomon.py +++ b/tests/test_reed_solomon.py @@ -4,7 +4,7 @@ from honeybadgermpc.polynomial import EvalPoint from honeybadgermpc.reed_solomon import EncoderFactory, DecoderFactory from honeybadgermpc.reed_solomon import EncoderSelector, DecoderSelector -from honeybadgermpc.ntl.helpers import AvailableNTLThreads +from honeybadgermpc.ntl import AvailableNTLThreads from unittest.mock import patch