2021SC@SDUSC-PALISADE(十三)PALISADE库结构以及专用对象分析

2021SC@SDUSC
PALISADE库结构以及专用对象分析


PALISADE被设计为一个层结构,每一层都提供了一系列的服务给上一层,使用下一层提供的服务。每一层的接口都被设计为API,下面为具体层结构:

在这里插入图片描述

  • Application:所有调用了PALISADE lib的程序都在这一层

  • Encoding:所有数据编码方法的实现都在这一层

    编码层包含将原始明文(PlainText)消息转换成明文对象,以及在必要时解码回原文消息的类。编码层用来创建Plaintext对象

  • Crypto:所有加密协议的实现都在这一层。

  • Lattice Operations:所有高级的格密码数学构造都在这一层

  • Primitive Math::所有低级通用数学运算,如多精度运算,算术实现,在这一层。

1 元素类型

所有的PALISADE开源库内的操作都是强类型的,要加密的明文会创造一个知道明文格式的密文(Ciphertext)以及用来加密的特定的密钥,如果使用不正确的密文,解密操作将会失败。一次成功的解密将产生一个新的,其基本格式与传递给的初始明文相匹配的明文
加密。密文之间的同态操作和混合模式操作在密文和明文之间只允许在相同格式之间进行。

从palisade_manual.pdf的7.1节与7.13节中,我们了解到:

7.1 Typeing

All PALISADE operations are strongly typed. A Plaintext that is passed to encrypt will create a Ciphertext that is aware of the underlying format of the Plaintext, as well as the particular key that was used to encrypt the Plaintext. The decrypt operation will fail in cases where an improper key is used. A successful decrypt will produce a new Plaintext whose underlying format matches the initial Plaintext that was passed to encrypt. Homomorphic operations between Ciphertexts, and mixed-mode operations between a Ciphertext and a Plaintext will only be permitted for operands with formats and keys that match.

7.13 Element

The math layer performs operations on different kinds of Element. This is a representation of a vector in lattice space.

7.13.1 Poly

A Poly is a vector of polynomial coefficients. The coefficients are whatever the BigInteger type is for the selected math back-end, and the vector is simply a vector of these BigInteger, and an associated modulus. All operations on a Poly are done modulo this modulus.

7.13.2 NativePoly

A NativePoly is a vector of polynomial coefficients where each of the coefficients is of type 64-bit unsigned integer. The NativePoly also has a modulus of at most 64 bits (though our math implementations are most efficient for moduli of 60 bits or less). Again,all operations are done modulo the modulus.

7.13.3 DCRTPoly

A DCRTPoly implements a large Poly decomposed via residue arithmetic into a tower (set) of NativePoly element

翻译一下就是:所有的PALISADE开源库内的操作都是强类型的,要加密的明文会创造一个知道明文格式的密文(Ciphertext)以及用来加密的特定的密钥,如果使用不正确的密文,解密操作将会失败。一次成功的解密将产生一个新的,其基本格式与传递给的初始明文相匹配的明文加密。密文之间的同态操作和混合模式操作在密文和明文之间只允许在相同格式之间进行。

PALISADE中有三种元素的类型:

  • Poly:

    Poly是多项式系数的向量,系数的取值是后端选择的BigInteger。向量包括一个BigInteger类型的向量以及一个模数(modulus),所有在Poly类型上的操作都要模上这个模数。

  • NativePoly

    NativePloy与Poly唯一不同的一点就是,多项式的系数的取值是64-bits位的无符号整数。

  • DCRTPoly

    DCRTPoly,它将编码的明文表示为使用双中国余数定理的分解的堆栈NativePoly多项式。

2 CryptoContext

PALISADE的核心的类是CryptoContext类,该类是提供所有 PALISADE 加密功能的类。PALISADE 实现中使用的所有对象均由CryptoContext类创建。

PALISADE对象的所有操作必须在相同的属于CryptoContext类的对象上进行,加密明文(Plaintext)生成密文(Ciphertext)的过程如下:

在这里插入图片描述

我的另一篇博客分析的加密过程就是属于这个流程。每个的加密过程的CryptoContext都是独特的,由Scheme, Element type, ElementParams EncodingParams生成。因此如果一个人在两台电脑前创建具有相同的Scheme, Element type, ElementParams EncodingParamsCryptoContext,那么这两个CryptoContext应该是相同的。

3 PlainText

PALISADE中使用明文(PlainText)表示未加密的内容。它实际上是PALISADE中支持的每种可能的纯文本编码的基类:

• PackedEncoding

• CKKSPackedEncoding

• CoefPackedEncoding

• StringEncoding

明文的用途:

  • 创建明文PlainText是通过调用适当的CryptoContext类的方法,方法的参数是未加密的信息

  • 一旦创建,明文PlainText可以使用CryptoContextEncrypt方法加密为密文Ciphertext

  • PlainText还可以用作多个CryptoContext同态操作的参数,

  • 当密文Ciphertext被解密时,解密方法创建一个新的Plaintext来包含解密

明文有几个方法提供对明文中的信息的访问,在/core/include/encoding/plaintext.h中的319行:

  virtual const std::string& GetStringValue() const {
    PALISADE_THROW(type_error, "not a string");
  }
  virtual const vector<int64_t>& GetCoefPackedValue() const {
    PALISADE_THROW(type_error, "not a packed coefficient vector");
  }
  virtual const vector<int64_t>& GetPackedValue() const {
    PALISADE_THROW(type_error, "not a packed coefficient vector");
  }
  virtual const std::vector<std::complex<double>>& GetCKKSPackedValue() const {
    PALISADE_THROW(type_error, "not a packed vector of complex numbers");
  }
  virtual const std::vector<double> GetRealPackedValue() const {
    PALISADE_THROW(type_error, "not a packed vector of real numbers");
  }
  virtual void SetStringValue(const std::string&) {
    PALISADE_THROW(type_error, "does not support a string");
  }
  virtual void SetIntVectorValue(const vector<int64_t>&) {
    PALISADE_THROW(type_error, "does not support an int vector");
  }

明文PlainText类中对明文的编码类型(PlaintextEncodings)、明文的元素类型都有定义:

enum PlaintextEncodings {
  Unknown = 0,
  CoefPacked,
  Packed,
  String,
  CKKSPacked,
};

enum PtxtPolyType { IsPoly, IsDCRTPoly, IsNativePoly };

class PlaintextImpl {
 protected:
  //是否被编码
  bool isEncoded;
  //元素类型
  PtxtPolyType typeFlag;
  //编码参数  
  EncodingParams encodingParams;
}

4 Ciphertext

Ciphertext对象在PALISADE中代表的是解密过的信息,Ciphertext是由PlainText明文对象通过解密方法创建的,然后再通过解密方法转回PlainText明文对象,加密encrypt和解密encrypt方法需要的KeysCryptoContext生成

如果操作数的编码匹配,则支持密文Ciphertext对之间或密文Ciphertext与明文PlainText之间的同态操作。并且这些编码支持同态操作(例如。同态操作不支持字符串编码,如果尝试将被拒绝)。

利用ABEContextCP-ABE/GPV IBE方案有自己独特的用于密文实现的类,这些类目前不支持同态操作。

5 ElementParams

ElementParams是一个容器,用于存放正在使用的任何元素的配置参数。结构参数包括环的维数( ring dimension)、切圆次序( cyclotomic order)和单位的基元根。

6 EncodingParams

EncodingParams是一个容器,用于存放编码明文所需要的所有参数。在大多数情况下,这只包含一个明文模数(plaintext modulus),然而,有些编码需要更详细的参数。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sunburst7

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值