mirror of
https://github.com/zama-ai/concrete.git
synced 2026-01-10 05:18:00 -05:00
f
This commit is contained in:
@@ -19,6 +19,15 @@ using concretelang::values::Tensor;
|
||||
using concretelang::values::TransportValue;
|
||||
using concretelang::values::Value;
|
||||
|
||||
/// \brief simulate the encryption of a value by adding noise
|
||||
///
|
||||
/// \param message encoded message to encrypt
|
||||
/// \param lwe_dim
|
||||
/// \param csprng used to generate noise during encryption
|
||||
/// \return noisy plaintext
|
||||
uint64_t sim_encrypt_lwe_u64(uint64_t message, uint32_t lwe_dim,
|
||||
Csprng *encrypt_csprng);
|
||||
|
||||
namespace concretelang {
|
||||
namespace transformers {
|
||||
|
||||
|
||||
@@ -12,15 +12,6 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
/// \brief simulate the encryption of a value by adding noise
|
||||
///
|
||||
/// \param message encoded message to encrypt
|
||||
/// \param lwe_dim
|
||||
/// \param csprng used to generate noise during encryption
|
||||
/// \return noisy plaintext
|
||||
uint64_t sim_encrypt_lwe_u64(uint64_t message, uint32_t lwe_dim,
|
||||
Csprng *encrypt_csprng);
|
||||
|
||||
/// \brief simulate the negation of a noisy plaintext
|
||||
///
|
||||
/// \param plaintext noisy plaintext
|
||||
@@ -6,29 +6,11 @@
|
||||
#ifndef CONCRETELANG_RUNTIME_WRAPPERS_H
|
||||
#define CONCRETELANG_RUNTIME_WRAPPERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <complex.h>
|
||||
#include "concrete-cpu.h"
|
||||
|
||||
namespace mlir {
|
||||
namespace concretelang {
|
||||
struct RuntimeContext {
|
||||
const uint64_t *keyswitch_key_buffer(size_t keyId);
|
||||
const std::complex<double> *fourier_bootstrap_key_buffer(size_t keyId);
|
||||
const uint64_t *fp_keyswitch_key_buffer(size_t keyId);
|
||||
const struct Fft *fft(size_t keyId);
|
||||
#ifdef CONCRETELANG_CUDA_SUPPORT
|
||||
void *get_bsk_gpu(uint32_t input_lwe_dim, uint32_t poly_size, uint32_t level,
|
||||
uint32_t glwe_dim, uint32_t gpu_idx, void *stream,
|
||||
uint32_t bsk_idx);
|
||||
void *get_ksk_gpu(uint32_t level, uint32_t input_lwe_dim,
|
||||
uint32_t output_lwe_dim, uint32_t gpu_idx, void *stream,
|
||||
uint32_t ksk_idx);
|
||||
#endif
|
||||
};
|
||||
}
|
||||
}
|
||||
#include <complex.h>
|
||||
#include <concretelang/Runtime/context.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
@@ -10,8 +10,6 @@ add_mlir_library(
|
||||
Transformers.cpp
|
||||
Security.cpp
|
||||
Values.cpp
|
||||
simulation.cpp
|
||||
wrappers.cpp
|
||||
LINK_LIBS
|
||||
PUBLIC
|
||||
rust_deps_bundle
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
#include "concretelang/Common/Csprng.h"
|
||||
#include "concretelang/Common/Error.h"
|
||||
#include "concretelang/Common/Keysets.h"
|
||||
#include "concretelang/Common/Security.h"
|
||||
#include "concretelang/Common/Values.h"
|
||||
#include "concretelang/Common/simulation.h"
|
||||
|
||||
#include <memory>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
@@ -24,6 +25,31 @@ using concretelang::values::Tensor;
|
||||
using concretelang::values::TransportValue;
|
||||
using concretelang::values::Value;
|
||||
|
||||
namespace {
|
||||
thread_local auto default_csprng = concretelang::csprng::SoftCSPRNG(0);
|
||||
|
||||
inline concretelang::security::SecurityCurve *security_curve() {
|
||||
return concretelang::security::getSecurityCurve(
|
||||
128, concretelang::security::BINARY);
|
||||
}
|
||||
|
||||
uint64_t gaussian_noise(double variance, Csprng *csprng = default_csprng.ptr) {
|
||||
uint64_t random_gaussian_buff[2];
|
||||
|
||||
double std_dev = std::sqrt(variance);
|
||||
concrete_cpu_fill_with_random_gaussian(random_gaussian_buff, 2, std_dev,
|
||||
csprng);
|
||||
return random_gaussian_buff[0];
|
||||
}
|
||||
} // namespace
|
||||
|
||||
uint64_t sim_encrypt_lwe_u64(uint64_t message, uint32_t lwe_dim,
|
||||
Csprng *csprng) {
|
||||
double variance = security_curve()->getVariance(1, lwe_dim, 64);
|
||||
uint64_t encryption_noise = gaussian_noise(variance, (Csprng *)csprng);
|
||||
return message + encryption_noise;
|
||||
}
|
||||
|
||||
namespace concretelang {
|
||||
namespace transformers {
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ if(CONCRETELANG_CUDA_SUPPORT)
|
||||
DFRuntime.cpp
|
||||
key_manager.cpp
|
||||
GPUDFG.cpp
|
||||
simulation.cpp
|
||||
wrappers.cpp
|
||||
time_util.cpp)
|
||||
else()
|
||||
add_library(
|
||||
@@ -15,6 +17,8 @@ else()
|
||||
DFRuntime.cpp
|
||||
key_manager.cpp
|
||||
GPUDFG.cpp
|
||||
simulation.cpp
|
||||
wrappers.cpp
|
||||
time_util.cpp)
|
||||
endif()
|
||||
|
||||
@@ -77,6 +81,8 @@ add_library(
|
||||
DFRuntime.cpp
|
||||
key_manager.cpp
|
||||
GPUDFG.cpp
|
||||
simulation.cpp
|
||||
wrappers.cpp
|
||||
time_util.cpp)
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <concretelang/Runtime/GPUDFG.hpp>
|
||||
#include <concretelang/Runtime/stream_emulator_api.h>
|
||||
#include <concretelang/Runtime/time_util.h>
|
||||
#include <concretelang/Common/wrappers.h>
|
||||
#include <concretelang/Runtime/wrappers.h>
|
||||
|
||||
using RuntimeContext = mlir::concretelang::RuntimeContext;
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
// https://github.com/zama-ai/concrete/blob/main/LICENSE.txt
|
||||
// for license information.
|
||||
|
||||
#include "concretelang/Common/simulation.h"
|
||||
#include "concretelang/Runtime/simulation.h"
|
||||
#include "concrete-cpu-noise-model.h"
|
||||
#include "concrete-cpu.h"
|
||||
#include "concretelang/Common/Csprng.h"
|
||||
#include "concretelang/Common/Security.h"
|
||||
#include "concretelang/Common/wrappers.h"
|
||||
#include "concretelang/Runtime/wrappers.h"
|
||||
#include "concretelang/Support/V0Parameters.h"
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
@@ -38,13 +38,6 @@ uint64_t gaussian_noise(double variance, Csprng *csprng = default_csprng.ptr) {
|
||||
return random_gaussian_buff[0];
|
||||
}
|
||||
|
||||
uint64_t sim_encrypt_lwe_u64(uint64_t message, uint32_t lwe_dim,
|
||||
Csprng *csprng) {
|
||||
double variance = security_curve()->getVariance(1, lwe_dim, 64);
|
||||
uint64_t encryption_noise = gaussian_noise(variance, (Csprng *)csprng);
|
||||
return message + encryption_noise;
|
||||
}
|
||||
|
||||
uint64_t sim_keyswitch_lwe_u64(uint64_t plaintext, uint32_t level,
|
||||
uint32_t base_log, uint32_t input_lwe_dim,
|
||||
uint32_t output_lwe_dim) {
|
||||
@@ -3,7 +3,7 @@
|
||||
// https://github.com/zama-ai/concrete/blob/main/LICENSE.txt
|
||||
// for license information.
|
||||
|
||||
#include "concretelang/Common/wrappers.h"
|
||||
#include "concretelang/Runtime/wrappers.h"
|
||||
#include "concrete-cpu.h"
|
||||
#include "concretelang/Common/Error.h"
|
||||
#include <assert.h>
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "concretelang/Common/wrappers.h"
|
||||
#include "concretelang/Runtime/wrappers.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user