forked from tuneinsight/lattigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ckks.go
74 lines (68 loc) · 2.35 KB
/
ckks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Package ckks implements a RNS-accelerated version of the Homomorphic Encryption for Arithmetic for Approximate Numbers
// (HEAAN, a.k.a. CKKS) scheme. It provides approximate arithmetic over the complex numbers.package ckks
package ckks
import (
"github.com/tuneinsight/lattigo/v5/core/rlwe"
)
// NewPlaintext allocates a new rlwe.Plaintext.
//
// inputs:
// - params: an rlwe.ParameterProvider interface
// - level: the level of the plaintext
//
// output: a newly allocated rlwe.Plaintext at the specified level.
//
// Note: the user can update the field `MetaData` to set a specific scaling factor,
// plaintext dimensions (if applicable) or encoding domain, before encoding values
// on the created plaintext.
func NewPlaintext(params Parameters, level int) (pt *rlwe.Plaintext) {
pt = rlwe.NewPlaintext(params, level)
pt.IsBatched = true
pt.Scale = params.DefaultScale()
pt.LogDimensions = params.LogMaxDimensions()
return
}
// NewCiphertext allocates a new rlwe.Ciphertext.
//
// inputs:
// - params: an rlwe.ParameterProvider interface
// - degree: the degree of the ciphertext
// - level: the level of the Ciphertext
//
// output: a newly allocated rlwe.Ciphertext of the specified degree and level.
func NewCiphertext(params Parameters, degree, level int) (ct *rlwe.Ciphertext) {
ct = rlwe.NewCiphertext(params, degree, level)
ct.IsBatched = true
ct.Scale = params.DefaultScale()
ct.LogDimensions = params.LogMaxDimensions()
return
}
// NewEncryptor instantiates a new rlwe.Encryptor.
//
// inputs:
// - params: an rlwe.ParameterProvider interface
// - key: *rlwe.SecretKey or *rlwe.PublicKey
//
// output: an rlwe.Encryptor instantiated with the provided key.
func NewEncryptor(params Parameters, key rlwe.EncryptionKey) *rlwe.Encryptor {
return rlwe.NewEncryptor(params, key)
}
// NewDecryptor instantiates a new rlwe.Decryptor.
//
// inputs:
// - params: an rlwe.ParameterProvider interface
// - key: *rlwe.SecretKey
//
// output: an rlwe.Decryptor instantiated with the provided key.
func NewDecryptor(params Parameters, key *rlwe.SecretKey) *rlwe.Decryptor {
return rlwe.NewDecryptor(params, key)
}
// NewKeyGenerator instantiates a new rlwe.KeyGenerator.
//
// inputs:
// - params: an rlwe.ParameterProvider interface
//
// output: an rlwe.KeyGenerator.
func NewKeyGenerator(params Parameters) *rlwe.KeyGenerator {
return rlwe.NewKeyGenerator(params)
}