The secret key. More...
#include <keys.h>

Public Member Functions | |
SecKey ()=delete | |
~SecKey () override=default | |
SecKey (const Context &_context) | |
bool | operator== (const SecKey &other) const |
bool | operator!= (const SecKey &other) const |
void | clear () override |
Clear all secret-key data. More... | |
long | ImportSecKey (const DoubleCRT &sKey, double bound, long ptxtSpace=0, long maxDegKswitch=3) |
long | GenSecKey (long ptxtSpace=0, long maxDegKswitch=3) |
void | GenKeySWmatrix (long fromSPower, long fromXPower, long fromKeyIdx=0, long toKeyIdx=0, long ptxtSpace=0) |
void | Decrypt (NTL::ZZX &plaintxt, const Ctxt &ciphertxt) const |
template<typename Scheme > | |
void | Decrypt (Ptxt< Scheme > &plaintxt, const Ctxt &ciphertxt, OptLong prec=OptLong()) const |
Decrypt a ciphertext into a plaintext. More... | |
void | Decrypt (NTL::ZZX &plaintxt, const Ctxt &ciphertxt, NTL::ZZX &f) const |
Debugging version, returns in f the polynomial before reduction modulo the ptxtSpace. More... | |
long | skEncrypt (Ctxt &ctxt, const NTL::ZZX &ptxt, long ptxtSpace, long skIdx) const |
Symmetric encryption using the secret key. More... | |
long | skEncrypt (Ctxt &ctxt, const zzX &ptxt, long ptxtSpace, long skIdx) const |
long | Encrypt (Ctxt &ciphertxt, const NTL::ZZX &plaintxt, long ptxtSpace=0) const override |
long | Encrypt (Ctxt &ciphertxt, const zzX &plaintxt, long ptxtSpace=0) const override |
virtual void | Encrypt (Ctxt &ctxt, const EncodedPtxt &eptxt) const override |
virtual void | Encrypt (Ctxt &ctxt, const EncodedPtxt_BGV &eptxt) const override |
virtual void | Encrypt (Ctxt &ctxt, const EncodedPtxt_CKKS &eptxt) const override |
long | genRecryptData () |
Generate bootstrapping data if needed, returns index of key. More... | |
const DoubleCRT & | getRecryptKey () const |
Getter method for the recryption key. More... | |
void | writeTo (std::ostream &str) const |
Write out the SecKey object in binary format. More... | |
void | writeToJSON (std::ostream &str) const |
Write out the secret key (SecKey ) object to the output stream using JSON format. More... | |
JsonWrapper | writeToJSON () const |
Write out the secret key (SecKey ) object to a JsonWrapper . More... | |
void | readJSON (std::istream &str) |
Read from the stream the serialized secret key (SecKey ) object using JSON format. More... | |
void | readJSON (const JsonWrapper &j) |
Read from the JsonWrapper the serialized secret key (SecKey ) object. More... | |
std::ostream & | writeSecKeyDerivedASCII (std::ostream &str) const |
template<> | |
void | Decrypt (Ptxt< BGV > &plaintxt, const Ctxt &ciphertxt, UNUSED OptLong prec) const |
template<> | |
void | Decrypt (Ptxt< CKKS > &plaintxt, const Ctxt &ciphertxt, OptLong prec) const |
![]() | |
PubKey ()=delete | |
PubKey (const Context &_context) | |
PubKey (const PubKey &other) | |
Copy constructor. More... | |
virtual | ~PubKey ()=default |
Default destructor. More... | |
bool | operator== (const PubKey &other) const |
bool | operator!= (const PubKey &other) const |
const Context & | getContext () const |
long | getPtxtSpace () const |
bool | keyExists (long keyID) const |
double | getSKeyBound (long keyID=0) const |
The size of the secret key. More... | |
bool | isReachable (long k, long keyID=0) const |
Is it possible to re-linearize the automorphism X -> X^k See Section 3.2.2 in the design document (KeySwitchMap) More... | |
void | setKeySwitchMap (long keyId=0) |
Compute the reachability graph of key-switching matrices See Section 3.2.2 in the design document (KeySwitchMap) More... | |
long | getKSStrategy (long dim) const |
get KS strategy for dimension dim dim == -1 is Frobenius More... | |
void | setKSStrategy (long dim, int val) |
set KS strategy for dimension dim dim == -1 is Frobenius More... | |
long | Encrypt (Ctxt &ciphertxt, const NTL::ZZX &plaintxt, long ptxtSpace, bool highNoise) const |
long | Encrypt (Ctxt &ciphertxt, const zzX &plaintxt, long ptxtSpace, bool highNoise) const |
void | CKKSencrypt (Ctxt &ciphertxt, const NTL::ZZX &plaintxt, double ptxtSize=1.0, double scaling=0.0) const |
void | CKKSencrypt (Ctxt &ciphertxt, const zzX &plaintxt, double ptxtSize=1.0, double scaling=0.0) const |
template<typename Scheme > | |
void | Encrypt (Ctxt &ciphertxt, const Ptxt< Scheme > &plaintxt) const |
Encrypts a plaintext into a ciphertext. More... | |
bool | isCKKS () const |
bool | isBootstrappable () const |
void | reCrypt (Ctxt &ctxt) const |
void | thinReCrypt (Ctxt &ctxt) const |
void | writeTo (std::ostream &str) const |
Write out the PubKey object in binary format. More... | |
void | writeToJSON (std::ostream &str) const |
Write out the public key (PubKey ) object to the output stream using JSON format. More... | |
JsonWrapper | writeToJSON () const |
Write out the public key (PubKey ) object to a JsonWrapper . More... | |
void | readJSON (std::istream &str) |
In-place read from the stream the serialized public key (PubKey ) object using JSON format. More... | |
void | readJSON (const JsonWrapper &j) |
In-place read from the JsonWrapper the serialized public key (PubKey ) object. More... | |
void | hackPtxtSpace (long p2r) |
template<> | |
void | Encrypt (Ctxt &ciphertxt, const Ptxt< BGV > &plaintxt) const |
template<> | |
void | Encrypt (Ctxt &ciphertxt, const Ptxt< CKKS > &plaintxt) const |
const std::vector< KeySwitch > & | keySWlist () const |
const KeySwitch & | getKeySWmatrix (const SKHandle &from, long toID=0) const |
Find a key-switching matrix by its indexes. If no such matrix exists it returns a dummy matrix with toKeyID==-1. More... | |
const KeySwitch & | getKeySWmatrix (long fromSPower, long fromXPower, long fromID=0, long toID=0) const |
bool | haveKeySWmatrix (const SKHandle &from, long toID=0) const |
bool | haveKeySWmatrix (long fromSPower, long fromXPower, long fromID=0, long toID=0) const |
const KeySwitch & | getAnyKeySWmatrix (const SKHandle &from) const |
Is there a matrix from this key to any base key? More... | |
bool | haveAnyKeySWmatrix (const SKHandle &from) const |
const KeySwitch & | getNextKSWmatrix (long fromXPower, long fromID=0) const |
Get the next matrix to use for multi-hop automorphism See Section 3.2.2 in the design document. More... | |
Static Public Member Functions | |
static SecKey | readFrom (std::istream &str, const Context &context) |
Read from the stream the serialized SecKey object in binary format. More... | |
static SecKey | readFromJSON (std::istream &str, const Context &context) |
Read from the stream the serialized secret key (SecKey ) object using JSON format. More... | |
static SecKey | readFromJSON (const JsonWrapper &j, const Context &context) |
Read from the JsonWrapper the serialized secret key (SecKey ) object. More... | |
![]() | |
static PubKey | readFrom (std::istream &str, const Context &context) |
Read from the stream the serialized PubKey object in binary format. More... | |
static PubKey | readFromJSON (std::istream &str, const Context &context) |
Read from the stream the serialized public key (PubKey ) object using JSON format. More... | |
static PubKey | readFromJSON (const JsonWrapper &j, const Context &context) |
Read from the JsonWrapper the serialized public key (PubKey ) object. More... | |
static long | ePlusR (long p) |
Static Public Attributes | |
static constexpr std::string_view | typeName = "SecKey" |
Class label to be added to JSON serialization as object type information. More... | |
![]() | |
static constexpr std::string_view | typeName = "PubKey" |
Class label to be added to JSON serialization as object type information. More... | |
Friends | |
class | KeySwitch |
std::ostream & | operator<< (std::ostream &str, const SecKey &sk) |
std::istream & | operator>> (std::istream &str, SecKey &sk) |
Detailed Description
The secret key.
Constructor & Destructor Documentation
◆ SecKey() [1/2]
|
delete |
◆ ~SecKey()
|
overridedefault |
◆ SecKey() [2/2]
|
explicit |
Member Function Documentation
◆ clear()
|
overridevirtual |
Clear all secret-key data.
Reimplemented from helib::PubKey.
◆ Decrypt() [1/5]
void helib::SecKey::Decrypt | ( | NTL::ZZX & | plaintxt, |
const Ctxt & | ciphertxt | ||
) | const |
◆ Decrypt() [2/5]
void helib::SecKey::Decrypt | ( | NTL::ZZX & | plaintxt, |
const Ctxt & | ciphertxt, | ||
NTL::ZZX & | f | ||
) | const |
Debugging version, returns in f the polynomial before reduction modulo the ptxtSpace.
◆ Decrypt() [3/5]
void helib::SecKey::Decrypt | ( | Ptxt< BGV > & | plaintxt, |
const Ctxt & | ciphertxt, | ||
UNUSED OptLong | prec | ||
) | const |
◆ Decrypt() [4/5]
void helib::SecKey::Decrypt | ( | Ptxt< CKKS > & | plaintxt, |
const Ctxt & | ciphertxt, | ||
OptLong | prec | ||
) | const |
◆ Decrypt() [5/5]
◆ Encrypt() [1/5]
|
overridevirtual |
Reimplemented from helib::PubKey.
◆ Encrypt() [2/5]
|
overridevirtual |
Reimplemented from helib::PubKey.
◆ Encrypt() [3/5]
|
overridevirtual |
Reimplemented from helib::PubKey.
◆ Encrypt() [4/5]
|
overridevirtual |
Reimplemented from helib::PubKey.
◆ Encrypt() [5/5]
|
overridevirtual |
Reimplemented from helib::PubKey.
◆ GenKeySWmatrix()
void helib::SecKey::GenKeySWmatrix | ( | long | fromSPower, |
long | fromXPower, | ||
long | fromKeyIdx = 0 , |
||
long | toKeyIdx = 0 , |
||
long | ptxtSpace = 0 |
||
) |
Generate a key-switching matrix and store it in the public key. The i'th column of the matrix encrypts fromKey*B1*B2*...*B{i-1}*Q under toKey, relative to the largest modulus (i.e., all primes) and plaintext space p. Q is the product of special primes, and the Bi's are the products of primes in the i'th digit. The plaintext space defaults to 2^r, as defined by context.mod2r.
◆ genRecryptData()
long helib::SecKey::genRecryptData | ( | ) |
Generate bootstrapping data if needed, returns index of key.
◆ GenSecKey()
long helib::SecKey::GenSecKey | ( | long | ptxtSpace = 0 , |
long | maxDegKswitch = 3 |
||
) |
Key generation: This procedure generates a single secret key, pushes it onto the sKeys list using ImportSecKey from above.
◆ getRecryptKey()
|
inline |
Getter method for the recryption key.
- Returns
- A
const
reference to the recryption key.
◆ ImportSecKey()
long helib::SecKey::ImportSecKey | ( | const DoubleCRT & | sKey, |
double | bound, | ||
long | ptxtSpace = 0 , |
||
long | maxDegKswitch = 3 |
||
) |
We allow the calling application to choose a secret-key polynomial by itself, then insert it into the SecKey object, getting the index of that secret key in the sKeys list. If this is the first secret-key for this object then the procedure below also generates a corresponding public encryption key. It is assumed that the context already contains all parameters.
◆ operator!=()
bool helib::SecKey::operator!= | ( | const SecKey & | other | ) | const |
◆ operator==()
bool helib::SecKey::operator== | ( | const SecKey & | other | ) | const |
◆ readFrom()
◆ readFromJSON() [1/2]
|
static |
Read from the JsonWrapper
the serialized secret key (SecKey
) object.
- Parameters
-
j The JsonWrapper
containing the serializedSecKey
object.context The Context
to be used.
- Returns
- The deserialized
SecKey
object.
◆ readFromJSON() [2/2]
◆ readJSON() [1/2]
void helib::SecKey::readJSON | ( | const JsonWrapper & | j | ) |
Read from the JsonWrapper
the serialized secret key (SecKey
) object.
- Parameters
-
j The JsonWrapper
containing the serializedSecKey
object.
◆ readJSON() [2/2]
void helib::SecKey::readJSON | ( | std::istream & | str | ) |
Read from the stream the serialized secret key (SecKey
) object using JSON format.
- Parameters
-
str Input std::istream
.
◆ skEncrypt() [1/2]
long helib::SecKey::skEncrypt | ( | Ctxt & | ctxt, |
const NTL::ZZX & | ptxt, | ||
long | ptxtSpace, | ||
long | skIdx | ||
) | const |
Symmetric encryption using the secret key.
◆ skEncrypt() [2/2]
◆ writeSecKeyDerivedASCII()
std::ostream & helib::SecKey::writeSecKeyDerivedASCII | ( | std::ostream & | str | ) | const |
◆ writeTo()
void helib::SecKey::writeTo | ( | std::ostream & | str | ) | const |
Write out the SecKey
object in binary format.
- Parameters
-
str Output std::ostream
.
◆ writeToJSON() [1/2]
JsonWrapper helib::SecKey::writeToJSON | ( | ) | const |
Write out the secret key (SecKey
) object to a JsonWrapper
.
- Returns
- The
JsonWrapper
.
◆ writeToJSON() [2/2]
void helib::SecKey::writeToJSON | ( | std::ostream & | str | ) | const |
Write out the secret key (SecKey
) object to the output stream using JSON format.
- Parameters
-
str Output std::ostream
.
Friends And Related Function Documentation
◆ KeySwitch
|
friend |
◆ operator<<
|
friend |
◆ operator>>
|
friend |
Member Data Documentation
◆ typeName
|
staticconstexpr |
Class label to be added to JSON serialization as object type information.