Manually increasing Ring Dimension in BFV

I have a simple program that uses BFV and for testing purposes I would like for a selected security level (e.g HEStd_128_classic) to increase the Ring Dimension. I can already do this with the snippet found below, but I had the following question:

Does increasing the Ring Dimension affect (in a negative manner) the resulted security level of the selected parameters? As far as I understand, the HomomorphicEncryption.org guideline present lower limits to achieve a given security level. Does this mean that I can safely increase the Ring Dimension and even get a more robust parameter selection?

Additionally, could you possibly point me to any resources that I can read about this and I could reference them if I made such claims?

Find here the snippet:

import openfhe as fhe

# Set the parameters
parameters = fhe.CCParamsBFVRNS()
parameters.SetPlaintextModulus(5767169)
parameters.SetMultiplicativeDepth(1)
parameters.SetSecurityLevel(fhe.HEStd_128_classic)
parameters.SetRingDim(262144)

crypto_context = fhe.GenCryptoContext(parameters)
crypto_context.Enable(fhe.PKESchemeFeature.PKE)
crypto_context.Enable(fhe.PKESchemeFeature.KEYSWITCH)
crypto_context.Enable(fhe.PKESchemeFeature.LEVELEDSHE)
crypto_context.Enable(fhe.ADVANCEDSHE)

# Print the parameters
q = crypto_context.GetModulus()
q_bitlength = int(q).bit_length()
print("Plaintext Modulus = ", 5767169)
print("Ciphertext modulus bitsize (log2 q) = ", q_bitlength )
print("Ring Dimension (m) = ", crypto_context.GetRingDimension() )

# Generate keys
key_pair = crypto_context.KeyGen()
crypto_context.EvalMultKeyGen(key_pair.secretKey)

# Generate data of length equal to the Ring Dimension
data = [i for i in range(262144)]


# Encrypt
data_packed = crypto_context.MakePackedPlaintext(data)
data_encrypted = crypto_context.Encrypt(key_pair.publicKey, data_packed)

# Evaluate
result_encrypted = crypto_context.EvalAdd(data_encrypted, data_encrypted)

# Decrypt and unpack
result_decrypted = crypto_context.Decrypt(result_encrypted, key_pair.secretKey)
result_decrypted.SetLength(262144)
unpacked_result = result_decrypted.GetPackedValue()

# Print the results
print(unpacked_result[0:100])
print(len(unpacked_result))

Thank you!

In a nutshell, only increasing the ring dimension does improve security, but it lowers performance/increases memory consumption. So, staying within the given guidelines is recommended unless you know what you are doing and have a specific need.

That is why documents like the one you have cited or a more recent work available on eprint try to find the smallest parameters to achieve the desired security level and provide optimal performances.

For a bit more detailed explanation, the security of BFV is based on the RLWE problem, and this problem becomes harder when you (only) increase the ring dimension. This has been detailed in many articles, and a possible reference could be this one; although the scope is rather large, it makes a good introduction to lattice cryptography. But plenty of other resources are available on LWE/RLWE.
For a more hands-on approach, the security of this underlying problem can be estimated with the lattice-estimator, a sage module. You’ll see that increasing the ring dimension gives you more bits of security.

1 Like

Thanks for your answer, it’s very informative.

Indeed, I wanted to test something specific, knowing that there is a performance degradation by increasing Ring Dimension.

I appreciate also the linked resources. From a quick look in the first link, I see there is a chapter about RLWE so I can read more about the relation with the Ring Dimension there. The Lattice-estimator could be also used to verify this, indeed.

Thanks again!

I highly recommend not changing the security parameters manually. LWE/RLWE hardness analysis is very complex, and the best we know is that only specific parameter ranges guarantee concrete hardness.

I would also reference the lattice-estimator paper.

1 Like