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 // Computes Chinese remainder theorem for two coprimes (i.e., relatively 17 // primes). 18 19 #ifndef PRIVATE_JOIN_AND_COMPUTE_CRYPTO_TWO_MODULUS_CRT_H_ 20 #define PRIVATE_JOIN_AND_COMPUTE_CRYPTO_TWO_MODULUS_CRT_H_ 21 22 #include "private_join_and_compute/crypto/big_num.h" 23 24 namespace private_join_and_compute { 25 26 class TwoModulusCrt { 27 public: 28 TwoModulusCrt(const BigNum& coprime1, const BigNum& coprime2); 29 30 // TwoModulusCrt is neither copyable nor movable. 31 TwoModulusCrt(const TwoModulusCrt&) = delete; 32 TwoModulusCrt& operator=(const TwoModulusCrt&) = delete; 33 34 ~TwoModulusCrt() = default; 35 36 // Computes r s.t. r congruent to both solution1 mod coprime1 and 37 // solution2 mod coprime2. 38 BigNum Compute(const BigNum& solution1, const BigNum& solution2) const; 39 40 // Returns the product of the two coprime values given to the constructor as 41 // input. 42 BigNum GetCoprimeProduct() const; 43 44 private: 45 BigNum crt_term1_; 46 BigNum crt_term2_; 47 BigNum coprime_product_; 48 }; 49 50 } // namespace private_join_and_compute 51 52 #endif // PRIVATE_JOIN_AND_COMPUTE_CRYPTO_TWO_MODULUS_CRT_H_ 53