diff --git a/Makefile b/Makefile index 92db0ea7..4c53ecd6 100644 --- a/Makefile +++ b/Makefile @@ -4,20 +4,6 @@ test_gotest: go test -timeout=0 ./... -.PHONY: test_examples -test_examples: - @echo Running the examples - go run ./examples/ring/vOLE -short > /dev/null - go run ./examples/rgsw > /dev/null - go run ./examples/bfv > /dev/null - go run ./examples/ckks/bootstrapping -short > /dev/null - go run ./examples/ckks/advanced/lut -short > /dev/null - go run ./examples/ckks/euler > /dev/null - go run ./examples/ckks/polyeval > /dev/null - go run ./examples/dbfv/pir &> /dev/null - go run ./examples/dbfv/psi &> /dev/null - @echo ok - .PHONY: static_check static_check: check_tools @echo Checking correct formatting of files @@ -62,10 +48,10 @@ static_check: check_tools out=`git status --porcelain`; echo "$$out"; [ -z "$$out" ] .PHONY: test -test: test_gotest test_examples +test: test_gotest .PHONY: ci_test -ci_test: static_check test_gotest test_examples +ci_test: static_check test_gotest EXECUTABLES = goimports staticcheck .PHONY: get_tools diff --git a/examples/bfv/main.go b/examples/bfv/main.go index 72de225c..47bf0e0b 100644 --- a/examples/bfv/main.go +++ b/examples/bfv/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "math" "math/bits" @@ -12,6 +13,8 @@ import ( "github.com/tuneinsight/lattigo/v4/ring" ) +var flagShort = flag.Bool("short", false, "run the example with a smaller and insecure ring degree.") + func obliviousRiding() { // This example simulates a situation where an anonymous rider @@ -49,6 +52,9 @@ func obliviousRiding() { // Number of drivers in the area nbDrivers := 2048 //max is N + if *flagShort { + nbDrivers = 512 + } // BFV parameters (128 bit security) with plaintext modulus 65929217 // Creating encryption parameters from a default params with logN=14, logQP=438 with a plaintext modulus T=65929217 @@ -197,5 +203,6 @@ func distance(a, b, c, d uint64) uint64 { } func main() { + flag.Parse() obliviousRiding() } diff --git a/examples/bfv/main_test.go b/examples/bfv/main_test.go new file mode 100644 index 00000000..ee59e083 --- /dev/null +++ b/examples/bfv/main_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "os" + "testing" +) + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + oldArgs := os.Args + defer func() { os.Args = oldArgs }() + os.Args = append(os.Args, "-short") + main() +} diff --git a/examples/ckks/advanced/lut/main_test.go b/examples/ckks/advanced/lut/main_test.go new file mode 100644 index 00000000..ee59e083 --- /dev/null +++ b/examples/ckks/advanced/lut/main_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "os" + "testing" +) + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + oldArgs := os.Args + defer func() { os.Args = oldArgs }() + os.Args = append(os.Args, "-short") + main() +} diff --git a/examples/ckks/bootstrapping/main_test.go b/examples/ckks/bootstrapping/main_test.go new file mode 100644 index 00000000..ee59e083 --- /dev/null +++ b/examples/ckks/bootstrapping/main_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "os" + "testing" +) + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + oldArgs := os.Args + defer func() { os.Args = oldArgs }() + os.Args = append(os.Args, "-short") + main() +} diff --git a/examples/ckks/ckks_tutorial/main.go b/examples/ckks/ckks_tutorial/main.go index c34193bf..f6cc7c31 100644 --- a/examples/ckks/ckks_tutorial/main.go +++ b/examples/ckks/ckks_tutorial/main.go @@ -638,7 +638,8 @@ func main() { // Then we generate the corresponding Galois keys. // The list of Galois elements can also be obtained with `linTransf.GaloisElements` galEls = params.GaloisElementsForLinearTransform(nonZeroDiagonales, LogBSGSRatio, LogSlots) - eval = eval.WithKey(rlwe.NewMemEvaluationKeySet(rlk, kgen.GenGaloisKeysNew(galEls, sk)...)) + gks = kgen.GenGaloisKeysNew(galEls, sk) + eval = eval.WithKey(rlwe.NewMemEvaluationKeySet(rlk, gks...)) // And we valuate the linear transform eval.LinearTransform(ct1, linTransf, []*rlwe.Ciphertext{res}) diff --git a/examples/ckks/ckks_tutorial/main_test.go b/examples/ckks/ckks_tutorial/main_test.go new file mode 100644 index 00000000..5f223e08 --- /dev/null +++ b/examples/ckks/ckks_tutorial/main_test.go @@ -0,0 +1,11 @@ +package main + +import "testing" + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + t.Skip("test not passing") // TODO: bug in the linear transform API ? + main() +} diff --git a/examples/ckks/euler/main_test.go b/examples/ckks/euler/main_test.go new file mode 100644 index 00000000..6cbdcc76 --- /dev/null +++ b/examples/ckks/euler/main_test.go @@ -0,0 +1,10 @@ +package main + +import "testing" + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + main() +} diff --git a/examples/ckks/polyeval/main_test.go b/examples/ckks/polyeval/main_test.go new file mode 100644 index 00000000..6cbdcc76 --- /dev/null +++ b/examples/ckks/polyeval/main_test.go @@ -0,0 +1,10 @@ +package main + +import "testing" + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + main() +} diff --git a/examples/dbfv/pir/main_test.go b/examples/dbfv/pir/main_test.go new file mode 100644 index 00000000..e9e198b0 --- /dev/null +++ b/examples/dbfv/pir/main_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "os" + "testing" +) + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + oldArgs := os.Args + defer func() { os.Args = oldArgs }() + os.Args = os.Args[:1] + main() +} diff --git a/examples/dbfv/psi/main_test.go b/examples/dbfv/psi/main_test.go new file mode 100644 index 00000000..e9e198b0 --- /dev/null +++ b/examples/dbfv/psi/main_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "os" + "testing" +) + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + oldArgs := os.Args + defer func() { os.Args = oldArgs }() + os.Args = os.Args[:1] + main() +} diff --git a/examples/drlwe/thresh_eval_key_gen/main.go b/examples/drlwe/thresh_eval_key_gen/main.go index 2cb633e7..2284aff7 100644 --- a/examples/drlwe/thresh_eval_key_gen/main.go +++ b/examples/drlwe/thresh_eval_key_gen/main.go @@ -304,7 +304,8 @@ func main() { // collects the results in an EvaluationKeySet gks := []*rlwe.GaloisKey{} for task := range C.finDone { - gks = append(gks, &task) + gk := task + gks = append(gks, &gk) } evk := rlwe.NewMemEvaluationKeySet(nil, gks...) diff --git a/examples/drlwe/thresh_eval_key_gen/main_test.go b/examples/drlwe/thresh_eval_key_gen/main_test.go new file mode 100644 index 00000000..6cbdcc76 --- /dev/null +++ b/examples/drlwe/thresh_eval_key_gen/main_test.go @@ -0,0 +1,10 @@ +package main + +import "testing" + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + main() +} diff --git a/examples/rgsw/main_test.go b/examples/rgsw/main_test.go new file mode 100644 index 00000000..6cbdcc76 --- /dev/null +++ b/examples/rgsw/main_test.go @@ -0,0 +1,10 @@ +package main + +import "testing" + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + main() +} diff --git a/examples/ring/vOLE/main_test.go b/examples/ring/vOLE/main_test.go new file mode 100644 index 00000000..ee59e083 --- /dev/null +++ b/examples/ring/vOLE/main_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "os" + "testing" +) + +func TestMain(t *testing.T) { + if testing.Short() { + t.Skip("skipped in -short mode") + } + oldArgs := os.Args + defer func() { os.Args = oldArgs }() + os.Args = append(os.Args, "-short") + main() +}