1 // Copyright (c) Microsoft Corporation. All rights reserved. 2 // Licensed under the MIT license. 3 4 #pragma once 5 6 #include "seal/ciphertext.h" 7 #include "seal/context.h" 8 #include "seal/encryptionparams.h" 9 #include "seal/publickey.h" 10 #include "seal/randomgen.h" 11 #include "seal/secretkey.h" 12 #include <cstdint> 13 14 namespace seal 15 { 16 namespace util 17 { 18 /** 19 Generate a uniform ternary polynomial and store in RNS representation. 20 21 @param[in] prng A uniform random generator 22 @param[in] parms EncryptionParameters used to parameterize an RNS polynomial 23 @param[out] destination Allocated space to store a random polynomial 24 */ 25 void sample_poly_ternary( 26 std::shared_ptr<UniformRandomGenerator> prng, const EncryptionParameters &parms, 27 std::uint64_t *destination); 28 29 /** 30 Generate a polynomial from a normal distribution and store in RNS representation. 31 32 @param[in] prng A uniform random generator 33 @param[in] parms EncryptionParameters used to parameterize an RNS polynomial 34 @param[out] destination Allocated space to store a random polynomial 35 */ 36 void sample_poly_normal( 37 std::shared_ptr<UniformRandomGenerator> prng, const EncryptionParameters &parms, 38 std::uint64_t *destination); 39 40 /** 41 Generate a polynomial from a centered binomial distribution and store in RNS representation. 42 43 @param[in] prng A uniform random generator. 44 @param[in] parms EncryptionParameters used to parameterize an RNS polynomial 45 @param[out] destination Allocated space to store a random polynomial 46 */ 47 void sample_poly_cbd( 48 std::shared_ptr<UniformRandomGenerator> prng, const EncryptionParameters &parms, 49 std::uint64_t *destination); 50 51 /** 52 Generate a uniformly random polynomial and store in RNS representation. 53 54 @param[in] prng A uniform random generator 55 @param[in] parms EncryptionParameters used to parameterize an RNS polynomial 56 @param[out] destination Allocated space to store a random polynomial 57 */ 58 void sample_poly_uniform( 59 std::shared_ptr<UniformRandomGenerator> prng, const EncryptionParameters &parms, 60 std::uint64_t *destination); 61 62 /** 63 Generate a uniformly random polynomial and store in RNS representation. 64 This implementation corresponds to Microsoft SEAL 3.4 and earlier. 65 66 @param[in] prng A uniform random generator 67 @param[in] parms EncryptionParameters used to parameterize an RNS polynomial 68 @param[out] destination Allocated space to store a random polynomial 69 */ 70 void sample_poly_uniform_seal_3_4( 71 std::shared_ptr<UniformRandomGenerator> prng, const EncryptionParameters &parms, 72 std::uint64_t *destination); 73 74 /** 75 Generate a uniformly random polynomial and store in RNS representation. 76 This implementation corresponds to Microsoft SEAL 3.5 and earlier. 77 78 @param[in] prng A uniform random generator 79 @param[in] parms EncryptionParameters used to parameterize an RNS polynomial 80 @param[out] destination Allocated space to store a random polynomial 81 */ 82 void sample_poly_uniform_seal_3_5( 83 std::shared_ptr<UniformRandomGenerator> prng, const EncryptionParameters &parms, 84 std::uint64_t *destination); 85 86 /** 87 Create an encryption of zero with a public key and store in a ciphertext. 88 89 @param[in] public_key The public key used for encryption 90 @param[in] context The SEALContext containing a chain of ContextData 91 @param[in] parms_id Indicates the level of encryption 92 @param[in] is_ntt_form If true, store ciphertext in NTT form 93 @param[out] destination The output ciphertext - an encryption of zero 94 */ 95 void encrypt_zero_asymmetric( 96 const PublicKey &public_key, const SEALContext &context, parms_id_type parms_id, bool is_ntt_form, 97 Ciphertext &destination); 98 99 /** 100 Create an encryption of zero with a secret key and store in a ciphertext. 101 102 @param[out] destination The output ciphertext - an encryption of zero 103 @param[in] secret_key The secret key used for encryption 104 @param[in] context The SEALContext containing a chain of ContextData 105 @param[in] parms_id Indicates the level of encryption 106 @param[in] is_ntt_form If true, store ciphertext in NTT form 107 @param[in] save_seed If true, the second component of ciphertext is 108 replaced with the random seed used to sample this component 109 */ 110 void encrypt_zero_symmetric( 111 const SecretKey &secret_key, const SEALContext &context, parms_id_type parms_id, bool is_ntt_form, 112 bool save_seed, Ciphertext &destination); 113 } // namespace util 114 } // namespace seal 115