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 #include "private_join_and_compute/crypto/two_modulus_crt.h"
17
18 namespace private_join_and_compute {
19
TwoModulusCrt(const BigNum & coprime1,const BigNum & coprime2)20 TwoModulusCrt::TwoModulusCrt(const BigNum& coprime1, const BigNum& coprime2)
21 : crt_term1_(coprime2 * coprime2.ModInverse(coprime1).value()),
22 crt_term2_(coprime1 * coprime1.ModInverse(coprime2).value()),
23 coprime_product_(coprime1 * coprime2) {}
24
Compute(const BigNum & solution1,const BigNum & solution2) const25 BigNum TwoModulusCrt::Compute(const BigNum& solution1,
26 const BigNum& solution2) const {
27 return ((solution1 * crt_term1_) + (solution2 * crt_term2_))
28 .Mod(coprime_product_);
29 }
30
GetCoprimeProduct() const31 BigNum TwoModulusCrt::GetCoprimeProduct() const { return coprime_product_; }
32
33 } // namespace private_join_and_compute
34