1 /* 2 * Copyright 2019 Google LLC. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * https://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 // Helper functions that enable conversion between ElGamal structs and protocol 17 // buffer messsages. 18 19 #ifndef PRIVATE_JOIN_AND_COMPUTE_UTIL_ELGAMAL_PROTO_UTIL_H_ 20 #define PRIVATE_JOIN_AND_COMPUTE_UTIL_ELGAMAL_PROTO_UTIL_H_ 21 22 #include <memory> 23 24 #include "private_join_and_compute/crypto/context.h" 25 #include "private_join_and_compute/crypto/ec_group.h" 26 #include "private_join_and_compute/crypto/elgamal.h" 27 #include "private_join_and_compute/crypto/elgamal.pb.h" 28 29 namespace private_join_and_compute::elgamal_proto_util { 30 31 // Converts a struct elgamal::PublicKey into a protocol buffer 32 // ::private_join_and_compute::ElGamalPublicKey. 33 StatusOr<ElGamalPublicKey> SerializePublicKey( 34 const elgamal::PublicKey& public_key_struct); 35 36 // Converts a protocol buffer ElGamalPublicKey into a struct 37 // elgamal::PublicKey. ec_group is used for ECPoint operations. 38 StatusOr<std::unique_ptr<elgamal::PublicKey>> DeserializePublicKey( 39 const ECGroup* ec_group, const ElGamalPublicKey& public_key_proto); 40 41 // Converts a struct elgamal::PrivateKey into a protocol buffer 42 // ::private_join_and_compute::ElGamalSecretKey. 43 StatusOr<::private_join_and_compute::ElGamalSecretKey> SerializePrivateKey( 44 const elgamal::PrivateKey& private_key_struct); 45 46 // Converts a protocol buffer ::private_join_and_compute::ElGamalSecretKey into 47 // a struct elgamal::PrivateKey. context is used for BigNum operations. 48 StatusOr<std::unique_ptr<elgamal::PrivateKey>> DeserializePrivateKey( 49 Context* context, 50 const ::private_join_and_compute::ElGamalSecretKey& private_key_proto); 51 52 // Converts a struct elgamal::Ciphertext into a protocol buffer 53 // ::private_join_and_compute::ElGamalCiphertext. 54 StatusOr<ElGamalCiphertext> SerializeCiphertext( 55 const elgamal::Ciphertext& ciphertext_struct); 56 57 // Converts a protocol buffer ElGamalCiphertext into a struct 58 // elgamal::Ciphertext. ec_group is used for ECPoint operations. 59 StatusOr<elgamal::Ciphertext> DeserializeCiphertext( 60 const ECGroup* ec_group, const ElGamalCiphertext& ciphertext_proto); 61 62 } // namespace private_join_and_compute::elgamal_proto_util 63 64 #endif // PRIVATE_JOIN_AND_COMPUTE_UTIL_ELGAMAL_PROTO_UTIL_H_ 65