68 lines
1.8 KiB
Python
68 lines
1.8 KiB
Python
import ctypes
|
|
import pathlib
|
|
|
|
def fill():
|
|
ys = [1827, 4266, 7837]
|
|
share_array = []
|
|
for i in range(3):
|
|
share_array.append([i+1, ys[i]])
|
|
|
|
return share_array
|
|
|
|
def c_fill():
|
|
c_share_array = ((ctypes.c_longlong*2)*3)
|
|
share_array = []
|
|
ys = [182788, 4266752, 78378353]
|
|
for i in range(3):
|
|
c_share = (ctypes.c_longlong*2)(*[i+1, ys[i]])
|
|
share_array.append(c_share)
|
|
|
|
c_share_array = ((ctypes.c_longlong*2)*3)(*share_array)
|
|
|
|
return c_share_array
|
|
|
|
def gen_shares():
|
|
libname = pathlib.Path().absolute() / "libcppsss.so"
|
|
c_lib = ctypes.CDLL(libname)
|
|
|
|
c_share = ctypes.c_longlong*2
|
|
c_share_array = ((ctypes.c_longlong*2)*3)
|
|
c_share_array_pointer = ctypes.POINTER(c_share_array)
|
|
|
|
length = 2*3
|
|
c_share_array = (ctypes.c_long*length)
|
|
c_share_array_pointer = ctypes.POINTER(c_share_array)
|
|
c_string = ctypes.POINTER(ctypes.c_char)
|
|
|
|
c_lib.newSecretInternal.argtypes = [ctypes.c_longlong, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_char)]
|
|
c_lib.newSecretInternal.restypes = None
|
|
|
|
print("calculating...")
|
|
|
|
path = "shares/"
|
|
charptr = ctypes.c_char_p(path.encode('utf-8'))
|
|
c_lib.newSecretInternal(520, 5, 3, charptr)
|
|
|
|
def main():
|
|
share_array = fill()
|
|
print(share_array)
|
|
|
|
libname = pathlib.Path().absolute() / "libcppsss.so"
|
|
c_lib = ctypes.CDLL(libname)
|
|
|
|
c_share_array = ((ctypes.c_longlong*2)*3)
|
|
c_share_array_pointer = ctypes.POINTER(c_share_array)
|
|
|
|
c_lib.solveInternal.argtypes = [c_share_array_pointer, ctypes.c_int]
|
|
c_lib.solveInternal.restypes = int
|
|
|
|
#new_share_array = ctypes.pointer((c_share_array)(*share_array))
|
|
new_share_array = ctypes.pointer(c_fill())
|
|
print("calculating...")
|
|
result = c_lib.solveInternal(new_share_array, 3)
|
|
print(f"result: {result}")
|
|
|
|
if __name__ == "__main__":
|
|
gen_shares()
|
|
#main()
|