mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-17 16:11:26 -05:00
feat(compiler): support crt encoding in scalars during simulation
This commit is contained in:
@@ -54,10 +54,22 @@ public:
|
||||
return value.getScalar().getValue<T>();
|
||||
|
||||
if (isSimulated()) {
|
||||
// value is a scalar in simulation
|
||||
auto ciphertext = value.getScalar().getValue<uint64_t>();
|
||||
OUTCOME_TRY(auto decrypted, decryptValue(pos, &ciphertext));
|
||||
return (T)decrypted;
|
||||
OUTCOME_TRY(auto gate, outputGate(pos));
|
||||
auto crtVec = gate.encryption->encoding.crt;
|
||||
if (crtVec.empty()) {
|
||||
// value is a scalar
|
||||
auto ciphertext = value.getScalar().getValue<uint64_t>();
|
||||
OUTCOME_TRY(auto decrypted, decryptValue(pos, &ciphertext));
|
||||
return (T)decrypted;
|
||||
} else {
|
||||
// value is a tensor (crt)
|
||||
auto &buffer = value.getTensor();
|
||||
auto ciphertext = buffer.getOpaqueElementPointer(0);
|
||||
OUTCOME_TRY(
|
||||
auto decrypted,
|
||||
decryptValue(pos, reinterpret_cast<uint64_t *>(ciphertext)));
|
||||
return (T)decrypted;
|
||||
}
|
||||
}
|
||||
|
||||
auto &buffer = value.getTensor();
|
||||
|
||||
@@ -238,9 +238,18 @@ protected:
|
||||
/// Simulate encrypt and export a 64bits integer to a serializale value
|
||||
outcome::checked<ScalarOrTensorData, StringError>
|
||||
exportEncryptValue(uint64_t arg, CircuitGate &gate, size_t argPos) override {
|
||||
uint64_t encValue = 0;
|
||||
OUTCOME_TRYV(encryptValue(gate, argPos, &encValue, arg));
|
||||
return ScalarData(encValue);
|
||||
auto crtVec = gate.encryption->encoding.crt;
|
||||
if (crtVec.empty()) {
|
||||
uint64_t encValue = 0;
|
||||
OUTCOME_TRYV(encryptValue(gate, argPos, &encValue, arg));
|
||||
return ScalarData(encValue);
|
||||
} else {
|
||||
TensorData td(bufferShape(gate), clientlib::EncryptedScalarElementType,
|
||||
clientlib::EncryptedScalarElementWidth);
|
||||
OUTCOME_TRYV(
|
||||
encryptValue(gate, argPos, td.getElementPointer<uint64_t>(0), arg));
|
||||
return std::move(td);
|
||||
}
|
||||
}
|
||||
|
||||
outcome::checked<CircuitGate, StringError> inputGate(size_t argPos) override {
|
||||
|
||||
Reference in New Issue
Block a user