mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-15 15:15:06 -05:00
add ct modulus
This commit is contained in:
@@ -3,6 +3,8 @@ from v0curves import curves
|
||||
# define the number of security levels in curves
|
||||
num_sec_levels = len(curves)
|
||||
|
||||
polynomial_i
|
||||
|
||||
|
||||
import_string = f"""
|
||||
|
||||
@@ -19,12 +21,15 @@ typedef struct v0curves
|
||||
{
|
||||
int rlweDimension;
|
||||
int polynomialSize;
|
||||
int ciphertextModulus;
|
||||
|
||||
v0curves(int rlweDimension,
|
||||
int polynomialSize_)
|
||||
int polynomialSize_,
|
||||
int ciphertextModulus)
|
||||
{
|
||||
rlweDimension = rlweDimension_;
|
||||
polynomialSize = polynomialSize_;
|
||||
ciphertextModulus = ciphertextModulus_;
|
||||
}
|
||||
|
||||
} v0curves;"""
|
||||
@@ -35,19 +40,20 @@ v0curves parameters[num_sec_levels] = """
|
||||
|
||||
|
||||
get_string = """
|
||||
extern "C" int security_estimator(int rlweDimension, int polynomialSize)
|
||||
extern "C" int security_estimator(int rlweDimension, int polynomialSize, int ciphertextModulus)
|
||||
{
|
||||
}"""
|
||||
|
||||
|
||||
def constructor(rlweDimension, polynomialSize):
|
||||
return f"v0curves({rlweDimension}, {polynomialSize}),"
|
||||
def constructor(rlweDimension, polynomialSize, ciphertextModulus):
|
||||
return f"v0curves({rlweDimension}, {polynomialSize}, {ciphertextModulus}),"
|
||||
|
||||
|
||||
def fill_parameters(
|
||||
# Return a string with parameters for the c++ array initialization
|
||||
polynomial_size_results,
|
||||
rlwe_dimension_results,
|
||||
ciphertextModulus,
|
||||
):
|
||||
parameters = "{}{{".format(table_string)
|
||||
for security_level in range(num_sec_levels):
|
||||
@@ -58,10 +64,10 @@ def fill_parameters(
|
||||
line += constructor(
|
||||
int(polynomial_size_results[security_level]),
|
||||
int(rlwe_dimension_results[security_level]),
|
||||
|
||||
int(ciphertext_modulus_results[security_level]),
|
||||
)
|
||||
except ValueError:
|
||||
line += constructor(0, 0)
|
||||
line += constructor(0, 0,0)
|
||||
line = line[:-1]
|
||||
line += "},"
|
||||
parameters += line
|
||||
@@ -73,6 +79,7 @@ def fill_parameters(
|
||||
def codegen(
|
||||
polynomial_size_results,
|
||||
rlwe_dimension_results,
|
||||
ciphertext_modulus_results,
|
||||
):
|
||||
# Generate the C++ file as a string
|
||||
code = f"""
|
||||
@@ -82,6 +89,7 @@ def codegen(
|
||||
{fill_parameters(
|
||||
polynomial_size_results,
|
||||
rlwe_dimension_results,
|
||||
ciphertext_modulus_results
|
||||
)}
|
||||
{get_string}
|
||||
"""
|
||||
@@ -91,11 +99,13 @@ def codegen(
|
||||
def write_codegen(
|
||||
polynomial_size_results,
|
||||
rlwe_dimension_results,
|
||||
ciphertext_modulus_results
|
||||
):
|
||||
# Create the c++ source
|
||||
code = codegen(
|
||||
polynomial_size_results,
|
||||
rlwe_dimension_results,
|
||||
ciphertext_modulus_results
|
||||
)
|
||||
# TODO: insert correct filename here with a path
|
||||
with open(f"test.cpp", "w") as f:
|
||||
@@ -107,12 +117,13 @@ def main_codegen():
|
||||
# finding parameters for V0
|
||||
(
|
||||
polynomial_size_results,
|
||||
rlwe_dimension_results
|
||||
rlwe_dimension_results,
|
||||
ciphertext_modulus_resultss
|
||||
) = main_optimization_v0()
|
||||
|
||||
# code generation
|
||||
write_codegen(
|
||||
polynomial_size_results,
|
||||
rlwe_dimension_results
|
||||
rlwe_dimension_results,
|
||||
ciphertext_modulus_results
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user