paillier

package
v0.0.0-...-aafbcf9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 质数p等于q
	ErrPrimePEqualsQ = errors.New("prime P should not equal Q")
	ErrMsgOutOfRange = errors.New("msg to be encrypted must within [0,N)")
)
View Source
var (
	DefaultPrimeLength = 512
)

Functions

This section is empty.

Types

type PrivateKey

type PrivateKey struct {
	PublicKey
	Lambda *big.Int // λ
	Mu     *big.Int // μ
}

PrivateKey 同态加解密私钥

func GeneratePrivateKey

func GeneratePrivateKey(primeLength int) (*PrivateKey, error)

GeneratePrivateKey 生成同态加密公私钥 通过指定比特长度来保证产生的质数p和q的长度相同,以便采取快速方法来构造公钥和私钥

func (*PrivateKey) Decrypt

func (privateKey *PrivateKey) Decrypt(cypher *big.Int) *big.Int

Decrypt 解密数据 - 正数 Compute the plaintext message as: m = L(c^λ mod(n^2)) * μ mod(n), L(x) = (x-1)/n

func (*PrivateKey) DecryptSupNegNum

func (privateKey *PrivateKey) DecryptSupNegNum(cypher *big.Int) *big.Int

DecryptSupNegNum 解密数据 - 负数 Compute the plaintext message as: m = D(c) = L(c^λ mod(n^2)) * μ mod(n), L(x) = (x-1)/n Decryption is modified to D′(c)=[D(c)]n with by definition [x]n = ((x+(n/2))mod(n) − (n/2).

type PublicKey

type PublicKey struct {
	N *big.Int
	G *big.Int
}

PublicKey 同态加解密公钥

func (*PublicKey) CypherPlainAdd

func (pk *PublicKey) CypherPlainAdd(cypher, plain *big.Int) *big.Int

CypherPlainAdd 密文与原文的加法 The product of a ciphertext with a plaintext raising g will decrypt to the sum of the corresponding plaintexts D(E(m1,r1)*g^m2 mod(n^2)) = m1+m2 mod(n)

func (*PublicKey) CypherPlainMultiply

func (pk *PublicKey) CypherPlainMultiply(cypher, plain *big.Int) *big.Int

CypherPlainMultiply 密文与原文的乘法 An encrypted plaintext raised to a constant k will decrypt to the product of the plaintext and the constant D(E(m,r)^k mod(n^2) = k*m mod(n)

func (*PublicKey) CypherPlainsAdd

func (pk *PublicKey) CypherPlainsAdd(cypher *big.Int, plains ...*big.Int) *big.Int

CypherPlainsAdd 密文与原文的加法 The product of a ciphertext with a plaintext raising g will decrypt to the sum of the corresponding plaintexts D(E(m1,r1)*g^m2 mod(n^2)) = m1+m2 mod(n)

func (*PublicKey) CyphersAdd

func (pk *PublicKey) CyphersAdd(cyphers ...*big.Int) *big.Int

CyphersAdd 纯密文加法 The product of two ciphertexts will decrypt to the sum of their corresponding plaintexts D(E(m1,r1)*E(m2,r2) mod(n^2)) = m1+m2 mod(n)

func (*PublicKey) Encrypt

func (publicKey *PublicKey) Encrypt(m *big.Int) (*big.Int, error)

Encrypt 加密正数 1. Let m be a message to be encrypted where 0<=m<n 2. Select a random number r where 0<r<n and ensure gcd(r,n)=1 3. Compute ciphertext as: c = g^m * r^n mod(n^2) 符号表示:E(m1,r1)

func (*PublicKey) EncryptSupNegNum

func (publicKey *PublicKey) EncryptSupNegNum(m *big.Int) (*big.Int, error)

EncryptSupNegNum 加密负数

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL