refactor: Move generated code

This commit is contained in:
Quentin Bourgerie
2022-12-19 15:11:03 +01:00
parent 732f2de57d
commit c8a23f02f5
11 changed files with 34 additions and 21 deletions

4
.gitignore vendored
View File

@@ -1,2 +1,2 @@
rust-security-curves/target/
rust-security-curves/Cargo.lock
concrete-security-curves/target/
concrete-security-curves/Cargo.lock

View File

@@ -1,12 +1,18 @@
CURVES_JSON_PATH=json/curves.json
CURVES_CPP_GEN_H=cpp/include/concrete/curves.gen.h
CURVES_CPP_GEN_H=concrete-security-curves-cpp/include/concrete/curves.gen.h
CURVES_RUST_GEN_TXT=concrete-security-curves-rust/src/curves.gen.rs
$(CURVES_JSON_PATH): verify_curves.py
sage verify_curves.py > $@
$(CURVES_CPP_GEN_H): cpp/gen_header.py $(CURVES_JSON_PATH)
cat $(CURVES_JSON_PATH) | python cpp/gen_header.py > $(CURVES_CPP_GEN_H)
$(CURVES_CPP_GEN_H): concrete-security-curves-cpp/gen_header.py $(CURVES_JSON_PATH)
cat $(CURVES_JSON_PATH) | python concrete-security-curves-cpp/gen_header.py > $(CURVES_CPP_GEN_H)
generate-cpp-header: $(CURVES_CPP_GEN_H)
generate-cpp: $(CURVES_CPP_GEN_H)
$(CURVES_RUST_GEN_TXT): rust/gen_table.py $(CURVES_JSON_PATH)
cat $(CURVES_JSON_PATH) | python concrete-security-curves-cpp/gen_table.py > $(CURVES_CPP_GEN_H)
generate-rust: $(CURVES_RUST_GEN_TXT)
.PHONY: generate-cpp-header

View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "concrete-security-curves"
version = "0.1.0"

View File

@@ -1,5 +1,5 @@
[package]
name = "rust-security-curves"
name = "concrete-security-curves"
version = "0.1.0"
edition = "2021"

View File

@@ -0,0 +1,13 @@
import sys, json;
def print_curve(data):
print(f' ({data["security_level"]}, SecurityWeights {{ slope: {data["slope"]}, bias: {data["bias"]}, minimal_lwe_dimension: {data["minimal_lwe_dimension"]} }}),')
def print_rust_curves_declaration(datas):
print("[")
for data in datas:
print_curve(data)
print("]")
print_rust_curves_declaration(json.load(sys.stdin))

View File

@@ -1,4 +1,4 @@
const SECURITY_WEIGHTS_ARRAY: [(u64, SecurityWeights); 9] = include!("../verified_curves.txt");
const SECURITY_WEIGHTS_ARRAY: [(u64, SecurityWeights); 9] = include!("./curves.gen.rs");
#[derive(Clone, Copy)]
pub struct SecurityWeights {

View File

@@ -1,13 +0,0 @@
import sys, json;
def print_curve(data):
print(f' ({data["bits"]}, SecurityWeights {{ slope: {data["linear_term1"]}, bias: {data["linear_term2"]}, minimal_lwe_dimension: {data["n_alpha"]} }}),')
def print_rust_curves_declaration(datas):
print("[")
for data in datas:
print_curve(data)
print("]")
print_rust_curves_declaration(json.load(open("json/curves.json")))