TFHE同态库详解(一)

引言

关于库的下载与安装可以参考上一篇文章TFHE同态库的安装与简单使用
也可以自己直接下载TFHE同态库
这一部分主要是介绍了该库中一些结构体的定义

src/include/tfhe_core.h

定义了一些结构体

#ifndef TFHE_CORE_H
#define TFHE_CORE_H

///@file
///@brief This file declares only the structures names
#include <stdint.h>

//not very important, but all the functions exported in the output library
//should use the C naming convention, for inter-compiler compatibility
//reasons, or to bind it with non C++ code.
#ifdef __cplusplus
#define EXPORT extern "C"
#include "tfhe_generic_templates.h"
#else
#define EXPORT
#endif

EXPORT void die_dramatically(const char* message);
typedef int32_t Torus32; //32位的int类型
//typedef int64_t Torus64; //64位的int类型

//定义的一些结构体
struct LweParams;
struct LweKey;
struct LweSample;
struct LweKeySwitchKey;
struct TLweParams;
struct TLweKey;
struct TLweSample;
struct TLweSampleFFT;
struct TGswParams;
struct TGswKey;
struct TGswSample;
struct TGswSampleFFT;
struct LweBootstrappingKey;
struct LweBootstrappingKeyFFT;
struct IntPolynomial;
struct TorusPolynomial;
struct LagrangeHalfCPolynomial;
struct TFheGateBootstrappingParameterSet;
struct TFheGateBootstrappingCloudKeySet;
struct TFheGateBootstrappingSecretKeySet;

//this is for compatibility with C code, to be able to use
//"LweParams" as a type and not "struct LweParams"
typedef struct LweParams           LweParams;
typedef struct LweKey              LweKey;
typedef struct LweSample           LweSample;
typedef struct LweKeySwitchKey     LweKeySwitchKey;
typedef struct TLweParams       TLweParams;
typedef struct TLweKey          TLweKey;
typedef struct TLweSample       TLweSample;
typedef struct TLweSampleFFT       TLweSampleFFT;
typedef struct TGswParams       TGswParams;
typedef struct TGswKey          TGswKey;
typedef struct TGswSample       TGswSample;
typedef struct TGswSampleFFT       TGswSampleFFT;
typedef struct LweBootstrappingKey LweBootstrappingKey;
typedef struct LweBootstrappingKeyFFT LweBootstrappingKeyFFT;
typedef struct IntPolynomial	   IntPolynomial;
typedef struct TorusPolynomial	   TorusPolynomial;
typedef struct LagrangeHalfCPolynomial	   LagrangeHalfCPolynomial;
typedef struct TFheGateBootstrappingParameterSet TFheGateBootstrappingParameterSet;
typedef struct TFheGateBootstrappingCloudKeySet TFheGateBootstrappingCloudKeySet;
typedef struct TFheGateBootstrappingSecretKeySet TFheGateBootstrappingSecretKeySet;

#endif //TFHE_CORE_H

src/include/lweparams.h

结构体LweParams,定义了lwe的参数

#ifndef LWEPARAMS_H
#define LWEPARAMS_H

///@file
///@brief This file contains the declaration of lwe parameters structures

#include "tfhe_core.h"

//this structure contains Lwe parameters
//this structure is constant (cannot be modified once initialized): 
//the pointer to the param can be passed directly
//to all the Lwe keys that use these params.
//这个结构包含Lwe参数
//这个结构是常量(一旦初始化就不能修改)。
struct LweParams {
	const int32_t n;//安全参数n
	const double alpha_min;//le plus petit bruit tq sur
	const double alpha_max;//le plus gd bruit qui permet le déchiffrement



//since all members are declared constant, a constructor is 
//required in the structure.
//由于所有成员都声明为常量,因此结构中需要一个构造函数
#ifdef __cplusplus
	LweParams(int32_t n, double alpha_min, double alpha_max);
	~LweParams();
	LweParams(const LweParams&) = delete; //forbidden
	LweParams& operator=(const LweParams& ) = delete; //forbidden
#endif
};

//allocate memory space for a LweParams
EXPORT LweParams* alloc_LweParams();
EXPORT LweParams* alloc_LweParams_array(int32_t nbelts);

//free memory space for a LweParams
EXPORT void free_LweParams(LweParams* ptr);
EXPORT void free_LweParams_array(int32_t nbelts, LweParams* ptr);

//initialize the LweParams structure
//(equivalent of the C++ constructor)
EXPORT void init_LweParams(LweParams* obj, int32_t n, double alpha_min, double alpha_max);
EXPORT void init_LweParams_array(int32_t nbelts, LweParams* obj, int32_t n, double alpha_min, double alpha_max);

//destroys the LweParams structure
//(equivalent of the C++ destructor)
EXPORT void destroy_LweParams(LweParams* obj);
EXPORT void destroy_LweParams_array(int32_t nbelts, LweParams* obj);
 
//allocates and initialize the LweParams structure
//(equivalent of the C++ new)
EXPORT LweParams* new_LweParams(int32_t n, double alpha_min, double alpha_max);
EXPORT LweParams* new_LweParams_array(int32_t nbelts, int32_t n, double alpha_min, double alpha_max);

//destroys and frees the LweParams structure
//(equivalent of the C++ delete)
EXPORT void delete_LweParams(LweParams* obj);
EXPORT void delete_LweParams_array(int32_t nbelts, LweParams* obj);

#endif //LWEPARAMS_H

src/include/lwekey.h

结构体LweKey,包含了 LWE 密钥结构的声明

#ifndef LweKEY_H
#define LweKEY_H

///@file
///@brief This file contains the declaration of LWE key structures
///此文件包含 LWE 密钥结构的声明

#include "tfhe_core.h"


struct LweKey {
   const LweParams* params;//lwe参数
   int32_t* key;//32位的int

#ifdef __cplusplus   
   LweKey(const LweParams* params);
   ~LweKey();
   LweKey(const LweKey&) = delete; //forbidden 
   LweKey* operator=(const LweKey&) = delete; //forbidden
#endif
};

//-----------------------------------------------------------------
// autogenerated allocators/constructors/destructors declarations
// use code_autogen.pl LweKey LweParams to regenerate
// 自动生成的分配器/构造器/析构器声明
//-----------------------------------------------------------------


/** allocate space for a single LweKey */
EXPORT LweKey* alloc_LweKey();
/** allocate space for an array of LweKey 
 * @param nbelts the number of elements */
EXPORT LweKey* alloc_LweKey_array(int32_t nbelts);

/** free memory space for a single LweKey 
 * @param ptr the pointer to release */
EXPORT void free_LweKey(LweKey* ptr);
/** free memory space for an array of LweKey 
 * @param nbelts the number of elements 
 * @param ptr the pointer to release */
EXPORT void free_LweKey_array(int32_t nbelts, LweKey* ptr);

/** initializes (constructor) a single LweKey on an already allocated space 
 * @param ptr the pointer to the first element
 * @param params the LWE parameters to use
 */
EXPORT void init_LweKey(LweKey* ptr, const LweParams* params);

/** initializes (constructor) an array of LweKeys on an already allocated space 
 * @param nbelts the number of elements to initialize 
 * @param ptr the pointer to the first element
 * @param params the LWE parameters to use
 */
EXPORT void init_LweKey_array(int32_t nbelts, LweKey* ptr, const LweParams* params);

/** finalizes (destructor) a single LweKey (before freeing the memory space) 
 * @param ptr the pointer to the first element
 */
EXPORT void destroy_LweKey(LweKey* ptr);

/** finalizes (destructor) an array of LweKeys (before freeing the memory space) 
 * @param nbelts the number of elements to initialize 
 * @param ptr the pointer to the first element
 */
EXPORT void destroy_LweKey_array(int32_t nbelts, LweKey* ptr);
 
/** allocates and initializes (constructor) a single LweKey 
 * @param params the LWE parameters to use
 */
EXPORT LweKey* new_LweKey(const LweParams* params);
/** allocates and initializes (constructor) a single LweKey 
 * @param nbelts the number of consecutive elements to create 
 * @param params the LWE parameters to use
 */
EXPORT LweKey* new_LweKey_array(int32_t nbelts, const LweParams* params);

/** destroy and frees memory space for a single LweKey 
 * @param ptr the pointer to release */
EXPORT void delete_LweKey(LweKey* obj);
/** destroys and free memory space for an array of LweKey 
 * @param nbelts the number of elements 
 * @param ptr the pointer to release */
EXPORT void delete_LweKey_array(int32_t nbelts, LweKey* obj);

#endif //LweKEY_H

src/include/lwesamples.h

结构体LweSample ,包含了 LWE 密文的结构

#ifndef LweSAMPLES_H
#define LweSAMPLES_H

///@file
///@brief This file contains the declaration of lwesamples structures
///该文件包含 lwesamples 结构的声明
#include "tfhe_core.h"

struct LweSample {
	Torus32* a; //mask的数组,有n个
    Torus32 b;  //
   	double current_variance; //样本的平均噪声

#ifdef __cplusplus
   LweSample(const LweParams* params);
   ~LweSample();
   LweSample(const LweSample&)=delete;
   LweSample& operator=(const LweSample&)=delete;
#endif
};


//-----------------------------------------------------------------
// autogenerated allocators/constructors/destructors declarations
// use code_autogen.pl LweSample LweParams to regenerate
// 自动生成的分配器/构造器/析构器声明
//-----------------------------------------------------------------


/** allocate space for a single LweSample */
EXPORT LweSample* alloc_LweSample();
/** allocate space for an array of LweSample 
 * @param nbelts the number of elements */
EXPORT LweSample* alloc_LweSample_array(int32_t nbelts);

/** free memory space for a single LweSample 
 * @param ptr the pointer to release */
EXPORT void free_LweSample(LweSample* ptr);
/** free memory space for an array of LweSample 
 * @param nbelts the number of elements 
 * @param ptr the pointer to release */
EXPORT void free_LweSample_array(int32_t nbelts, LweSample* ptr);

/** initializes (constructor) a single LweSample on an already allocated space 
 * @param ptr the pointer to the first element
 * @param params the LWE parameters to use
 */
EXPORT void init_LweSample(LweSample* ptr, const LweParams* params);

/** initializes (constructor) an array of LweSamples on an already allocated space 
 * @param nbelts the number of elements to initialize 
 * @param ptr the pointer to the first element
 * @param params the LWE parameters to use
 */
EXPORT void init_LweSample_array(int32_t nbelts, LweSample* ptr, const LweParams* params);

/** finalizes (destructor) a single LweSample (before freeing the memory space) 
 * @param ptr the pointer to the first element
 */
EXPORT void destroy_LweSample(LweSample* ptr);

/** finalizes (destructor) an array of LweSamples (before freeing the memory space) 
 * @param nbelts the number of elements to initialize 
 * @param ptr the pointer to the first element
 */
EXPORT void destroy_LweSample_array(int32_t nbelts, LweSample* ptr);
 
/** allocates and initializes (constructor) a single LweSample 
 * @param params the LWE parameters to use
 */
EXPORT LweSample* new_LweSample(const LweParams* params);
/** allocates and initializes (constructor) a single LweSample 
 * @param nbelts the number of consecutive elements to create 
 * @param params the LWE parameters to use
 */
EXPORT LweSample* new_LweSample_array(int32_t nbelts, const LweParams* params);

/** destroy and frees memory space for a single LweSample 
 * @param ptr the pointer to release */
EXPORT void delete_LweSample(LweSample* obj);
/** destroys and free memory space for an array of LweSample 
 * @param nbelts the number of elements 
 * @param ptr the pointer to release */
EXPORT void delete_LweSample_array(int32_t nbelts, LweSample* obj);

#endif //LWESAMPLES_H

src/include/lwekeyswitch.h

结构体LweKeySwitchKey,定义了lwe的密钥转换结构

#ifndef LWEKEYSWITCH_H
#define LWEKEYSWITCH_H

///@file
///@brief This file contains the declaration of LWE keyswitch structures
///此文件包含 LWE 密钥转换结构的声明

#include "tfhe_core.h"
#include "lweparams.h"
#include "lwesamples.h"

struct LweKeySwitchKey {
    int32_t n; /// 密钥s的长度
    int32_t t; /// 分解长度
    int32_t basebit; ///< log_2(base)
    int32_t base; /// 分解基数:2的幂
    const LweParams* out_params; /// 输出密钥s的参数 
    LweSample* ks0_raw; // 包含所有大小为 nlbase 的 Lwe 密钥的数组
    LweSample** ks1_raw;// 大小为 nl 的数组 ks0_raw 指向一个数组 de taille nl  pointe vers un tableau ks0_raw dont les cases sont espaceés de base positions
    LweSample*** ks; /// keyswitch元素:a n.l.base matrix
    // de taille n pointe vers ks1 un tableau dont les cases sont espaceés de ell positions
    // 大小为 n 的指向 ks1 一个数组,其单元格由 ell 位置隔开

#ifdef __cplusplus
    LweKeySwitchKey(int32_t n, int32_t t, int32_t basebit, const LweParams* out_params, LweSample* ks0_raw);
    ~LweKeySwitchKey();
    LweKeySwitchKey(const LweKeySwitchKey&) = delete;
    void operator=(const LweKeySwitchKey&) = delete;
#endif
};

//allocate memory space for a LweKeySwitchKey
EXPORT LweKeySwitchKey* alloc_LweKeySwitchKey();
EXPORT LweKeySwitchKey* alloc_LweKeySwitchKey_array(int32_t nbelts);

//free memory space for a LweKeySwitchKey
EXPORT void free_LweKeySwitchKey(LweKeySwitchKey* ptr);
EXPORT void free_LweKeySwitchKey_array(int32_t nbelts, LweKeySwitchKey* ptr);

//initialize the LweKeySwitchKey structure
//(equivalent of the C++ constructor)
EXPORT void init_LweKeySwitchKey(LweKeySwitchKey* obj, int32_t n, int32_t t, int32_t basebit, const LweParams* out_params);
EXPORT void init_LweKeySwitchKey_array(int32_t nbelts, LweKeySwitchKey* obj, int32_t n, int32_t t, int32_t basebit, const LweParams* out_params);

//destroys the LweKeySwitchKey structure
//(equivalent of the C++ destructor)
EXPORT void destroy_LweKeySwitchKey(LweKeySwitchKey* obj);
EXPORT void destroy_LweKeySwitchKey_array(int32_t nbelts, LweKeySwitchKey* obj);

//allocates and initialize the LweKeySwitchKey structure
//(equivalent of the C++ new)
EXPORT LweKeySwitchKey* new_LweKeySwitchKey(int32_t n, int32_t t, int32_t basebit, const LweParams* out_params);
EXPORT LweKeySwitchKey* new_LweKeySwitchKey_array(int32_t nbelts, int32_t n, int32_t t, int32_t basebit, const LweParams* out_params);

//destroys and frees the LweKeySwitchKey structure
//(equivalent of the C++ delete)
EXPORT void delete_LweKeySwitchKey(LweKeySwitchKey* obj);
EXPORT void delete_LweKeySwitchKey_array(int32_t nbelts, LweKeySwitchKey* obj);

#endif // LWEKEYSWITCH_H

src/include/tlwe.h

结构体TLweParams、TLweKey、TLweSample、TLweSampleFFT,包含了 tlwe 结构的声明

#ifndef RINGLWE_H
#define RINGLWE_H

///@file
///@brief This file contains the declaration of tlwe structures
///此文件包含 tlwe 结构的声明

#include "tfhe_core.h"
#include "lweparams.h"

/// TLwe参数
struct TLweParams {
    const int32_t N; ///< 2 的幂:多项式的次数
    const int32_t k; ///< mask中的多项式数
    const double alpha_min; ///< 最小噪音标准 样品是安全的
    const double alpha_max; ///< 最大噪声标准 我们可以解密
    const LweParams extracted_lweparams; ///< lwe 参数 if one extracts

#ifdef __cplusplus

    TLweParams(int32_t N, int32_t k, double alpha_min, double alpha_max);

    ~TLweParams();

    TLweParams(const TLweParams &) = delete;

    void operator=(const TLweParams &) = delete;

#endif
};

/// TLwe密钥
struct TLweKey {
    const TLweParams *params; ///< 密钥的参数
    IntPolynomial *key; ///< 密钥(即 k 二元多项式)
    // IntPolynomial这个结构表示一个整数多项式模 X^N+1
#ifdef __cplusplus

    TLweKey(const TLweParams *params);

    ~TLweKey();

    TLweKey(const TLweKey &) = delete;

    void operator=(const TLweKey &) = delete;

#endif
};

/// TLwe密文
struct TLweSample {
    TorusPolynomial *a; ///< 长度为 k+1 的数组: mask + right term
    TorusPolynomial *b; ///< a[k] 的别名以获得正确的术语
    // TorusPolynomial这个结构表示一个环面多项式模 X^N+1
    double current_variance; ///< 样本(sample)的平均方差
    const int32_t k;
#ifdef __cplusplus

    TLweSample(const TLweParams *params);

    ~TLweSample();

    TLweSample(const TLweSample &) = delete;

    void operator=(const TLweSample &) = delete;

#endif
};

/// TLwe密文的FFT运算结构
struct TLweSampleFFT {
    LagrangeHalfCPolynomial *a; ///< 长度为 k+1 的数组: mask + right term
    LagrangeHalfCPolynomial *b; ///< a[k] 的别名以获得正确的术语
    // LagrangeHalfCPolynomial该结构用于 FFT 运算,是一种表示
    double current_variance; ///< 密文(sample)的平均方差 
    const int32_t k; //在析构函数调用期间需要...
#ifdef __cplusplus

    TLweSampleFFT(const TLweParams *params, LagrangeHalfCPolynomial *a, double current_variance);

    ~TLweSampleFFT();

    TLweSampleFFT(const TLweSampleFFT &) = delete;

    void operator=(const TLweSampleFFT &) = delete;

#endif
};


//allocate memory space for a TLweParams
EXPORT TLweParams *alloc_TLweParams();
EXPORT TLweParams *alloc_TLweParams_array(int32_t nbelts);

//free memory space for a TLweParams
EXPORT void free_TLweParams(TLweParams *ptr);
EXPORT void free_TLweParams_array(int32_t nbelts, TLweParams *ptr);

//initialize the TLweParams structure
//(equivalent of the C++ constructor)
EXPORT void init_TLweParams(TLweParams *obj, int32_t N, int32_t k, double alpha_min, double alpha_max);
EXPORT void init_TLweParams_array(int32_t nbelts, TLweParams *obj, int32_t N, int32_t k, double alpha_min, double alpha_max);

//destroys the TLweParams structure
//(equivalent of the C++ destructor)
EXPORT void destroy_TLweParams(TLweParams *obj);
EXPORT void destroy_TLweParams_array(int32_t nbelts, TLweParams *obj);

//allocates and initialize the TLweParams structure
//(equivalent of the C++ new)
EXPORT TLweParams *new_TLweParams(int32_t N, int32_t k, double alpha_min, double alpha_max);
EXPORT TLweParams *new_TLweParams_array(int32_t nbelts, int32_t N, int32_t k, double alpha_min, double alpha_max);

//destroys and frees the TLweParams structure
//(equivalent of the C++ delete)
EXPORT void delete_TLweParams(TLweParams *obj);
EXPORT void delete_TLweParams_array(int32_t nbelts, TLweParams *obj);

//-----------------------------------------------------------------
// autogenerated allocators/constructors/destructors declarations
// use code_autogen.pl TLweKey TLweParams to regenerate
//-----------------------------------------------------------------


/** allocate space for a single TLweKey */
EXPORT TLweKey *alloc_TLweKey();
/** allocate space for an array of TLweKey 
 * @param nbelts the number of elements */
EXPORT TLweKey *alloc_TLweKey_array(int32_t nbelts);

/** free memory space for a single TLweKey 
 * @param ptr the pointer to release */
EXPORT void free_TLweKey(TLweKey *ptr);
/** free memory space for an array of TLweKey 
 * @param nbelts the number of elements 
 * @param ptr the pointer to release */
EXPORT void free_TLweKey_array(int32_t nbelts, TLweKey *ptr);

/** initializes (constructor) a single TLweKey on an already allocated space 
 * @param ptr the pointer to the first element
 * @param params the LWE parameters to use
 */
EXPORT void init_TLweKey(TLweKey *ptr, const TLweParams *params);

/** initializes (constructor) an array of TLweKeys on an already allocated space 
 * @param nbelts the number of elements to initialize 
 * @param ptr the pointer to the first element
 * @param params the LWE parameters to use
 */
EXPORT void init_TLweKey_array(int32_t nbelts, TLweKey *ptr, const TLweParams *params);

/** finalizes (destructor) a single TLweKey (before freeing the memory space) 
 * @param ptr the pointer to the first element
 */
EXPORT void destroy_TLweKey(TLweKey *ptr);

/** finalizes (destructor) an array of TLweKeys (before freeing the memory space) 
 * @param nbelts the number of elements to initialize 
 * @param ptr the pointer to the first element
 */
EXPORT void destroy_TLweKey_array(int32_t nbelts, TLweKey *ptr);

/** allocates and initializes (constructor) a single TLweKey 
 * @param params the LWE parameters to use
 */
EXPORT TLweKey *new_TLweKey(const TLweParams *params);
/** allocates and initializes (constructor) a single TLweKey 
 * @param nbelts the number of consecutive elements to create 
 * @param params the LWE parameters to use
 */
EXPORT TLweKey *new_TLweKey_array(int32_t nbelts, const TLweParams *params);

/** destroy and frees memory space for a single TLweKey 
 * @param ptr the pointer to release */
EXPORT void delete_TLweKey(TLweKey *obj);
/** destroys and free memory space for an array of TLweKey 
 * @param nbelts the number of elements 
 * @param ptr the pointer to release */
EXPORT void delete_TLweKey_array(int32_t nbelts, TLweKey *obj);


//-----------------------------------------------------------------
// autogenerated allocators/constructors/destructors declarations
// use code_autogen.pl TLweSample TLweParams to regenerate
//-----------------------------------------------------------------


/** allocate space for a single TLweSample */
EXPORT TLweSample *alloc_TLweSample();
/** allocate space for an array of TLweSample 
 * @param nbelts the number of elements */
EXPORT TLweSample *alloc_TLweSample_array(int32_t nbelts);

/** free memory space for a single TLweSample 
 * @param ptr the pointer to release */
EXPORT void free_TLweSample(TLweSample *ptr);
/** free memory space for an array of TLweSample 
 * @param nbelts the number of elements 
 * @param ptr the pointer to release */
EXPORT void free_TLweSample_array(int32_t nbelts, TLweSample *ptr);

/** initializes (constructor) a single TLweSample on an already allocated space 
 * @param ptr the pointer to the first element
 * @param params the LWE parameters to use
 */
EXPORT void init_TLweSample(TLweSample *ptr, const TLweParams *params);

/** initializes (constructor) an array of TLweSamples on an already allocated space 
 * @param nbelts the number of elements to initialize 
 * @param ptr the pointer to the first element
 * @param params the LWE parameters to use
 */
EXPORT void init_TLweSample_array(int32_t nbelts, TLweSample *ptr, const TLweParams *params);

/** finalizes (destructor) a single TLweSample (before freeing the memory space) 
 * @param ptr the pointer to the first element
 */
EXPORT void destroy_TLweSample(TLweSample *ptr);

/** finalizes (destructor) an array of TLweSamples (before freeing the memory space) 
 * @param nbelts the number of elements to initialize 
 * @param ptr the pointer to the first element
 */
EXPORT void destroy_TLweSample_array(int32_t nbelts, TLweSample *ptr);

/** allocates and initializes (constructor) a single TLweSample 
 * @param params the LWE parameters to use
 */
EXPORT TLweSample *new_TLweSample(const TLweParams *params);
/** allocates and initializes (constructor) a single TLweSample 
 * @param nbelts the number of consecutive elements to create 
 * @param params the LWE parameters to use
 */
EXPORT TLweSample *new_TLweSample_array(int32_t nbelts, const TLweParams *params);

/** destroy and frees memory space for a single TLweSample 
 * @param ptr the pointer to release */
EXPORT void delete_TLweSample(TLweSample *obj);
/** destroys and free memory space for an array of TLweSample 
 * @param nbelts the number of elements 
 * @param ptr the pointer to release */
EXPORT void delete_TLweSample_array(int32_t nbelts, TLweSample *obj);


//-----------------------------------------------------------------
// autogenerated allocators/constructors/destructors declarations
// use code_autogen.pl TLweSampleFFT TLweParams to regenerate
//-----------------------------------------------------------------


/** allocate space for a single TLweSampleFFT */
EXPORT TLweSampleFFT *alloc_TLweSampleFFT();
/** allocate space for an array of TLweSampleFFT 
 * @param nbelts the number of elements */
EXPORT TLweSampleFFT *alloc_TLweSampleFFT_array(int32_t nbelts);

/** free memory space for a single TLweSampleFFT 
 * @param ptr the pointer to release */
EXPORT void free_TLweSampleFFT(TLweSampleFFT *ptr);
/** free memory space for an array of TLweSampleFFT 
 * @param nbelts the number of elements 
 * @param ptr the pointer to release */
EXPORT void free_TLweSampleFFT_array(int32_t nbelts, TLweSampleFFT *ptr);

/** initializes (constructor) a single TLweSampleFFT on an already allocated space 
 * @param ptr the pointer to the first element
 * @param params the LWE parameters to use
 */
EXPORT void init_TLweSampleFFT(TLweSampleFFT *ptr, const TLweParams *params);

/** initializes (constructor) an array of TLweSampleFFTs on an already allocated space 
 * @param nbelts the number of elements to initialize 
 * @param ptr the pointer to the first element
 * @param params the LWE parameters to use
 */
EXPORT void init_TLweSampleFFT_array(int32_t nbelts, TLweSampleFFT *ptr, const TLweParams *params);

/** finalizes (destructor) a single TLweSampleFFT (before freeing the memory space) 
 * @param ptr the pointer to the first element
 */
EXPORT void destroy_TLweSampleFFT(TLweSampleFFT *ptr);

/** finalizes (destructor) an array of TLweSampleFFTs (before freeing the memory space) 
 * @param nbelts the number of elements to initialize 
 * @param ptr the pointer to the first element
 */
EXPORT void destroy_TLweSampleFFT_array(int32_t nbelts, TLweSampleFFT *ptr);

/** allocates and initializes (constructor) a single TLweSampleFFT 
 * @param params the LWE parameters to use
 */
EXPORT TLweSampleFFT *new_TLweSampleFFT(const TLweParams *params);
/** allocates and initializes (constructor) a single TLweSampleFFT 
 * @param nbelts the number of consecutive elements to create 
 * @param params the LWE parameters to use
 */
EXPORT TLweSampleFFT *new_TLweSampleFFT_array(int32_t nbelts, const TLweParams *params);

/** destroy and frees memory space for a single TLweSampleFFT 
 * @param ptr the pointer to release */
EXPORT void delete_TLweSampleFFT(TLweSampleFFT *obj);
/** destroys and free memory space for an array of TLweSampleFFT 
 * @param nbelts the number of elements 
 * @param ptr the pointer to release */
EXPORT void delete_TLweSampleFFT_array(int32_t nbelts, TLweSampleFFT *obj);

#endif // RINGLWE_H

src/include/tgsw.h

结构体TGswParams、TGswKey、TGswSample、TGswSampleFFT ,定义了TGSW 结构的声明

#ifndef TGSW_H
#define TGSW_H

///@file
///@brief This file contains the declaration of TGSW structures
///该文件包含 TGSW 结构的声明

#include "tfhe_core.h"
#include "tlwe.h"

/// TGsw参数
struct TGswParams {
    const int32_t l; ///< 分解长度
    const int32_t Bgbit;///< log_2(分解基数Bg)
    const int32_t Bg;///< 分解基数(必须是 2 的幂)
    const int32_t halfBg; ///< 分解基数Bg/2
    const uint32_t maskMod; ///< 分解基数Bg-1
    const TLweParams *tlwe_params; ///< 每行的参数
    const int32_t kpl; ///< 行数 = (k+1)*l
    Torus32 *h; ///< Bgbit的幂
    uint32_t offset; ///< offset = Bg/2 * (2^(32-Bgbit) + 2^(32-2*Bgbit) + ... + 2^(32-l*Bgbit))

#ifdef __cplusplus

    TGswParams(int32_t l, int32_t Bgbit, const TLweParams *tlwe_params);

    ~TGswParams();

    TGswParams(const TGswParams &) = delete;

    void operator=(const TGswParams &) = delete;

#endif
};

/// TGsw密钥
struct TGswKey {
    const TGswParams *params; ///< 参数
    const TLweParams *tlwe_params; ///< 每行的 tlwe 参数
    IntPolynomial *key; ///< 密钥(k 个多项式的数组)
    TLweKey tlwe_key;

#ifdef __cplusplus

    TGswKey(const TGswParams *params);

    ~TGswKey();

    TGswKey(const TGswKey &) = delete;

    void operator=(const TGswKey &) = delete;

#endif
};

/// TGsw密文
struct TGswSample {
    TLweSample *all_sample; ///< TLwe密文* all_sample; (k+1)l TLwe密文
    TLweSample **bloc_sample;///< 可选择访问大小为 l 的不同块。
    // double current_variance;
    const int32_t k;
    const int32_t l;

#ifdef __cplusplus

    inline TGswSample(TLweSample *all_sample, TLweSample **bloc_sample, const int32_t k, const int32_t l) :
            all_sample(all_sample),
            bloc_sample(bloc_sample),
            k(k), l(l) {}

    inline ~TGswSample() {}

    TGswSample(const TGswSample &) = delete;

    void operator=(const TGswSample &) = delete;

#endif
};

/// TGsw密文FFT运算结构
struct TGswSampleFFT {
    TLweSampleFFT *all_samples; ///< TLwe密文* all_sample; (k+1)l TLwe密文
    TLweSampleFFT **sample; ///< 可选择访问大小为 l 的不同块。
    //double current_variance;
    const int32_t k;
    const int32_t l;

#ifdef __cplusplus

    TGswSampleFFT(const TGswParams *params, TLweSampleFFT *all_samples);

    ~TGswSampleFFT();

    TGswSampleFFT(const TGswSampleFFT &) = delete;

    void operator=(const TGswSampleFFT &) = delete;

#endif
};

//allocate memory space for a TGswKey
EXPORT TGswKey *alloc_TGswKey();
EXPORT TGswKey *alloc_TGswKey_array(int32_t nbelts);

//free memory space for a TGswKey
EXPORT void free_TGswKey(TGswKey *ptr);
EXPORT void free_TGswKey_array(int32_t nbelts, TGswKey *ptr);

//initialize the TGswKey structure
//(equivalent of the C++ constructor)
EXPORT void init_TGswKey(TGswKey *obj, const TGswParams *params);
EXPORT void init_TGswKey_array(int32_t nbelts, TGswKey *obj, const TGswParams *params);

//destroys the TGswKey structure
//(equivalent of the C++ destructor)
EXPORT void destroy_TGswKey(TGswKey *obj);
EXPORT void destroy_TGswKey_array(int32_t nbelts, TGswKey *obj);

//allocates and initialize the TGswKey structure
//(equivalent of the C++ new)
EXPORT TGswKey *new_TGswKey(const TGswParams *params);
EXPORT TGswKey *new_TGswKey_array(int32_t nbelts, const TGswParams *params);

//destroys and frees the TGswKey structure
//(equivalent of the C++ delete)
EXPORT void delete_TGswKey(TGswKey *obj);
EXPORT void delete_TGswKey_array(int32_t nbelts, TGswKey *obj);
//allocate memory space for a TGswParams
EXPORT TGswParams *alloc_TGswParams();
EXPORT TGswParams *alloc_TGswParams_array(int32_t nbelts);

//free memory space for a TGswParams
EXPORT void free_TGswParams(TGswParams *ptr);
EXPORT void free_TGswParams_array(int32_t nbelts, TGswParams *ptr);

//initialize the TGswParams structure
//(equivalent of the C++ constructor)
EXPORT void init_TGswParams(TGswParams *obj, int32_t l, int32_t Bgbit, const TLweParams *tlwe_params);
EXPORT void init_TGswParams_array(int32_t nbelts, TGswParams *obj, int32_t l, int32_t Bgbit, const TLweParams *tlwe_params);

//destroys the TGswParams structure
//(equivalent of the C++ destructor)
EXPORT void destroy_TGswParams(TGswParams *obj);
EXPORT void destroy_TGswParams_array(int32_t nbelts, TGswParams *obj);

//allocates and initialize the TGswParams structure
//(equivalent of the C++ new)
EXPORT TGswParams *new_TGswParams(int32_t l, int32_t Bgbit, const TLweParams *tlwe_params);
EXPORT TGswParams *new_TGswParams_array(int32_t nbelts, int32_t l, int32_t Bgbit, const TLweParams *tlwe_params);

//destroys and frees the TGswParams structure
//(equivalent of the C++ delete)
EXPORT void delete_TGswParams(TGswParams *obj);
EXPORT void delete_TGswParams_array(int32_t nbelts, TGswParams *obj);
//allocate memory space for a TGswSample
EXPORT TGswSample *alloc_TGswSample();
EXPORT TGswSample *alloc_TGswSample_array(int32_t nbelts);

//free memory space for a TGswSample
EXPORT void free_TGswSample(TGswSample *ptr);
EXPORT void free_TGswSample_array(int32_t nbelts, TGswSample *ptr);

//initialize the TGswSample structure
//(equivalent of the C++ constructor)
EXPORT void init_TGswSample(TGswSample *obj, const TGswParams *params);
EXPORT void init_TGswSample_array(int32_t nbelts, TGswSample *obj, const TGswParams *params);

//destroys the TGswSample structure
//(equivalent of the C++ destructor)
EXPORT void destroy_TGswSample(TGswSample *obj);
EXPORT void destroy_TGswSample_array(int32_t nbelts, TGswSample *obj);

//allocates and initialize the TGswSample structure
//(equivalent of the C++ new)
EXPORT TGswSample *new_TGswSample(const TGswParams *params);
EXPORT TGswSample *new_TGswSample_array(int32_t nbelts, const TGswParams *params);

//destroys and frees the TGswSample structure
//(equivalent of the C++ delete)
EXPORT void delete_TGswSample(TGswSample *obj);
EXPORT void delete_TGswSample_array(int32_t nbelts, TGswSample *obj);

//allocate memory space for a TGswSampleFFT
EXPORT TGswSampleFFT *alloc_TGswSampleFFT();
EXPORT TGswSampleFFT *alloc_TGswSampleFFT_array(int32_t nbelts);

//free memory space for a TGswSampleFFT
EXPORT void free_TGswSampleFFT(TGswSampleFFT *ptr);
EXPORT void free_TGswSampleFFT_array(int32_t nbelts, TGswSampleFFT *ptr);

//initialize the TGswSampleFFT structure
//(equivalent of the C++ constructor)
EXPORT void init_TGswSampleFFT(TGswSampleFFT *obj, const TGswParams *params);
EXPORT void init_TGswSampleFFT_array(int32_t nbelts, TGswSampleFFT *obj, const TGswParams *params);

//destroys the TGswSampleFFT structure
//(equivalent of the C++ destructor)
EXPORT void destroy_TGswSampleFFT(TGswSampleFFT *obj);
EXPORT void destroy_TGswSampleFFT_array(int32_t nbelts, TGswSampleFFT *obj);

//allocates and initialize the TGswSampleFFT structure
//(equivalent of the C++ new)
EXPORT TGswSampleFFT *new_TGswSampleFFT(const TGswParams *params);
EXPORT TGswSampleFFT *new_TGswSampleFFT_array(int32_t nbelts, const TGswParams *params);

//destroys and frees the TGswSampleFFT structure
//(equivalent of the C++ delete)
EXPORT void delete_TGswSampleFFT(TGswSampleFFT *obj);
EXPORT void delete_TGswSampleFFT_array(int32_t nbelts, TGswSampleFFT *obj);

#endif // TGSW_H

src/include/lwebootstrappingkey.h

结构体LweBootstrappingKey、LweBootstrappingKeyFFT,定义了bootstrappingkey的声明

#ifndef LweBOOTSTRAPPINGKEY_H
#define LweBOOTSTRAPPINGKEY_H

///@file
///@brief This file contains the declaration of bootstrapping key structures
///该文件包含bootstrappingkey的声明

#include "tfhe_core.h"

///lwe中bootstrapping密钥结构
struct LweBootstrappingKey{
    const LweParams* in_out_params; ///< 输入输出参数。 密钥:s
    const TGswParams* bk_params; ///< bk 中 Gsw 元素的参数。 密钥:s"
    const TLweParams* accum_params; ///< 累加变量密钥的参数:s"
    const LweParams* extract_params; ///< 提取后的参数:密钥:s'
    TGswSample* bk; ///< the bootstrapping key (s->s")
    LweKeySwitchKey* ks; ///< the keyswitch key (s'->s)


#ifdef __cplusplus
   LweBootstrappingKey(const LweParams* in_out_params, 
    const TGswParams* bk_params,
    const TLweParams* accum_params,
    const LweParams* extract_params,
    TGswSample* bk,
    LweKeySwitchKey* ks);
    ~LweBootstrappingKey();
    LweBootstrappingKey(const LweBootstrappingKey&) = delete;
    void operator=(const LweBootstrappingKey&) = delete;
  
#endif


};

///lwe中bootstrapping密钥FFT算法结构
struct LweBootstrappingKeyFFT {
    const LweParams* in_out_params; ///< 输入输出参数。 密钥: s
    const TGswParams* bk_params; ///< bk 中 Gsw 元素的参数. 密钥: s"
    const TLweParams* accum_params; ///< 累加变量密钥的参数: s"
    const LweParams* extract_params; ///< 提取之后的参数: 密钥: s' 
    const TGswSampleFFT* bkFFT; ///< the bootstrapping key (s->s")
    const LweKeySwitchKey* ks; ///< the keyswitch key (s'->s)


#ifdef __cplusplus
   LweBootstrappingKeyFFT(const LweParams* in_out_params, 
    const TGswParams* bk_params,
    const TLweParams* accum_params,
    const LweParams* extract_params, 
    const TGswSampleFFT* bkFFT,
    const LweKeySwitchKey* ks);
    ~LweBootstrappingKeyFFT();
    LweBootstrappingKeyFFT(const LweBootstrappingKeyFFT&) = delete;
    void operator=(const LweBootstrappingKeyFFT&) = delete;
  
#endif


};


//allocate memory space for a LweBootstrappingKey
EXPORT LweBootstrappingKey* alloc_LweBootstrappingKey();
EXPORT LweBootstrappingKey* alloc_LweBootstrappingKey_array(int32_t nbelts);

//free memory space for a LweBootstrappingKey
EXPORT void free_LweBootstrappingKey(LweBootstrappingKey* ptr);
EXPORT void free_LweBootstrappingKey_array(int32_t nbelts, LweBootstrappingKey* ptr);

//initialize the LweBootstrappingKey structure
//(equivalent of the C++ constructor)
EXPORT void init_LweBootstrappingKey(LweBootstrappingKey* obj, int32_t ks_t, int32_t ks_basebit, const LweParams* in_out_params, const TGswParams* bk_params);
EXPORT void init_LweBootstrappingKey_array(int32_t nbelts, LweBootstrappingKey* obj, int32_t ks_t, int32_t ks_basebit, const LweParams* in_out_params, const TGswParams* bk_params);

//destroys the LweBootstrappingKey structure
//(equivalent of the C++ destructor)
EXPORT void destroy_LweBootstrappingKey(LweBootstrappingKey* obj);
EXPORT void destroy_LweBootstrappingKey_array(int32_t nbelts, LweBootstrappingKey* obj);
 
//allocates and initialize the LweBootstrappingKey structure
//(equivalent of the C++ new)
EXPORT LweBootstrappingKey* new_LweBootstrappingKey(const int32_t ks_t, const int32_t ks_basebit, const LweParams* in_out_params, const TGswParams* bk_params);
EXPORT LweBootstrappingKey* new_LweBootstrappingKey_array(int32_t nbelts, const int32_t ks_t, const int32_t ks_basebit, const LweParams* in_out_params, const TGswParams* bk_params);

//destroys and frees the LweBootstrappingKey structure
//(equivalent of the C++ delete)
EXPORT void delete_LweBootstrappingKey(LweBootstrappingKey* obj);
EXPORT void delete_LweBootstrappingKey_array(int32_t nbelts, LweBootstrappingKey* obj);

//allocate memory space for a LweBootstrappingKeyFFT
EXPORT LweBootstrappingKeyFFT* alloc_LweBootstrappingKeyFFT();
EXPORT LweBootstrappingKeyFFT* alloc_LweBootstrappingKeyFFT_array(int32_t nbelts);

//free memory space for a LweBootstrappingKeyFFT
EXPORT void free_LweBootstrappingKeyFFT(LweBootstrappingKeyFFT* ptr);
EXPORT void free_LweBootstrappingKeyFFT_array(int32_t nbelts, LweBootstrappingKeyFFT* ptr);

//initialize the LweBootstrappingKeyFFT structure
//(equivalent of the C++ constructor)
EXPORT void init_LweBootstrappingKeyFFT(LweBootstrappingKeyFFT* obj, const LweBootstrappingKey* bk);
EXPORT void init_LweBootstrappingKeyFFT_array(int32_t nbelts, LweBootstrappingKeyFFT* obj, const LweBootstrappingKey* bk);

//destroys the LweBootstrappingKeyFFT structure
//(equivalent of the C++ destructor)
EXPORT void destroy_LweBootstrappingKeyFFT(LweBootstrappingKeyFFT* obj);
EXPORT void destroy_LweBootstrappingKeyFFT_array(int32_t nbelts, LweBootstrappingKeyFFT* obj);
 
//allocates and initialize the LweBootstrappingKeyFFT structure
//(equivalent of the C++ new)
EXPORT LweBootstrappingKeyFFT* new_LweBootstrappingKeyFFT(const LweBootstrappingKey* bk);
EXPORT LweBootstrappingKeyFFT* new_LweBootstrappingKeyFFT_array(int32_t nbelts, const LweBootstrappingKey* bk);

//destroys and frees the LweBootstrappingKeyFFT structure
//(equivalent of the C++ delete)
EXPORT void delete_LweBootstrappingKeyFFT(LweBootstrappingKeyFFT* obj);
EXPORT void delete_LweBootstrappingKeyFFT_array(int32_t nbelts, LweBootstrappingKeyFFT* obj);

#endif

src/include/polynomials.h

结构体IntPolynomial、TorusPolynomial、LagrangeHalfCPolynomial,包含多项式结构的声明

#ifndef POLYNOMIALS_H
#define POLYNOMIALS_H

///@file
///@brief This file contains the declaration of polynomials structures
///该文件包含多项式结构的声明

#include "tfhe_core.h"

/** 这个结构表示一个整数多项式模 X^N+1 */
struct IntPolynomial {
   const int32_t N;
   int32_t* coefs;

#ifdef __cplusplus   
   IntPolynomial(const int32_t N);
   ~IntPolynomial();
   IntPolynomial(const IntPolynomial&) = delete; //forbidden 
   IntPolynomial* operator=(const IntPolynomial&) = delete; //forbidden
#endif
};


/** 这个结构表示一个环面多项式模 X^N+1 */
struct TorusPolynomial {
   const int32_t N;
   Torus32* coefsT;

#ifdef __cplusplus   
   TorusPolynomial(const int32_t N);
   ~TorusPolynomial();
   TorusPolynomial(const TorusPolynomial&) = delete; //forbidden 
   TorusPolynomial* operator=(const TorusPolynomial&) = delete; //forbidden
#endif
};


/** 
 * This structure is used for FFT operations, and is a representation
 * over C of a polynomial in R[X]/X^N+1
 * This type is meant to be specialized, and all implementations of the structure must be compatible 
 * (reinterpret_cast) with this one. Namely, they should contain at most 2 pointers 
  * 此结构用于 FFT 运算,是一种表示
  * 在 R[X]/X^N+1 中的多项式的 C 上
  * 这种类型是特化的,结构的所有实现必须兼容
  * (reinterpret_cast) 这个。 即,它们最多应包含 2 个指针
 */
struct LagrangeHalfCPolynomial
{
   void* data;
   void* precomp;
};

//allocate memory space for a IntPolynomial
EXPORT IntPolynomial* alloc_IntPolynomial();
EXPORT IntPolynomial* alloc_IntPolynomial_array(int32_t nbelts);

//free memory space for a IntPolynomial
EXPORT void free_IntPolynomial(IntPolynomial* ptr);
EXPORT void free_IntPolynomial_array(int32_t nbelts, IntPolynomial* ptr);

//initialize the IntPolynomial structure
//(equivalent of the C++ constructor)
EXPORT void init_IntPolynomial(IntPolynomial* obj, const int32_t N);
EXPORT void init_IntPolynomial_array(int32_t nbelts, IntPolynomial* obj, const int32_t N);

//destroys the IntPolynomial structure
//(equivalent of the C++ destructor)
EXPORT void destroy_IntPolynomial(IntPolynomial* obj);
EXPORT void destroy_IntPolynomial_array(int32_t nbelts, IntPolynomial* obj);
 
//allocates and initialize the IntPolynomial structure
//(equivalent of the C++ new)
EXPORT IntPolynomial* new_IntPolynomial(const int32_t N);
EXPORT IntPolynomial* new_IntPolynomial_array(int32_t nbelts, const int32_t N);

//destroys and frees the IntPolynomial structure
//(equivalent of the C++ delete)
EXPORT void delete_IntPolynomial(IntPolynomial* obj);
EXPORT void delete_IntPolynomial_array(int32_t nbelts, IntPolynomial* obj);

//allocate memory space for a TorusPolynomial
EXPORT TorusPolynomial* alloc_TorusPolynomial();
EXPORT TorusPolynomial* alloc_TorusPolynomial_array(int32_t nbelts);

//free memory space for a TorusPolynomial
EXPORT void free_TorusPolynomial(TorusPolynomial* ptr);
EXPORT void free_TorusPolynomial_array(int32_t nbelts, TorusPolynomial* ptr);

//initialize the TorusPolynomial structure
//(equivalent of the C++ constructor)
EXPORT void init_TorusPolynomial(TorusPolynomial* obj, const int32_t N);
EXPORT void init_TorusPolynomial_array(int32_t nbelts, TorusPolynomial* obj, const int32_t N);

//destroys the TorusPolynomial structure
//(equivalent of the C++ destructor)
EXPORT void destroy_TorusPolynomial(TorusPolynomial* obj);
EXPORT void destroy_TorusPolynomial_array(int32_t nbelts, TorusPolynomial* obj);
 
//allocates and initialize the TorusPolynomial structure
//(equivalent of the C++ new)
EXPORT TorusPolynomial* new_TorusPolynomial(const int32_t N);
EXPORT TorusPolynomial* new_TorusPolynomial_array(int32_t nbelts, const int32_t N);

//destroys and frees the TorusPolynomial structure
//(equivalent of the C++ delete)
EXPORT void delete_TorusPolynomial(TorusPolynomial* obj);
EXPORT void delete_TorusPolynomial_array(int32_t nbelts, TorusPolynomial* obj);

//allocate memory space for a LagrangeHalfCPolynomial
EXPORT LagrangeHalfCPolynomial* alloc_LagrangeHalfCPolynomial();
EXPORT LagrangeHalfCPolynomial* alloc_LagrangeHalfCPolynomial_array(int32_t nbelts);

//free memory space for a LagrangeHalfCPolynomial
EXPORT void free_LagrangeHalfCPolynomial(LagrangeHalfCPolynomial* ptr);
EXPORT void free_LagrangeHalfCPolynomial_array(int32_t nbelts, LagrangeHalfCPolynomial* ptr);

//initialize the LagrangeHalfCPolynomial structure
//(equivalent of the C++ constructor)
EXPORT void init_LagrangeHalfCPolynomial(LagrangeHalfCPolynomial* obj, const int32_t N);
EXPORT void init_LagrangeHalfCPolynomial_array(int32_t nbelts, LagrangeHalfCPolynomial* obj, const int32_t N);

//destroys the LagrangeHalfCPolynomial structure
//(equivalent of the C++ destructor)
EXPORT void destroy_LagrangeHalfCPolynomial(LagrangeHalfCPolynomial* obj);
EXPORT void destroy_LagrangeHalfCPolynomial_array(int32_t nbelts, LagrangeHalfCPolynomial* obj);
 
//allocates and initialize the LagrangeHalfCPolynomial structure
//(equivalent of the C++ new)
EXPORT LagrangeHalfCPolynomial* new_LagrangeHalfCPolynomial(const int32_t N);
EXPORT LagrangeHalfCPolynomial* new_LagrangeHalfCPolynomial_array(int32_t nbelts, const int32_t N);

//destroys and frees the LagrangeHalfCPolynomial structure
//(equivalent of the C++ delete)
EXPORT void delete_LagrangeHalfCPolynomial(LagrangeHalfCPolynomial* obj);
EXPORT void delete_LagrangeHalfCPolynomial_array(int32_t nbelts, LagrangeHalfCPolynomial* obj);

#endif //POLYNOMIALS_H

src/include/tfhe_gate_bootstrapping_structures.h

结构体TFheGateBootstrappingParameterSet、TFheGateBootstrappingCloudKeySet 、TFheGateBootstrappingSecretKeySet ,门自举结构定义

#ifndef TFHE_GATE_BOOTSTRAPPING_STRUCTURES_H
#define TFHE_GATE_BOOTSTRAPPING_STRUCTURES_H

///@file
///@brief gate bootstrapping api structures definition
///门自举 API 结构定义

#include "tfhe_core.h"

// tfhe门自举参数集结构
struct TFheGateBootstrappingParameterSet {
    const int32_t ks_t;
    const int32_t ks_basebit;
    const LweParams *const in_out_params;
    const TGswParams *const tgsw_params;
#ifdef __cplusplus

    TFheGateBootstrappingParameterSet(const int32_t ks_t, const int32_t ks_basebit, const LweParams *const in_out_params,
                                      const TGswParams *const tgsw_params);

    TFheGateBootstrappingParameterSet(const TFheGateBootstrappingParameterSet &) = delete;

    void operator=(const TFheGateBootstrappingParameterSet &)= delete;

#endif
};

// tfhe门自举云密钥集结构
struct TFheGateBootstrappingCloudKeySet {
    const TFheGateBootstrappingParameterSet *const params;
    const LweBootstrappingKey *const bk;
    const LweBootstrappingKeyFFT *const bkFFT;
#ifdef __cplusplus

    TFheGateBootstrappingCloudKeySet(
            const TFheGateBootstrappingParameterSet *const params,
            const LweBootstrappingKey *const bk,
            const LweBootstrappingKeyFFT *const bkFFT);

    TFheGateBootstrappingCloudKeySet(const TFheGateBootstrappingCloudKeySet &) = delete;

    void operator=(const TFheGateBootstrappingCloudKeySet &)= delete;

#endif
};

// tfhe门自举密钥集结构
struct TFheGateBootstrappingSecretKeySet {
    const TFheGateBootstrappingParameterSet *params;
    const LweKey *lwe_key;
    const TGswKey *tgsw_key;
    const TFheGateBootstrappingCloudKeySet cloud;
#ifdef __cplusplus

    TFheGateBootstrappingSecretKeySet(
            const TFheGateBootstrappingParameterSet *const params,
            const LweBootstrappingKey *const bk,
            const LweBootstrappingKeyFFT *const bkFFT,
            const LweKey *lwe_key,
            const TGswKey *tgsw_key);

    TFheGateBootstrappingSecretKeySet(const TFheGateBootstrappingSecretKeySet &) = delete;

    void operator=(const TFheGateBootstrappingSecretKeySet &)= delete;

#endif
};

#endif //TFHE_GATE_BOOTSTRAPPING_STRUCTURES_H

刚刚接触TFHE不久,难免有出错的地方,请大家指正。

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值