#encryption #fhe #homomorphic

concrete-core-experimental

Concrete 是一个全同态加密 (FHE) 库,实现了 Zama 的 TFHE 变体

1 个版本 (0 个不稳定)

1.0.0-beta2022年7月6日

#2446 in 密码学

BSD-3-Clause-ClearGPL-2.0-or-later

5.5MB
94K SLoC

Concrete Core

这个crate包含了在concrete库中使用的同态算子的底层实现。

⚠ 注意 ⚠

这个crate假设用户熟悉FHE的理论。如果您更喜欢使用更简单的API,该API将代表您执行检查,那么更高层的concrete crate应该可以满足您的需求。

示例

以下是一个示例,展示如何使用 concrete-core 来执行简单的同态操作

// This examples shows how to multiply a secret value by a public one homomorphically. First
// we import the proper symbols:
use concrete_core::crypto::encoding::{RealEncoder, Cleartext, Encoder, Plaintext};
use concrete_core::crypto::secret::LweSecretKey;
use concrete_core::crypto::LweDimension;
use concrete_core::crypto::lwe::LweCiphertext;
use concrete_core::math::dispersion::LogStandardDev;

// We initialize an encoder that will allow us to turn cleartext values into plaintexts.
let encoder = RealEncoder{offset: 0., delta: 100.};
// Our secret value will be 10.,
let cleartext = Cleartext(10.);
let public_multiplier = Cleartext(5);
// We encode our cleartext
let plaintext = encoder.encode(cleartext);

// We generate a new secret key which is used to encrypt the message
let secret_key_size = LweDimension(710);
let secret_key = LweSecretKey::generate(secret_key_size);

// We allocate a ciphertext and encrypt the plaintext with a secure parameter
let mut ciphertext = LweCiphertext::allocate(0u32, secret_key_size.to_lwe_size());
secret_key.encrypt_lwe(
    &mut ciphertext,
    &plaintext,
    LogStandardDev::from_log_standard_dev(-17.)
);

// We perform the homomorphic operation:
ciphertext.update_with_scalar_mul(public_multiplier);

// We decrypt the message
let mut output_plaintext = Plaintext(0u32);
secret_key.decrypt_lwe(&mut output_plaintext, &ciphertext);
let output_cleartext = encoder.decode(output_plaintext);

// We check that the result is as expected !
assert_eq!((output_cleartext.0 - 50.).abs() < 0.01);

许可证

本软件在 BSD-3-Clause-Clear 许可证下分发。如果您有任何问题,请通过 hello@zama.ai 联系我们。

依赖项

~11MB
~312K SLoC