chromium/third_party/distributed_point_functions/code/dpf/distributed_point_function.proto

// 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.

syntax = "proto3";

package distributed_point_functions;

// For faster allocations of sub-messages.
option cc_enable_arenas = true;

// Describes the type of a single DPF output value. Any additional types added
// here should also be supported in internal/value_type_helpers.h.
// LINT.IfChange
message ValueType {
  // Describes an integer modulo 2^l. Maps to the C++ types `uint8_t`,
  // `uint16_t`, `uint32_t`, `uint64_t`, and `absl::uint128`.
  message Integer {
    // Number of bits per integer. Must be a power of 2 and at most 128.
    int32 bitsize = 1;
  }

  // Describes a tuple of value types.
  message Tuple {
    repeated ValueType elements = 1;
  }

  // Describes an integer ring modulo `modulus`.
  message IntModN {
    // The underlying integer type used to represent elements in the ring.
    Integer base_integer = 1;
    // The modulus.
    Value.Integer modulus = 2;
  }

  oneof type {
    // A single integer modulo 2^l.
    Integer integer = 1;
    // A tuple of values.
    Tuple tuple = 2;
    // A integer with custom modulus.
    IntModN int_mod_n = 3;
    // An XOR-wrapped integer. Corresponds to the XorWrapper C++ class.
    Integer xor_wrapper = 4;
  }
  // Do not add fields outside of the `oneof` above, to ensure that messages
  // with known ValueTypes are serialized deterministically. See the
  // documentation of `value_correction_functions_` in
  // distributed_point_function.h for details.
}

// Used to correct output values to the desired DPF magnitude. Holds the values
// corresponding to the types defined in `ValueType`.
message Value {
  message Integer {
    oneof value {
      // Any value up to 64 bits.
      uint64 value_uint64 = 1;
      // 128-bit values.
      Block value_uint128 = 2;
    }
  }

  message Tuple {
    repeated Value elements = 1;
  }

  oneof value {
    Integer integer = 1;
    Tuple tuple = 2;
    Integer int_mod_n =
        3;  // The value of an IntModN is represented by its base_integer type.
    Integer xor_wrapper = 4;
  }
}
// LINT.ThenChange(
//   internal/value_type_helpers.h,
//   internal/value_type_helpers.cc
// )

// Parameters of a single hierarchy level of a distributed point function (DPF).
message DpfParameters {
  reserved 2;
  // Base-2 logarithm of the number of elements.
  int32 log_domain_size = 1;
  // Describes the type of output values at this hierarchy level.
  ValueType value_type = 3;
  // The negative logarithm of the total variation distance from uniform that an
  // evaluation at a *single point* at this hierarchy level is allowed to have.
  // The correct value for this parameter depends on the maximum number of
  // points at which this hierarchy level is evaluated. It should be at least 40
  // + log2(number_of_evaluation_points). Defaults to
  // ProtoValidator::kDefaultSecurityParameter + log_domain_size.
  double security_parameter = 4;
}

// A single 128-bit AES block.
message Block {
  uint64 high = 1;
  uint64 low = 2;
}

// A correction word used to evaluate a single layer in the DPF evaluation tree.
message CorrectionWord {
  // Block used to correct the new seeds after PRG evaluation.
  Block seed = 1;
  // Correction bits for the left and right control bits.
  bool control_left = 2;
  bool control_right = 3;
  // Reserved for deprecated value correction field.
  reserved 4;
  // Used to correct the output value at the previous tree layer. Only included
  // if the previous tree layer is an output layer. Repeated to capture the case
  // where multiple correction values are needed due to packing.
  repeated Value value_correction = 5;
}

// A key of a distributed point function (DPF).
message DpfKey {
  // Initial seed at the first level.
  Block seed = 1;
  // Correction words for each level after expansion.
  repeated CorrectionWord correction_words = 2;
  // Party this DpfKey belongs to (0 or 1).
  int32 party = 3;
  // Deprecated last level value correction.
  reserved 4;
  // Output correction for the last level of the evaluation tree.
  repeated Value last_level_value_correction = 5;
}

// Maps a single prefix of a DPF index to a PRG seed. Used to store partial
// evaluation state between hierarchy levels in `EvaluationContext`
message PartialEvaluation {
  // Prefix in the FSS evaluation tree. Does not necessarily coincide with the
  // corresponding prefix of the output domain at this hierarchy level.
  Block prefix = 1;
  // Seed for the next evaluation.
  Block seed = 2;
  // Control bit for the correction in the next evaluation.
  bool control_bit = 3;
}

// An EvaluationContext holds the state of a partially evaluated incremental
// DPF.
message EvaluationContext {
  // The parameters of the DPF being evaluated. One set of parameters for each
  // hierarchy level of the incremental DPF.
  repeated DpfParameters parameters = 1;
  // The DPF key being evaluated.
  DpfKey key = 2;
  // The hierarchy level that this EvaluationContext was last evaluated on.
  int32 previous_hierarchy_level = 3;
  // Maps prefixes from an earlier hierarchy level to PRG seeds, which are used
  // to continue the evaluation under each prefix. Uses a repeated message field
  // since Protobuf doesn't allow messages (such as `Block`) as map keys.
  repeated PartialEvaluation partial_evaluations = 4;
  // The hierarchy level `partial_evaluations` corresponds to. Ignored when
  // `partial_evaluations` is empty.
  int32 partial_evaluations_level = 5;
}