CryptoSystem Interface

The CryptoSystem interface provides a uniform API for cryptographic operations such as key generation, encryption, decryption, and homomorphic arithmetic operations. It is designed to abstract different underlying cryptosystem implementations, allowing for CPU or GPU-based backends while maintaining the same interface for users.

Note: The current CPUCryptoSystem class uses pointers for underlying implementations in tensors and vectors. This will be updated in the future to strictly follow the interface described below.

Template Parameters

template <
    typename CryptoSystemImpl,
    typename SecretKeyImpl,
    typename PublicKeyImpl,
    typename PlainTextImpl,
    typename CipherTextImpl,
    typename SecretKeyShareImpl,
    typename PartDecryptionResult
>
  • CryptoSystemImpl: The implementation of the cryptosystem.

  • SecretKeyImpl: The type representing the secret key.

  • PublicKeyImpl: The type representing the public key.

  • PlainTextImpl: The type representing plaintext data.

  • CipherTextImpl: The type representing ciphertext data.

  • SecretKeyShareImpl: The type representing a share of the secret key (used in distributed settings).

  • PartDecryptionResult: The type representing the result of a partial decryption.

Interface Functions

Key Generation

  • SecretKeyImpl keygen()

    Generates a new secret key.

  • PublicKeyImpl keygen(SecretKeyImpl sk)

    Generates a public key from the given secret key.

  • Vector<Vector<SecretKeyShareImpl>> keygen(SecretKeyImpl sk, int threshold, int num_parties)

    Generates secret key shares for threshold decryption in a distributed setting.

Encryption

  • CipherTextImpl encrypt(PublicKeyImpl pk, PlainTextImpl pt)

    Encrypts a plaintext using the public key.

  • Vector<CipherTextImpl> encrypt(PublicKeyImpl pk, Vector<PlainTextImpl> pts)

    Encrypts a vector of plaintexts.

  • Tensor<CipherTextImpl> encrypt_tensor(PublicKeyImpl pk, Tensor<PlainTextImpl> pts)

    Encrypts a tensor of plaintexts.

Decryption

  • PlainTextImpl decrypt(SecretKeyImpl sk, CipherTextImpl ct)

    Decrypts a ciphertext using the secret key.

  • Vector<PlainTextImpl> decrypt_vector(SecretKeyImpl sk, Vector<CipherTextImpl> cts)

    Decrypts a vector of ciphertexts.

  • Tensor<PlainTextImpl> decrypt_tensor(SecretKeyImpl sk, Tensor<CipherTextImpl> cts)

    Decrypts a tensor of ciphertexts.

Partial Decryption (Distributed)

  • PartDecryptionResult part_decrypt(SecretKeyShareImpl sks, CipherTextImpl ct)

    Performs partial decryption using a secret key share.

  • Vector<PartDecryptionResult> part_decrypt_vector(SecretKeyShareImpl sks, Vector<CipherTextImpl> cts)

    Partial decryption of a vector of ciphertexts.

  • Tensor<PartDecryptionResult> part_decrypt_tensor(SecretKeyShareImpl sks, Tensor<CipherTextImpl> cts)

    Partial decryption of a tensor of ciphertexts.

  • PlainTextImpl combine_part_decryption_results(CipherTextImpl ct, Vector<PartDecryptionResult> pdrs)

    Combines partial decryption results to recover the plaintext.

  • Vector<PlainTextImpl> combine_part_decryption_results_vector(CipherTextImpl ct, Vector<PartDecryptionResult> pdrs)

    Combines partial decryption results for a vector of ciphertexts.

  • Tensor<PlainTextImpl> combine_part_decryption_results_tensor(CipherTextImpl ct, Vector<Tensor<PartDecryptionResult>> pdrs)

    Combines partial decryption results for a tensor of ciphertexts.

Homomorphic Operations on Ciphertexts

  • CipherTextImpl add_ciphertexts(PublicKeyImpl pk, CipherTextImpl ct1, CipherTextImpl ct2)

    Adds two ciphertexts homomorphically.

  • CipherTextImpl scal_ciphertext(PublicKeyImpl pk, PlainTextImpl pt, CipherTextImpl ct)

    Multiplies a ciphertext by a plaintext scalar homomorphically.

  • Vector<CipherTextImpl> add_ciphertext_vectors(PublicKeyImpl pk, Vector<CipherTextImpl> cts1, Vector<CipherTextImpl> cts2)

    Adds two vectors of ciphertexts element-wise.

  • Vector<CipherTextImpl> scal_ciphertext_vector(PublicKeyImpl pk, PlainTextImpl pt, Vector<CipherTextImpl> cts)

    Multiplies each ciphertext in the vector by a plaintext scalar.

  • Vector<CipherTextImpl> scal_ciphertext_vector(PublicKeyImpl pk, Vector<PlainTextImpl> pts, Vector<CipherTextImpl> cts)

    Multiplies each ciphertext in the vector by corresponding plaintext scalars.

  • Tensor<CipherTextImpl> add_ciphertext_tensors(PublicKeyImpl pk, Tensor<CipherTextImpl> cts1, Tensor<CipherTextImpl> cts2)

    Adds two tensors of ciphertexts element-wise.

  • Tensor<CipherTextImpl> scal_ciphertext_tensors(PublicKeyImpl pk, Tensor<PlainTextImpl> pts, Tensor<CipherTextImpl> cts)

    Multiplies each ciphertext in the tensor by corresponding plaintext scalars.

Plaintext Operations

  • PlainTextImpl generate_random_plaintext()

    Generates a random plaintext.

  • Vector<PlainTextImpl> generate_random_beavers_triplet()

    Generates a Beaver's triplet for secure multiplication.

  • PlainTextImpl add_plaintexts(PlainTextImpl pt1, PlainTextImpl pt2)

    Adds two plaintexts.

  • PlainTextImpl multiply_plaintexts(PlainTextImpl pt1, PlainTextImpl pt2)

    Multiplies two plaintexts.

  • Tensor<PlainTextImpl> add_plaintext_tensors(Tensor<PlainTextImpl> pts1, Tensor<PlainTextImpl> pts2)

    Adds two tensors of plaintexts element-wise.

  • Tensor<PlainTextImpl> multiply_plaintext_tensors(Tensor<PlainTextImpl> pts1, Tensor<PlainTextImpl> pts2)

    Multiplies two tensors of plaintexts element-wise.

Negation Operations

  • PlainTextImpl negate_plaintext(PlainTextImpl pt)

    Negates a plaintext.

  • Tensor<PlainTextImpl> negate_plain_tensor(Tensor<PlainTextImpl> pts)

    Negates each plaintext in a tensor.

  • CipherTextImpl negate_ciphertext(PublicKeyImpl pk, CipherTextImpl ct)

    Negates a ciphertext homomorphically.

  • Tensor<CipherTextImpl> negate_ciphertext_tensor(PublicKeyImpl pk, Tensor<CipherTextImpl> cts)

    Negates each ciphertext in a tensor homomorphically.

Plaintext Creation and Retrieval

  • PlainTextImpl make_plaintext(float value)

    Creates a plaintext from a floating-point value.

  • float get_float_from_plaintext(PlainTextImpl pt)

    Retrieves the floating-point value from a plaintext.

Serialization

  • String serialize()

    Serializes the cryptosystem instance.

  • String serialize_secret_key(SecretKeyImpl sk)

    Serializes a secret key.

  • String serialize_secret_key_share(SecretKeyShareImpl sks)

    Serializes a secret key share.

  • String serialize_public_key(PublicKeyImpl pk)

    Serializes a public key.

  • String serialize_plaintext(PlainTextImpl pt)

    Serializes a plaintext.

  • String serialize_ciphertext(CipherTextImpl ct)

    Serializes a ciphertext.

  • String serialize_part_decryption_result(PartDecryptionResult pdr)

    Serializes a partial decryption result.

  • String serialize_plaintext_tensor(Tensor<PlainTextImpl> pts)

    Serializes a tensor of plaintexts.

  • String serialize_ciphertext_tensor(Tensor<CipherTextImpl> cts)

    Serializes a tensor of ciphertexts.

  • String serialize_part_decryption_result_tensor(Tensor<PartDecryptionResult> pdrs)

    Serializes a tensor of partial decryption results.

Deserialization

  • CryptoSystemImpl::deserialize(String data)

    Deserializes a cryptosystem instance from a string.

  • SecretKeyImpl deserialize_secret_key(String data)

    Deserializes a secret key from a string.

  • SecretKeyShareImpl deserialize_secret_key_share(String data)

    Deserializes a secret key share from a string.

  • PublicKeyImpl deserialize_public_key(String data)

    Deserializes a public key from a string.

  • PlainTextImpl deserialize_plaintext(String data)

    Deserializes a plaintext from a string.

  • CipherTextImpl deserialize_ciphertext(String data)

    Deserializes a ciphertext from a string.

  • PartDecryptionResult deserialize_part_decryption_result(String data)

    Deserializes a partial decryption result from a string.

  • Tensor<PlainTextImpl> deserialize_plaintext_tensor(String data)

    Deserializes a tensor of plaintexts from a string.

  • Tensor<CipherTextImpl> deserialize_ciphertext_tensor(String data)

    Deserializes a tensor of ciphertexts from a string.

  • Tensor<PartDecryptionResult> deserialize_part_decryption_result_tensor(String data)

    Deserializes a tensor of partial decryption results from a string.

Notes

  • Serialization and deserialization facilitate the storage and transmission over network of cryptographic objects.

Example Usage

Key Generation and Encryption

Homomorphic Addition and Decryption

Serialization and Deserialization

Last updated