Skip to content

Commit

Permalink
chore(common): add 132 bits security curves
Browse files Browse the repository at this point in the history
  • Loading branch information
aPere3 committed Dec 16, 2024
1 parent f0e0a08 commit 4eff1d1
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/guides/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,6 @@ When options are specified both in the `configuration` and as kwargs in the `com
- Automatic scheduling behavior can be override locally by calling directly a variant of `run`:
- `run_sync`: forces the fhe function to occur in the current thread, not in the background,
- `run_async`: forces the fhe function to occur in a background thread, returning immediately a `Future[Value]`

#### security_level: int = 128
- Set the level of security used to perform the optimization of crypto-parameters.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
DEFAULT_GLOBAL_P_ERROR = 1 / 100_000


class SecurityLevel(int, Enum):
"""
Security level used to optimize the circuit parameters.
"""

SECURITY_128_BITS = 128
SECURITY_132_BITS = 132


class ParameterSelectionStrategy(str, Enum):
"""
ParameterSelectionStrategy, to set optimization strategy.
Expand Down Expand Up @@ -998,6 +1007,7 @@ class Configuration:
range_restriction: Optional[RangeRestriction]
keyset_restriction: Optional[KeysetRestriction]
auto_schedule_run: bool
security_level: SecurityLevel

def __init__(
self,
Expand Down Expand Up @@ -1070,6 +1080,7 @@ def __init__(
range_restriction: Optional[RangeRestriction] = None,
keyset_restriction: Optional[KeysetRestriction] = None,
auto_schedule_run: bool = False,
security_level: SecurityLevel = SecurityLevel.SECURITY_128_BITS,
):
self.verbose = verbose
self.compiler_debug_mode = compiler_debug_mode
Expand Down Expand Up @@ -1181,6 +1192,8 @@ def __init__(

self.auto_schedule_run = auto_schedule_run

self.security_level = security_level

self._validate()

class Keep:
Expand Down Expand Up @@ -1259,6 +1272,7 @@ def fork(
range_restriction: Union[Keep, Optional[RangeRestriction]] = KEEP,
keyset_restriction: Union[Keep, Optional[KeysetRestriction]] = KEEP,
auto_schedule_run: Union[Keep, bool] = KEEP,
security_level: Union[Keep, SecurityLevel] = KEEP,
) -> "Configuration":
"""
Get a new configuration from another one specified changes.
Expand Down
2 changes: 2 additions & 0 deletions frontends/concrete-python/concrete/fhe/compilation/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def create(
if configuration.range_restriction:
options.set_range_restriction(configuration.range_restriction)

options.set_security_level(configuration.security_level)

try:
if configuration.compiler_debug_mode: # pragma: no cover
set_llvm_debug_flag(True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import os
import sys

import numpy as np
import pytest

from concrete import fhe
from concrete.fhe.compilation import Configuration
from concrete.fhe.compilation import Configuration, server
from concrete.fhe.compilation.configuration import SecurityLevel

from ..conftest import USE_MULTI_PRECISION

Expand Down Expand Up @@ -301,3 +303,46 @@ def test_configuration_show_bit_width_constraints_and_assignment(
""".strip(),
)


def test_set_security_level():

@fhe.module()
class Module:
@fhe.function({"x": "encrypted", "y": "clear"})
def inc(x, y):
return (x + y + 1) % 20

composition = fhe.Wired(
{
fhe.Wire(fhe.Output(inc, 0), fhe.AllInputs(inc)),
}
)

inputset = [
(np.random.randint(1, 20, size=()), np.random.randint(1, 20, size=())) for _ in range(100)
]

module1 = Module.compile(
{"inc": inputset},
security_level=SecurityLevel.SECURITY_128_BITS,
)

module2 = Module.compile(
{"inc": inputset},
security_level=SecurityLevel.SECURITY_128_BITS,
)

module3 = Module.compile(
{"inc": inputset},
security_level=SecurityLevel.SECURITY_132_BITS,
)

assert (
module1.server.client_specs.program_info.get_keyset_info()
== module2.server.client_specs.program_info.get_keyset_info()
)
assert (
module1.server.client_specs.program_info.get_keyset_info()
!= module3.server.client_specs.program_info.get_keyset_info()
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SecurityCurve curves[] = {
SecurityCurve(128, -0.025696778711484593, 2.675931372549016, 450, KeyFormat::BINARY),
SecurityCurve(132, -0.024891456582633045, 2.65734593837534, 450, KeyFormat::BINARY),
};

size_t curvesLen = 1;
size_t curvesLen = 2;
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
use super::security_weights::SecurityWeights;
pub const SECURITY_WEIGHTS_ARRAY: [(u64, SecurityWeights); 1] = [
(128, SecurityWeights { slope: -0.025696778711484593, bias: 2.675931372549016, minimal_lwe_dimension: 450 }),
pub const SECURITY_WEIGHTS_ARRAY: [(u64, SecurityWeights); 2] = [
(
128,
SecurityWeights {
slope: -0.025696778711484593,
bias: 2.675931372549016,
minimal_lwe_dimension: 450,
},
),
(
132,
SecurityWeights {
slope: -0.024891456582633045,
bias: 2.65734593837534,
minimal_lwe_dimension: 450,
},
),
];

0 comments on commit 4eff1d1

Please sign in to comment.