Methods
# add(a, b, destinationopt) → {CipherText|void}
Adds two CipherTexts. This function adds together a and b
and stores the result in the destination parameter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a |
CipherText
|
CipherText operand A | |
b |
CipherText
|
CipherText operand B | |
destination |
CipherText
|
<optional> |
CipherText destination to store the sum |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const cipherTextA = seal.CipherText()
const cipherTextB = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.add(cipherTextA, cipherTextB)
// or
const cipherDest = seal.CipherText()
evaluator.add(cipherTextA, cipherTextB, cipherDest)
# addPlain(encrypted, plain, destinationopt, poolopt) → {CipherText|void}
Adds a CipherText and a PlainText. This function adds a CipherText and
a PlainText and stores the result in the destination parameter. The PlainText
must be valid for the current encryption parameters.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText operand A | ||
plain |
PlainText
|
PlainText operand B | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the sum | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const cipherTextA = seal.CipherText()
const plainTextB = seal.PlainText()
// ... after encrypting/encoding some data ...
const resultCipher = evaluator.addPlain(cipherTextA, plainTextB)
// or
const cipherDest = seal.CipherText()
evaluator.addPlain(cipherTextA, plainTextB, cipherDest)
# applyGalois(encrypted, galoisElt, galoisKeys, destinationopt, poolopt) → {CipherText|void}
Applies a Galois automorphism to a CipherText and writes the result to the
destination parameter. To evaluate the Galois automorphism, an appropriate
set of Galois keys must also be provided. Dynamic memory allocations in
the process are allocated from the memory pool pointed to by the given
MemoryPoolHandle.
The desired Galois automorphism is given as a Galois element, and must be
an odd integer in the interval [1, M-1], where M = 2*N, and N = degree(poly_modulus).
Used with batching, a Galois element 3^i % M corresponds to a cyclic row
rotation i steps to the left, and a Galois element 3^(N/2-i) % M corresponds
to a cyclic row rotation i steps to the right. The Galois element M-1 corresponds
to a column rotation (row swap) in BFV, and complex conjugation in CKKS.
In the polynomial view (not batching), a Galois automorphism by a Galois
element p changes Enc(plain(x)) to Enc(plain(x^p)).
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to apply the automorphism | ||
galoisElt |
number
|
number representing the Galois element | ||
galoisKeys |
GaloisKeys
|
GaloisKeys used to perform rotations | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
...
const evaluator = seal.Evaluator(context)
const arr = Int32Array.from({ length: encoder.slotCount }, (_, i) => i)
const plain = encoder.encode(arr)
const cipher = encryptor.encrypt(plain)
const cipherDest = seal.CipherText()
const galElt = 2 * parms.polyModulusDegree - 1
evaluator.applyGalois(cipher, galElt, galoisKeys, cipherDest)
# cipherModSwitchTo(encrypted, parmsId, destinationopt, poolopt) → {CipherText|void}
Given a CipherText encrypted modulo q_1...q_k, this function switches the
modulus down until the parameters reach the given parmsId and stores the
result in the destination parameter. Dynamic memory allocations in the process
are allocated from the memory pool pointed to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to switch its modulus down | ||
parmsId |
ParmsIdType
|
Target parmsId to switch to | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the switched result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const context = seal.Context(encParms, true)
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const parmsId = context.lastParmsId
const resultCipher = evaluator.cipherModSwitchTo(cipherTextA, parmsId)
// or
const cipherDest = seal.CipherText()
evaluator.cipherModSwitchTo(cipherTextA, parmsId, cipherDest)
# cipherModSwitchToNext(encrypted, destinationopt, poolopt) → {CipherText|void}
Given a CipherText encrypted modulo q_1...q_k, this function switches the
modulus down to q_1...q_{k-1} and stores the result in the destination
parameter. Dynamic memory allocations in the process are allocated from
the memory pool pointed to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to switch its modulus down | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the switched result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.cipherModSwitchToNext(cipherTextA)
// or
const cipherDest = seal.CipherText()
evaluator.cipherModSwitchToNext(cipherTextA, cipherDest)
# cipherTransformFromNtt(encryptedNtt, destinationopt) → {CipherText|void}
Transforms a CipherText back from NTT domain. This functions applies the
inverse of David Harvey's number Theoretic Transform separately to each
polynomial of a CipherText. The result is stored in the destination parameter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
encryptedNtt |
CipherText
|
CipherText to transform | |
destination |
CipherText
|
<optional> |
CipherText destination to store the transformed result |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
// ... after cipherTransformToNtt ...
const resultCipher = evaluator.cipherTransformFromNtt(cipherTextANtt)
// or
const cipherDest = seal.CipherText()
evaluator.cipherTransformFromNtt(cipherTextANtt, cipherDest)
# cipherTransformToNtt(encrypted, destinationNttopt) → {CipherText|void}
Transforms a CipherText to NTT domain. This functions applies David Harvey's
number Theoretic Transform separately to each polynomial of a CipherText.
The result is stored in the destinationNtt parameter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
encrypted |
CipherText
|
CipherText to transform | |
destinationNtt |
CipherText
|
<optional> |
CipherText destination to store the transformed result |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.cipherTransformToNtt(cipherTextA)
// or
const cipherDest = seal.CipherText()
evaluator.cipherTransformToNtt(cipherTextA, cipherDest)
# complexConjugate(encrypted, galoisKeys, destinationopt, poolopt) → {CipherText|void}
Complex conjugates PlainText slot values. When using the CKKS scheme, this
function complex conjugates all values in the underlying PlainText, and
writes the result to the destination parameter. Dynamic memory allocations
in the process are allocated from the memory pool pointed to by the given
MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to complex conjugate | ||
galoisKeys |
GaloisKeys
|
GaloisKeys used to perform rotations | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the conjugated result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const galoisKeys = keyGenerator.createGaloisKeys()
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.complexConjugate(cipherTextA, galoisKeys)
// or
const cipherDest = seal.CipherText()
evaluator.complexConjugate(cipherTextA, galoisKeys, cipherDest)
# delete()
Delete the underlying WASM instance.
Should be called before dereferencing this object to prevent the
WASM heap from growing indefinitely.
# dotProduct(a, b, relinKeys, galoisKeys, scheme, destinationopt, poolopt) → {CipherText|void}
Perform the dot product (A.B) of two CipherTexts The resulting CipherText contains the dot product in every
element.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
a |
CipherText
|
CipherText operand A | ||
b |
CipherText
|
CipherText operand B | ||
relinKeys |
RelinKeys
|
RelinKeys used to perform relinearization after multiplication | ||
galoisKeys |
GaloisKeys
|
GaloisKeys used to perform rotations | ||
scheme |
SchemeType
|
Scheme that was used for encryption | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const relinKeys = keyGenerator.createRelinKeys()
const galoisKeys = keyGenerator.createGaloisKeys()
const cipherTextA = seal.CipherText()
const cipherTextB = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.dotProduct(cipherTextA, cipherTextB, relinKeys, galoisKeys, seal.SchemeTypes.BFV)
// or
const cipherDest = seal.CipherText()
evaluator.dotProduct(cipherTextA, cipherTextB, relinKeys, galoisKeys, seal.SchemeTypes.BFV, cipherDest)
# dotProductPlain(a, b, galoisKeys, scheme, destinationopt, poolopt) → {CipherText|void}
Perform the dot product (A.B) of CipherText (A) and PlainText (B). The resulting CipherText contains the dot
product in every element.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
a |
CipherText
|
CipherText operand A | ||
b |
PlainText
|
PlainText operand B | ||
galoisKeys |
GaloisKeys
|
GaloisKeys used to perform rotations | ||
scheme |
SchemeType
|
Scheme that was used for encryption | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const galoisKeys = keyGenerator.createGaloisKeys()
const cipherTextA = seal.CipherText()
const plainTextB = seal.PlainText()
// ... after encoding / encrypting some data ...
const resultCipher = evaluator.dotProductPlain(cipherTextA, plainTextB, galoisKeys, seal.SchemeTypes.BFV)
// or
const cipherDest = seal.CipherText()
evaluator.dotProductPlain(cipherTextA, plainTextB, galoisKeys, seal.SchemeTypes.BFV, cipherDest)
# exponentiate(encrypted, exponent, relinKeys, destinationopt, poolopt) → {CipherText|void}
Exponentiates a CipherText. This functions raises encrypted to a power and
stores the result in the destination parameter. Dynamic memory allocations
in the process are allocated from the memory pool pointed to by the given
MemoryPoolHandle. The exponentiation is done in a depth-optimal order, and
relinearization is performed automatically after every multiplication in
the process. In relinearization the given relinearization keys are used.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to exponentiate | ||
exponent |
number
|
Positive integer to exponentiate the CipherText | ||
relinKeys |
RelinKeys
|
RelinKeys used to perform relinearization after each exponentiation | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the exponentiated result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const relinKeys = keyGenerator.createRelinKeys()
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.exponentiate(cipherTextA, 3, relinKeys)
// or
const cipherDest = seal.CipherText()
evaluator.exponentiate(cipherTextA, 3, relinKeys, cipherDest)
# modReduceTo(encrypted, parmsId, destinationopt, poolopt) → {CipherText|void}
Given a ciphertext encrypted modulo q_1...q_k, this function reduces
the modulus down until the parameters reach the given parms_id and
stores the result in the destination parameter. Dynamic memory
allocations in the process are allocated from the memory pool pointed
to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to reduce | ||
parmsId |
ParmsIdType
|
Target parmsId to reduce to | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the reduced result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if
a destination was supplied
CipherText
|
void
Example
const context = seal.Context(encParms, true)
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const parmsId = context.lastParmsId
const resultCipher = evaluator.modReduceTo(cipherTextA, parmsId)
// or
const cipherDest = seal.CipherText()
evaluator.modReduceTo(cipherTextA, parmsId, cipherDest)
# modReduceToNext(encrypted, destinationopt, poolopt) → {CipherText|void}
Given a ciphertext encrypted modulo q_1...q_k, this function switches
the modulus down to q_1...q_{k-1}, scales the message down accordingly,
and stores the result in the destination parameter. Dynamic memory
allocations in the process are allocated from the memory pool pointed
to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to reduce | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the reduced result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if
a destination was supplied
CipherText
|
void
Example
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.modReduceToNext(cipherTextA)
// or
const cipherDest = seal.CipherText()
evaluator.modReduceToNext(cipherTextA, cipherDest)
# multiply(a, b, destinationopt, poolopt) → {CipherText|void}
Multiplies two CipherTexts. This functions computes the product of a
and b and stores the result in the destination parameter. Dynamic
memory allocations in the process are allocated from the memory pool pointed
to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
a |
CipherText
|
CipherText operand A | ||
b |
CipherText
|
CipherText operand B | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the product | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const cipherTextA = seal.CipherText()
const cipherTextB = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.multiply(cipherTextA, cipherTextB)
// or
const cipherDest = seal.CipherText()
evaluator.multiply(cipherTextA, cipherTextB, cipherDest)
# multiplyPlain(encrypted, plain, destinationopt, poolopt) → (nullable) {CipherText}
Multiplies a CipherText with a PlainText. This function multiplies
a CipherText with a PlainText and stores the result in the destination
parameter. The PlainText must be a valid for the current encryption parameters,
and cannot be identially 0. Dynamic memory allocations in the process are
allocated from the memory pool pointed to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText operand A | ||
plain |
PlainText
|
PlainText operand B | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the product | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
Example
const cipherTextA = seal.CipherText()
const plainTextB = seal.PlainText()
// ... after encrypting/encoding some data ...
const resultCipher = evaluator.multiplyPlain(cipherTextA, plainTextB)
// or
const cipherDest = seal.CipherText()
evaluator.multiplyPlain(cipherTextA, plainTextB, cipherDest)
# negate(encrypted, destinationopt) → {CipherText|void}
Negates a CipherText and stores the result in the destination parameter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
encrypted |
CipherText
|
CipherText to negate | |
destination |
CipherText
|
<optional> |
CipherText to store the negated results |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const cipherText = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.negate(cipherText)
// or
const cipherDest = seal.CipherText()
evaluator.negate(encrypted, cipherDest)
# plainModSwitchTo(plain, parmsId, destinationopt) → {PlainText|void}
Given an NTT transformed PlainText modulo q_1...q_k, this function switches
the modulus down until the parameters reach the given parmsId and stores
the result in the destination parameter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
plain |
PlainText
|
PlainText to switch its modulus down | |
parmsId |
ParmsIdType
|
Target parmsId to switch to | |
destination |
PlainText
|
<optional> |
PlainText destination to store the switched result |
PlainText containing the result or void if a destination was supplied
PlainText
|
void
Example
const context = seal.Context(encParms, true)
const plainTextA = seal.PlainText()
// ... after encoding some data ...
const parmsId = context.lastParmsId
const resultCipher = evaluator.plainModSwitchTo(plainTextA, parmsId)
// or
const plainDest = seal.PlainText()
evaluator.plainModSwitchTo(plainTextA, parmsId, plainDest)
# plainModSwitchToNext(plain, destinationopt) → {PlainText|void}
Modulus switches an NTT transformed PlainText from modulo q_1...q_k down
to modulo q_1...q_{k-1} and stores the result in the destination parameter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
plain |
PlainText
|
PlainText to switch its modulus down | |
destination |
PlainText
|
<optional> |
PlainText destination to store the switched result |
PlainText containing the result or void if a destination was supplied
PlainText
|
void
Example
const plainTextA = seal.PlainText()
// ... after encoding some data ...
const resultCipher = evaluator.plainModSwitchToNext(plainTextA)
// or
const plainDest = seal.PlainText()
evaluator.plainModSwitchToNext(plainTextA, plainDest)
# plainTransformToNtt(plain, parmsId, destinationNttopt, poolopt) → {PlainText|void}
Transforms a PlainText to NTT domain. This functions applies the number
Theoretic Transform to a PlainText by first embedding integers modulo the
PlainText modulus to integers modulo the coefficient modulus and then
performing David Harvey's NTT on the resulting polynomial. The transformation
is done with respect to encryption parameters corresponding to a given
parmsId. The result is stored in the destinationNtt parameter. For the
operation to be valid, the PlainText must have degree less than PolyModulusDegree
and each coefficient must be less than the PlainText modulus, i.e., the PlainText
must be a valid PlainText under the current encryption parameters. Dynamic
memory allocations in the process are allocated from the memory pool pointed
to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
plain |
PlainText
|
PlainText to transform | ||
parmsId |
ParmsIdType
|
target parmsId to perform NTT transformation | ||
destinationNtt |
PlainText
|
<optional> |
PlainText destination to store the transformed result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
PlainText containing the result or void if a destination was supplied
PlainText
|
void
Example
const context = seal.Context(encParms, true)
const plainTextA = seal.PlainText()
// ... after encoding some data ...
const parmsId = context.lastParmsId
const resultCipher = evaluator.plainTransformToNtt(plainTextA, parmsId)
// or
const plainDest = seal.PlainText()
evaluator.plainTransformToNtt(plainTextA, parmsId, plainDest)
# relinearize(encrypted, relinKeys, destinationopt, poolopt) → {CipherText|void}
Relinearizes a CipherText. This functions relinearizes encrypted, reducing
its size down to 2, and stores the result in the destination parameter.
If the size of encrypted is K+1, the given relinearization keys need to
have size at least K-1. Dynamic memory allocations in the process are allocated
from the memory pool pointed to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to relinearize | ||
relinKeys |
RelinKeys
|
RelinKey used to perform relinearization | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the relinearized result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const relinKeys = keyGenerator.createRelinKeys()
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.relinearize(cipherTextA, relinKeys)
// or
const cipherDest = seal.CipherText()
evaluator.relinearize(cipherTextA, relinKeys, cipherDest)
# rescaleTo(encrypted, parmsId, destinationopt, poolopt) → {CipherText|void}
Given a CipherText encrypted modulo q_1...q_k, this function switches the
modulus down until the parameters reach the given parmsId, scales the message
down accordingly, and stores the result in the destination parameter. Dynamic
memory allocations in the process are allocated from the memory pool pointed
to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to rescale | ||
parmsId |
ParmsIdType
|
Target parmsId to rescale to | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the rescaled result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const context = seal.Context(encParms, true)
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const parmsId = context.lastParmsId
const resultCipher = evaluator.rescaleTo(cipherTextA, parmsId)
// or
const cipherDest = seal.CipherText()
evaluator.rescaleTo(cipherTextA, parmsId, cipherDest)
# rescaleToNext(encrypted, destinationopt, poolopt) → {CipherText|void}
Given a CipherText encrypted modulo q_1...q_k, this function switches the
modulus down to q_1...q_{k-1}, scales the message down accordingly, and
stores the result in the destination parameter. Dynamic memory allocations
in the process are allocated from the memory pool pointed to by the given
MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to rescale | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the rescaled result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.rescaleToNext(cipherTextA)
// or
const cipherDest = seal.CipherText()
evaluator.rescaleToNext(cipherTextA, cipherDest)
# rotateColumns(encrypted, galoisKeys, destinationopt, poolopt) → {CipherText|void}
Rotates PlainText matrix columns cyclically. When batching is used with
the BFV scheme, this function rotates the encrypted PlainText matrix columns
cyclically, and writes the result to the destination parameter. Since the
size of the batched matrix is 2-by-(N/2), where N is the degree of the
polynomial modulus, this means simply swapping the two rows. Dynamic memory
allocations in the process are allocated from the memory pool pointed to
by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to rotate columns | ||
galoisKeys |
GaloisKeys
|
GaloisKeys used to perform rotations | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the rotated result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const galoisKeys = keyGenerator.createGaloisKeys()
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.rotateColumns(cipherTextA, galoisKeys)
// or
const cipherDest = seal.CipherText()
evaluator.rotateColumns(cipherTextA, galoisKeys, cipherDest)
# rotateRows(encrypted, steps, galoisKeys, destinationopt, poolopt) → {CipherText|void}
Rotates PlainText matrix rows cyclically. When batching is used with the
BFV/BGV scheme, this function rotates the encrypted PlainText matrix rows
cyclically to the left (steps > 0) or to the right (steps < 0) and writes
the result to the destination parameter. Since the size of the batched
matrix is 2-by-(N/2), where N is the degree of the polynomial modulus,
the number of steps to rotate must have absolute value at most N/2-1. Dynamic
memory allocations in the process are allocated from the memory pool pointed
to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to rotate rows | ||
steps |
number
|
Int representing steps to rotate (negative = right, positive = left) | ||
galoisKeys |
GaloisKeys
|
GaloisKeys used to perform rotations | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the rotated result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const galoisKeys = keyGenerator.createGaloisKeys()
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.rotateRows(cipherTextA, 3, galoisKeys)
// or
const cipherDest = seal.CipherText()
evaluator.rotateRows(cipherTextA, 3, galoisKeys, cipherDest)
# rotateVector(encrypted, steps, galoisKeys, destinationopt, poolopt) → {CipherText|void}
Rotates PlainText vector cyclically. When using the CKKS scheme, this function
rotates the encrypted PlainText vector cyclically to the left (steps > 0)
or to the right (steps < 0) and writes the result to the destination parameter.
Since the size of the batched matrix is 2-by-(N/2), where N is the degree
of the polynomial modulus, the number of steps to rotate must have absolute
value at most N/2-1. Dynamic memory allocations in the process are allocated
from the memory pool pointed to by the given MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to rotate the entire vector | ||
steps |
number
|
Int representing steps to rotate (negative = right, positive = left) | ||
galoisKeys |
GaloisKeys
|
GaloisKeys used to perform rotations | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the rotated result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const galoisKeys = keyGenerator.createGaloisKeys()
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.rotateVector(cipherTextA, 3, galoisKeys)
// or
const cipherDest = seal.CipherText()
evaluator.rotateVector(cipherTextA, 3, galoisKeys, cipherDest)
# square(encrypted, destinationopt, poolopt) → {CipherText|void}
Squares a CipherText. This functions computes the square of encrypted and
stores the result in the destination parameter. Dynamic memory allocations
in the process are allocated from the memory pool pointed to by the given
MemoryPoolHandle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to square | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the squared result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.square(cipherTextA, cipherTextB)
// or
const cipherDest = seal.CipherText()
evaluator.square(cipherTextA, cipherDest)
# sub(a, b, destinationopt) → {CipherText|void}
Subtracts two CipherTexts. This function computes the difference of a
and b and stores the result in the destination parameter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a |
CipherText
|
CipherText operand A | |
b |
CipherText
|
CipherText operand B | |
destination |
CipherText
|
<optional> |
CipherText destination to store the difference |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const cipherTextA = seal.CipherText()
const cipherTextB = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.sub(cipherTextA, cipherTextB)
// or
const cipherDest = seal.CipherText()
evaluator.sub(cipherTextA, cipherTextB, cipherDest)
# subPlain(encrypted, plain, destinationopt, poolopt) → {CipherText|void}
Subtracts a PlainText from a CipherText. This function subtracts a PlainText
from a CipherText and stores the result in the destination parameter. The
PlainText must be valid for the current encryption parameters.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText operand A | ||
plain |
PlainText
|
PlainText operand B | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the difference | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const cipherTextA = seal.CipherText()
const plainTextB = seal.PlainText()
// ... after encrypting/encoding some data ...
const resultCipher = evaluator.subPlain(cipherTextA, plainTextB)
// or
const cipherDest = seal.CipherText()
evaluator.subPlain(cipherTextA, plainTextB, cipherDest)
# sumElements(encrypted, galoisKeys, scheme, destinationopt, poolopt) → {CipherText|void}
Sum all elements in the encrypted CipherText. The resulting CipherText contains the sum in every element.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
encrypted |
CipherText
|
CipherText to sum elements | ||
galoisKeys |
GaloisKeys
|
GaloisKeys used to perform rotations | ||
scheme |
SchemeType
|
Scheme that was used for encryption | ||
destination |
CipherText
|
<optional> |
CipherText destination to store the result | |
pool |
MemoryPoolHandle
|
<optional> |
MemoryPoolHandle.global | MemoryPool to use |
CipherText containing the result or void if a destination was supplied
CipherText
|
void
Example
const galoisKeys = keyGenerator.createGaloisKeys()
const cipherTextA = seal.CipherText()
// ... after encrypting some data ...
const resultCipher = evaluator.sumElements(cipherTextA, galoisKeys, seal.SchemeTypes.BFV)
// or
const cipherDest = seal.CipherText()
evaluator.sumElements(cipherTextA, galoisKeys, seal.SchemeTypes.BFV, cipherDest)