t-encrypt 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- t_encrypt-0.0.1/MANIFEST.in +1 -0
- t_encrypt-0.0.1/PKG-INFO +12 -0
- t_encrypt-0.0.1/setup.cfg +4 -0
- t_encrypt-0.0.1/setup.py +35 -0
- t_encrypt-0.0.1/setup_t_encrypt.py +60 -0
- t_encrypt-0.0.1/t_encrypt/__init__.py +15 -0
- t_encrypt-0.0.1/t_encrypt/core.py +154 -0
- t_encrypt-0.0.1/t_encrypt/exceptions.py +11 -0
- t_encrypt-0.0.1/t_encrypt.egg-info/PKG-INFO +12 -0
- t_encrypt-0.0.1/t_encrypt.egg-info/SOURCES.txt +10 -0
- t_encrypt-0.0.1/t_encrypt.egg-info/dependency_links.txt +1 -0
- t_encrypt-0.0.1/t_encrypt.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
recursive-include t_encrypt *.so
|
t_encrypt-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: t-encrypt
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python bindings for SKALE Threshold Encryption
|
|
5
|
+
Author: SKALE Network
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Dynamic: author
|
|
10
|
+
Dynamic: classifier
|
|
11
|
+
Dynamic: requires-python
|
|
12
|
+
Dynamic: summary
|
t_encrypt-0.0.1/setup.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
from distutils.core import setup, Extension
|
|
6
|
+
|
|
7
|
+
strCompilerCommonFlagsSuffix = " -fpermissive -fPIC -std=c++11 -Wno-error=parentheses -Wno-error=char-subscripts"
|
|
8
|
+
os.environ["CC"] = "gcc-7" + strCompilerCommonFlagsSuffix
|
|
9
|
+
os.environ["CXX"] = "g++-7" + strCompilerCommonFlagsSuffix
|
|
10
|
+
os.environ["LD"] = "ld" + strCompilerCommonFlagsSuffix
|
|
11
|
+
|
|
12
|
+
extras_require = {
|
|
13
|
+
"codecov==2.1.11"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
dkgpython_module = Extension('dkgpython',
|
|
17
|
+
sources=['dkgpython.cpp'],
|
|
18
|
+
include_dirs=['..', '../bls', '../dkg', '../third_party', '../deps/',
|
|
19
|
+
'../deps/deps_inst/x86_or_x64/include',
|
|
20
|
+
'../deps/deps_inst/x86_or_x64/include/libff'],
|
|
21
|
+
|
|
22
|
+
library_dirs=['../build', '../deps/deps_inst/x86_or_x64/lib',
|
|
23
|
+
'../deps/deps_inst/x86_or_x64/lib/libff',
|
|
24
|
+
'../deps/deps_inst/x86_or_x64/lib/libgmp',
|
|
25
|
+
'../deps/deps_inst/x86_or_x64/lib/libgmpxx'],
|
|
26
|
+
|
|
27
|
+
libraries=['bls', 'ff', 'gmpxx', 'gmp']
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
setup(name='dkgpython',
|
|
31
|
+
version='0.1.0',
|
|
32
|
+
description='dkgpython module written in C++',
|
|
33
|
+
ext_modules=[dkgpython_module],
|
|
34
|
+
extras_require=extras_require
|
|
35
|
+
)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Setup script for the SKALE Threshold Encryption Python package.
|
|
3
|
+
"""
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
from setuptools import setup, find_packages
|
|
7
|
+
from setuptools.command.build_py import build_py
|
|
8
|
+
|
|
9
|
+
# Configuration
|
|
10
|
+
PACKAGE_NAME = 't_encrypt'
|
|
11
|
+
LIB_NAME = 'libencrypt.so'
|
|
12
|
+
BUILD_TARGET_NAME = 'libt_encrypt_python.so'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def resolve_built_library_path() -> str:
|
|
16
|
+
override_path = os.environ.get('T_ENCRYPT_LIB_PATH')
|
|
17
|
+
if override_path:
|
|
18
|
+
if not os.path.exists(override_path):
|
|
19
|
+
raise FileNotFoundError(
|
|
20
|
+
f"T_ENCRYPT_LIB_PATH points to missing file: {override_path}"
|
|
21
|
+
)
|
|
22
|
+
return override_path
|
|
23
|
+
else:
|
|
24
|
+
raise RuntimeError(
|
|
25
|
+
"Environment variable T_ENCRYPT_LIB_PATH is not set. ")
|
|
26
|
+
|
|
27
|
+
class CustomBuildPy(build_py):
|
|
28
|
+
"""
|
|
29
|
+
Custom build command to copy the shared library into the package directory.
|
|
30
|
+
"""
|
|
31
|
+
def run(self):
|
|
32
|
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
33
|
+
found_lib = resolve_built_library_path()
|
|
34
|
+
|
|
35
|
+
target_path = os.path.join(current_dir, PACKAGE_NAME, LIB_NAME)
|
|
36
|
+
|
|
37
|
+
shutil.copy2(found_lib, target_path)
|
|
38
|
+
os.chmod(target_path, 0o755)
|
|
39
|
+
|
|
40
|
+
super().run()
|
|
41
|
+
|
|
42
|
+
setup(
|
|
43
|
+
name='t-encrypt',
|
|
44
|
+
version='0.0.1',
|
|
45
|
+
description='Python bindings for SKALE Threshold Encryption',
|
|
46
|
+
author='SKALE Network',
|
|
47
|
+
packages=find_packages(),
|
|
48
|
+
include_package_data=True,
|
|
49
|
+
package_data={
|
|
50
|
+
't_encrypt': ['*.so'],
|
|
51
|
+
},
|
|
52
|
+
cmdclass={
|
|
53
|
+
'build_py': CustomBuildPy,
|
|
54
|
+
},
|
|
55
|
+
classifiers=[
|
|
56
|
+
'Programming Language :: Python :: 3',
|
|
57
|
+
'Operating System :: POSIX :: Linux',
|
|
58
|
+
],
|
|
59
|
+
python_requires='>=3.11',
|
|
60
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides a Python interface to the t-encrypt C++ library.
|
|
3
|
+
It allows encrypting messages using BLS keys.
|
|
4
|
+
"""
|
|
5
|
+
from .core import encrypt_message, encrypt_message_dual_key, encrypt_message_mockup
|
|
6
|
+
from .exceptions import TEncryptError, LibraryNotFoundError, EncryptionError
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
'encrypt_message',
|
|
10
|
+
'encrypt_message_dual_key',
|
|
11
|
+
'encrypt_message_mockup',
|
|
12
|
+
'TEncryptError',
|
|
13
|
+
'LibraryNotFoundError',
|
|
14
|
+
'EncryptionError',
|
|
15
|
+
]
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Core implementation of SKALE Threshold Encryption interface.
|
|
3
|
+
"""
|
|
4
|
+
import ctypes
|
|
5
|
+
import os
|
|
6
|
+
from ctypes import c_char_p
|
|
7
|
+
|
|
8
|
+
from .exceptions import EncryptionError, LibraryNotFoundError
|
|
9
|
+
|
|
10
|
+
def _load_library():
|
|
11
|
+
"""Finds and loads the shared library, setting up function signatures."""
|
|
12
|
+
# The library is expected to be in the same directory as this file
|
|
13
|
+
lib_path = os.path.join(os.path.dirname(__file__), 'libencrypt.so')
|
|
14
|
+
|
|
15
|
+
if not os.path.exists(lib_path):
|
|
16
|
+
# Fallback for development/testing if not explicitly installed
|
|
17
|
+
# Check if we can find it in common build locations relative to this file
|
|
18
|
+
current_dir = os.path.dirname(__file__)
|
|
19
|
+
possible_paths = [
|
|
20
|
+
os.path.abspath(os.path.join(current_dir, '../../build/threshold_encryption/libt_encrypt_python.so')),
|
|
21
|
+
]
|
|
22
|
+
for path in possible_paths:
|
|
23
|
+
if os.path.exists(path):
|
|
24
|
+
lib_path = path
|
|
25
|
+
break
|
|
26
|
+
|
|
27
|
+
if not os.path.exists(lib_path):
|
|
28
|
+
raise LibraryNotFoundError(f"Shared library not found. Checked {lib_path} and build directories.")
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
lib = ctypes.CDLL(lib_path)
|
|
32
|
+
except OSError as e:
|
|
33
|
+
raise LibraryNotFoundError(f"Could not load shared library at {lib_path}: {e}") from e
|
|
34
|
+
|
|
35
|
+
# Define return types and argument types for C++ functions
|
|
36
|
+
lib.encryptMessage.restype = c_char_p
|
|
37
|
+
lib.encryptMessage.argtypes = [c_char_p, c_char_p, c_char_p, c_char_p]
|
|
38
|
+
|
|
39
|
+
lib.encryptMessageDualKey.restype = c_char_p
|
|
40
|
+
lib.encryptMessageDualKey.argtypes = [c_char_p, c_char_p, c_char_p, c_char_p, c_char_p]
|
|
41
|
+
|
|
42
|
+
lib.encryptMessageMockup.restype = c_char_p
|
|
43
|
+
lib.encryptMessageMockup.argtypes = [c_char_p]
|
|
44
|
+
|
|
45
|
+
return lib
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Load the shared library
|
|
49
|
+
_lib = _load_library()
|
|
50
|
+
|
|
51
|
+
def encrypt_message(
|
|
52
|
+
tx_data: str,
|
|
53
|
+
public_key: str,
|
|
54
|
+
additional_authenticated_data_aes: str | None = None,
|
|
55
|
+
additional_authenticated_data_te: str | None = None) -> str:
|
|
56
|
+
"""
|
|
57
|
+
Encrypts a message using a single BLS public key.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
tx_data (str): The transaction data hex string.
|
|
61
|
+
public_key (str): The BLS public key hex string.
|
|
62
|
+
additional_authenticated_data_aes (str | None, optional): AES additional authenticated data.
|
|
63
|
+
additional_authenticated_data_te (str | None, optional): TE additional authenticated data.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
str: The encrypted message as a hex string.
|
|
67
|
+
|
|
68
|
+
Raises:
|
|
69
|
+
ValueError: If tx_data or public_key are empty.
|
|
70
|
+
EncryptionError: If encryption fails.
|
|
71
|
+
"""
|
|
72
|
+
if not tx_data or not public_key:
|
|
73
|
+
raise ValueError("tx_data and public_key must not be empty")
|
|
74
|
+
|
|
75
|
+
aad_aes = None
|
|
76
|
+
if additional_authenticated_data_aes:
|
|
77
|
+
aad_aes = additional_authenticated_data_aes.encode('utf-8')
|
|
78
|
+
|
|
79
|
+
aad_te = None
|
|
80
|
+
if additional_authenticated_data_te:
|
|
81
|
+
aad_te = additional_authenticated_data_te.encode('utf-8')
|
|
82
|
+
|
|
83
|
+
result = _lib.encryptMessage(
|
|
84
|
+
tx_data.encode('utf-8'),
|
|
85
|
+
public_key.encode('utf-8'),
|
|
86
|
+
aad_aes,
|
|
87
|
+
aad_te
|
|
88
|
+
)
|
|
89
|
+
if result is None:
|
|
90
|
+
raise EncryptionError("Encryption failed. Check library logs for details.")
|
|
91
|
+
return result.decode('utf-8')
|
|
92
|
+
|
|
93
|
+
def encrypt_message_dual_key(
|
|
94
|
+
tx_data: str,
|
|
95
|
+
first_key: str,
|
|
96
|
+
second_key: str,
|
|
97
|
+
additional_authenticated_data_aes: str | None = None,
|
|
98
|
+
additional_authenticated_data_te: str | None = None) -> str:
|
|
99
|
+
"""
|
|
100
|
+
Encrypts a message using two BLS public keys (dual-key encryption).
|
|
101
|
+
Args:
|
|
102
|
+
tx_data (str): The transaction data hex string to be encrypted.
|
|
103
|
+
first_key (str): The first BLS public key hex string.
|
|
104
|
+
second_key (str): The second BLS public key hex string.
|
|
105
|
+
additional_authenticated_data_aes (str | None, optional): AES additional authenticated data.
|
|
106
|
+
additional_authenticated_data_te (str | None, optional): TE additional authenticated data.
|
|
107
|
+
Returns:
|
|
108
|
+
str: The encrypted message as a hex string produced by dual-key encryption.
|
|
109
|
+
|
|
110
|
+
Raises:
|
|
111
|
+
ValueError: If tx_data, first_key, or second_key are empty.
|
|
112
|
+
EncryptionError: If dual key encryption fails.
|
|
113
|
+
"""
|
|
114
|
+
if not tx_data or not first_key or not second_key:
|
|
115
|
+
raise ValueError("tx_data, first_key, and second_key must not be empty")
|
|
116
|
+
|
|
117
|
+
aad_aes = None
|
|
118
|
+
if additional_authenticated_data_aes:
|
|
119
|
+
aad_aes = additional_authenticated_data_aes.encode('utf-8')
|
|
120
|
+
|
|
121
|
+
aad_te = None
|
|
122
|
+
if additional_authenticated_data_te:
|
|
123
|
+
aad_te = additional_authenticated_data_te.encode('utf-8')
|
|
124
|
+
|
|
125
|
+
result = _lib.encryptMessageDualKey(
|
|
126
|
+
tx_data.encode('utf-8'),
|
|
127
|
+
first_key.encode('utf-8'),
|
|
128
|
+
second_key.encode('utf-8'),
|
|
129
|
+
aad_aes,
|
|
130
|
+
aad_te
|
|
131
|
+
)
|
|
132
|
+
if result is None:
|
|
133
|
+
raise EncryptionError("Dual key encryption failed. Check library logs for details.")
|
|
134
|
+
return result.decode('utf-8')
|
|
135
|
+
|
|
136
|
+
def encrypt_message_mockup(tx_data: str) -> str:
|
|
137
|
+
"""
|
|
138
|
+
Mockup encryption for testing purposes.
|
|
139
|
+
Args:
|
|
140
|
+
tx_data (str): The transaction data hex string.
|
|
141
|
+
Returns:
|
|
142
|
+
str: The mockup encrypted message as a hex string.
|
|
143
|
+
|
|
144
|
+
Raises:
|
|
145
|
+
ValueError: If tx_data is empty.
|
|
146
|
+
EncryptionError: If mockup encryption fails.
|
|
147
|
+
"""
|
|
148
|
+
if not tx_data:
|
|
149
|
+
raise ValueError("tx_data must not be empty")
|
|
150
|
+
|
|
151
|
+
result = _lib.encryptMessageMockup(tx_data.encode('utf-8'))
|
|
152
|
+
if result is None:
|
|
153
|
+
raise EncryptionError("Mockup encryption failed. Check library logs for details.")
|
|
154
|
+
return result.decode('utf-8')
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class TEncryptError(Exception):
|
|
2
|
+
"""Base exception for t-encrypt errors."""
|
|
3
|
+
pass
|
|
4
|
+
|
|
5
|
+
class LibraryNotFoundError(TEncryptError):
|
|
6
|
+
"""Raised when the shared library cannot be found or loaded."""
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
class EncryptionError(TEncryptError):
|
|
10
|
+
"""Raised when encryption fails."""
|
|
11
|
+
pass
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: t-encrypt
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python bindings for SKALE Threshold Encryption
|
|
5
|
+
Author: SKALE Network
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Dynamic: author
|
|
10
|
+
Dynamic: classifier
|
|
11
|
+
Dynamic: requires-python
|
|
12
|
+
Dynamic: summary
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
t_encrypt
|