Documentation ¶
Index ¶
- Variables
- type PrivateKey
- type PublicKey
- func (pk *PublicKey) CypherPlainAdd(cypher, plain *big.Int) *big.Int
- func (pk *PublicKey) CypherPlainMultiply(cypher, plain *big.Int) *big.Int
- func (pk *PublicKey) CypherPlainsAdd(cypher *big.Int, plains ...*big.Int) *big.Int
- func (pk *PublicKey) CyphersAdd(cyphers ...*big.Int) *big.Int
- func (publicKey *PublicKey) Encrypt(m *big.Int) (*big.Int, error)
- func (publicKey *PublicKey) EncryptSupNegNum(m *big.Int) (*big.Int, error)
Constants ¶
This section is empty.
Variables ¶
var ( // 质数p等于q ErrPrimePEqualsQ = errors.New("prime P should not equal Q") ErrMsgOutOfRange = errors.New("msg to be encrypted must within [0,N)") )
var (
DefaultPrimeLength = 512
)
Functions ¶
This section is empty.
Types ¶
type PrivateKey ¶
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 ¶
PublicKey 同态加解密公钥
func (*PublicKey) CypherPlainAdd ¶
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 ¶
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 ¶
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 ¶
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)