chromium/third_party/distributed_point_functions/code/dpf/int_mod_n.h

/*
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef DISTRIBUTED_POINT_FUNCTIONS_DPF_INTERNAL_INT_MOD_N_H_
#define DISTRIBUTED_POINT_FUNCTIONS_DPF_INTERNAL_INT_MOD_N_H_

#include <algorithm>
#include <string>
#include <type_traits>

#include "absl/base/config.h"
#include "absl/container/inlined_vector.h"
#include "absl/log/absl_check.h"
#include "absl/numeric/int128.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"

namespace distributed_point_functions {

namespace dpf_internal {

// Base class holding common functions of IntModN that are independent of the
// template parameter.
class IntModNBase {};

template <typename BaseInteger, typename ModulusType, ModulusType kModulus>
class IntModNImpl : public IntModNBase {};

template <typename BaseInteger, typename ModulusType, ModulusType kModulus>
constexpr IntModNImpl<BaseInteger, ModulusType, kModulus> operator+(
    IntModNImpl<BaseInteger, ModulusType, kModulus> a,
    const IntModNImpl<BaseInteger, ModulusType, kModulus>& b) {}

template <typename BaseInteger, typename ModulusType, ModulusType kModulus>
constexpr IntModNImpl<BaseInteger, ModulusType, kModulus> operator-(
    IntModNImpl<BaseInteger, ModulusType, kModulus> a,
    const IntModNImpl<BaseInteger, ModulusType, kModulus>& b) {}

template <typename BaseInteger, typename ModulusType, ModulusType kModulus>
constexpr IntModNImpl<BaseInteger, ModulusType, kModulus> operator-(
    IntModNImpl<BaseInteger, ModulusType, kModulus> a) {}

template <typename BaseInteger, typename ModulusType, ModulusType kModulus>
constexpr bool operator==(
    const IntModNImpl<BaseInteger, ModulusType, kModulus>& a,
    const IntModNImpl<BaseInteger, ModulusType, kModulus>& b) {}

template <typename BaseInteger, typename ModulusType, ModulusType kModulus>
constexpr bool operator!=(
    const IntModNImpl<BaseInteger, ModulusType, kModulus>& a,
    const IntModNImpl<BaseInteger, ModulusType, kModulus>& b) {}

}  // namespace dpf_internal

// Since `absl::uint128` is not an alias to `unsigned __int128`, but a struct,
// we cannot use it as a template parameter type. So if we have an intrinsic
// int128, we always use that as the modulus type. Otherwise, the modulus type
// is the same as BaseInteger.
#ifdef ABSL_HAVE_INTRINSIC_INT128
IntModN;
#else
template <typename BaseInteger, BaseInteger kModulus>
using IntModN = dpf_internal::IntModNImpl<BaseInteger, BaseInteger, kModulus>;
#endif

}  // namespace distributed_point_functions
#endif  // DISTRIBUTED_POINT_FUNCTIONS_DPF_INTERNAL_INT_MOD_N_H_