<commit_before>syntax = "proto3";

package wfa.measurement.internal.duchy;

option java_package = "org.wfanet.measurement.internal.duchy";
option java_multiple_files = true;

// Proto messages wrapping the input arguments or output results of the protocol
// encryption methods, which are to be called via JNI in the Duchy.
// Note that these protos contain sensitive data, e.g., private keys used in the
// ciphers. So they SHOULD NOT be written into any logs or leave the running
// process.

// Keys of the ElGamal cipher.
message ElGamalKeys {
  // Secret key of the ElGamal cipher.
  bytes el_gamal_sk = 1;
  // Public key g (generator) of the ElGamal cipher.
  bytes el_gamal_g = 2;
  // Public key y (g^sk) of the ElGamal cipher.
  bytes el_gamal_y = 3;
}

// The request to blind (one layer) all register indexes of a sketch.
// Only 3-tuple (register_index, fingerprint, count) registers are supported.
message BlindOneLayerRegisterIndexRequest {
  // The input sketch, which is a concatenation of a list of registers.
  // Each register contains a 3-tuple of (index, key, count), each of which is
  // a 66 bytes ElGamal ciphertext. In other words, the sketch size should be
  // divisible by 66*3.
  bytes sketch = 1;
  // Keys of the local ElGamal cipher. Required.
  ElGamalKeys local_el_gamal_keys = 2;
  // Secret key of the local Pohlig-Hellman cipher. Optional.
  // If unset, a random key will be used.
  bytes local_pohlig_hellman_sk = 3;
  // The elliptical curve to work on.
  int64 curve_id = 4;
}

// Response of the BlindOneLayerRegisterIndex method.
message BlindOneLayerRegisterIndexResponse {
  // The output sketch, whose register indexes are partially decrypted.
  // Each register contains a 3-tuple of (index, key, count), each of which is
  // a 66 bytes ElGamal ciphertext. In other words, the sketch size should be
  // divisible by 66*3.
  bytes sketch = 1;
  // The key used to create the local Pohlig Hellman cipher.
  // If the request specifies this key, the same value is returned,
  // otherwise, the randomly generated key is returned.
  bytes local_pohlig_hellman_sk = 2;
}

// The request to blind (last layer) the register indexes, and then join the
// registers by the deterministically encrypted register indexes, and then
// merge the counts using the same-key-aggregating algorithm.
message BlindLastLayerIndexThenJoinRegistersRequest {
  // The input sketch, which is a concatenation of a list of registers.
  // Each register contains a 3-tuple of (index, key, count), each of which is
  // a 66 bytes ElGamal ciphertext. In other words, the sketch size should be
  // divisible by 66*3.
  // There should be only one layer of ElGamal encryption left
  // on the register indexes. In other words, this method should only be called
  // by the primary duchy at the last stop of round 1.
  bytes sketch = 1;
  // Keys of the local ElGamal cipher. Required.
  ElGamalKeys local_el_gamal_keys = 2;
  // Secret key of the local Pohlig-Hellman cipher. Optional.
  // If unset, a random key will be used.
  bytes local_pohlig_hellman_sk = 3;
  // The elliptical curve to work on.
  int64 curve_id = 4;
  // Keys of the composite ElGamal cipher. Only public keys are required, i.e.,
  // el_gamal_g and el_gamal_y.
  ElGamalKeys composite_el_gamal_keys = 5;
}

// The response of the BlindLastLayerIndexThenJoinRegisters method.
message BlindLastLayerIndexThenJoinRegistersResponse {
  // A concatenation of a list of (flag, count) pairs in bytes.
  // Each flag or count is a 66 bytes ElGamal ciphertext, and the size of
  // flag_count_lists should be divisible by 132.
  bytes flag_counts = 1;
  // The key used to create the local Pohlig Hellman cipher.
  // If the request specifies this key, the same value is returned,
  // otherwise, the randomly generated key is returned.
  bytes local_pohlig_hellman_sk = 2;
}

// The request to decrypt one layer of ElGamal encryption on the flag and count
// of all registers.
message DecryptOneLayerFlagAndCountRequest {
  // A concatenation of a list of (flag, count) pairs in bytes.
  // Each flag or count is a 66 bytes ElGamal ciphertext, and the size of
  // flag_count_lists should be divisible by 132.
  bytes flag_counts = 1;
  // The keys used to create the local ElGamal cipher. required.
  ElGamalKeys local_el_gamal_keys = 2;
  // The elliptical curve to work on.
  int64 curve_id = 4;
}

// The response of the DecryptCountAndFlag method.
message DecryptOneLayerFlagAndCountResponse {
  // A concatenation of a list of (flag, count) pairs in bytes.
  // Each flag or count is a 66 bytes ElGamal ciphertext, and the size of
  // flag_count_lists should be divisible by 132.
  bytes flag_counts = 1;
}

// The request to decrypt the last layer of ElGamal encryption on the flag and
// count of all registers. Only called by the primary duchy as the last step of
// round 2.
message DecryptLastLayerFlagAndCountRequest {
  // A concatenation of a list of (flag, count) pairs in bytes.
  // Each flag or count is a 66 bytes ElGamal ciphertext, which only has one
  // layer of ElGamal encryption left.
  // The size of flag_count_lists should be divisible by 132.
  bytes flag_counts = 1;
  // The keys used to create the local ElGamal cipher. required.
  ElGamalKeys local_el_gamal_keys = 2;
  // Maximum frequency to display. Every count value greater than this value
  // is decrypted as the maximum_frequency.
  int32 maximum_frequency = 3;
  // The elliptical curve to work on.
  int64 curve_id = 4;
}

// The response of the DecryptCountAndFlag method.
message DecryptLastLayerFlagAndCountResponse {
  message FlagCount {
    // Decrypted is_not_destroyed flag. False indicates there are key conflict
    // at this register. True means all keys of this register are the same.
    bool is_not_destroyed = 1;
    // Decrypted count value, Caped by the maximum_frequency.
    int32 frequency = 2;
  }
  // (flag, count) result for each register index.
  repeated FlagCount flag_counts = 1;
}<commit_msg>Define the protos to be used in AddNoiseToSketch method.<commit_after>syntax = "proto3";

package wfa.measurement.internal.duchy;

option java_package = "org.wfanet.measurement.internal.duchy";
option java_multiple_files = true;

// Proto messages wrapping the input arguments or output results of the protocol
// encryption methods, which are to be called via JNI in the Duchy.
// Note that these protos contain sensitive data, e.g., private keys used in the
// ciphers. So they SHOULD NOT be written into any logs or leave the running
// process.

// Keys of the ElGamal cipher.
message ElGamalKeys {
  // Secret key of the ElGamal cipher.
  bytes el_gamal_sk = 1;
  // Public key g (generator) of the ElGamal cipher.
  bytes el_gamal_g = 2;
  // Public key y (g^sk) of the ElGamal cipher.
  bytes el_gamal_y = 3;
}

// The request to add noise registers to the sketch.
// Only 3-tuple (register_index, fingerprint, count) registers are supported.
message AddNoiseToSketchRequest {
  // The input sketch, which is a concatenation of a list of registers.
  // Each register contains a 3-tuple of (index, key, count), each of which is
  // a 66 bytes ElGamal ciphertext. In other words, the sketch size should be
  // divisible by 66*3.
  // The sketch is only needed so the noise can be interleaved and hidden in the
  // sktech. The registers in the sketch are unchanged, except for their orders.
  bytes sketch = 1;
  // Keys of the composite ElGamal cipher. Only public keys are required, i.e.,
  // el_gamal_g and el_gamal_y.
  ElGamalKeys composite_el_gamal_keys = 2;
  // The elliptical curve to work on.
  int64 curve_id = 3;
  // Maximum frequency to display. Every count value greater than this value
  // is decrypted as the maximum_frequency. Hiding counts above the
  // maximum_frequency impacts how much moise is needed to achieve differential
  // privacy.
  int32 maximum_frequency = 4;
  // The baseline of noise agreed by all workers.
  int32 noise_baseline = 5;
}

// Response of the AddNoiseToSketch method.
message AddNoiseToSketchResponse {
  // The output sketch, which contains shuffled input and noise registers.
  // Each register contains a 3-tuple of (index, key, count), each of which is
  // a 66 bytes ElGamal ciphertext. In other words, the sketch size should be
  // divisible by 66*3.
  bytes sketch = 1;
}

// The request to blind (one layer) all register indexes of a sketch.
// Only 3-tuple (register_index, fingerprint, count) registers are supported.
message BlindOneLayerRegisterIndexRequest {
  // The input sketch, which is a concatenation of a list of registers.
  // Each register contains a 3-tuple of (index, key, count), each of which is
  // a 66 bytes ElGamal ciphertext. In other words, the sketch size should be
  // divisible by 66*3.
  bytes sketch = 1;
  // Keys of the local ElGamal cipher. Required.
  ElGamalKeys local_el_gamal_keys = 2;
  // Secret key of the local Pohlig-Hellman cipher. Optional.
  // If unset, a random key will be used.
  bytes local_pohlig_hellman_sk = 3;
  // The elliptical curve to work on.
  int64 curve_id = 4;
}

// Response of the BlindOneLayerRegisterIndex method.
message BlindOneLayerRegisterIndexResponse {
  // The output sketch, whose register indexes are partially decrypted.
  // Each register contains a 3-tuple of (index, key, count), each of which is
  // a 66 bytes ElGamal ciphertext. In other words, the sketch size should be
  // divisible by 66*3.
  bytes sketch = 1;
  // The key used to create the local Pohlig Hellman cipher.
  // If the request specifies this key, the same value is returned,
  // otherwise, the randomly generated key is returned.
  bytes local_pohlig_hellman_sk = 2;
}

// The request to blind (last layer) the register indexes, and then join the
// registers by the deterministically encrypted register indexes, and then
// merge the counts using the same-key-aggregating algorithm.
message BlindLastLayerIndexThenJoinRegistersRequest {
  // The input sketch, which is a concatenation of a list of registers.
  // Each register contains a 3-tuple of (index, key, count), each of which is
  // a 66 bytes ElGamal ciphertext. In other words, the sketch size should be
  // divisible by 66*3.
  // There should be only one layer of ElGamal encryption left
  // on the register indexes. In other words, this method should only be called
  // by the primary duchy at the last stop of round 1.
  bytes sketch = 1;
  // Keys of the local ElGamal cipher. Required.
  ElGamalKeys local_el_gamal_keys = 2;
  // Secret key of the local Pohlig-Hellman cipher. Optional.
  // If unset, a random key will be used.
  bytes local_pohlig_hellman_sk = 3;
  // The elliptical curve to work on.
  int64 curve_id = 4;
  // Keys of the composite ElGamal cipher. Only public keys are required, i.e.,
  // el_gamal_g and el_gamal_y.
  ElGamalKeys composite_el_gamal_keys = 5;
}

// The response of the BlindLastLayerIndexThenJoinRegisters method.
message BlindLastLayerIndexThenJoinRegistersResponse {
  // A concatenation of a list of (flag, count) pairs in bytes.
  // Each flag or count is a 66 bytes ElGamal ciphertext, and the size of
  // flag_count_lists should be divisible by 132.
  bytes flag_counts = 1;
  // The key used to create the local Pohlig Hellman cipher.
  // If the request specifies this key, the same value is returned,
  // otherwise, the randomly generated key is returned.
  bytes local_pohlig_hellman_sk = 2;
}

// The request to decrypt one layer of ElGamal encryption on the flag and count
// of all registers.
message DecryptOneLayerFlagAndCountRequest {
  // A concatenation of a list of (flag, count) pairs in bytes.
  // Each flag or count is a 66 bytes ElGamal ciphertext, and the size of
  // flag_count_lists should be divisible by 132.
  bytes flag_counts = 1;
  // The keys used to create the local ElGamal cipher. required.
  ElGamalKeys local_el_gamal_keys = 2;
  // The elliptical curve to work on.
  int64 curve_id = 4;
}

// The response of the DecryptCountAndFlag method.
message DecryptOneLayerFlagAndCountResponse {
  // A concatenation of a list of (flag, count) pairs in bytes.
  // Each flag or count is a 66 bytes ElGamal ciphertext, and the size of
  // flag_count_lists should be divisible by 132.
  bytes flag_counts = 1;
}

// The request to decrypt the last layer of ElGamal encryption on the flag and
// count of all registers. Only called by the primary duchy as the last step of
// round 2.
message DecryptLastLayerFlagAndCountRequest {
  // A concatenation of a list of (flag, count) pairs in bytes.
  // Each flag or count is a 66 bytes ElGamal ciphertext, which only has one
  // layer of ElGamal encryption left.
  // The size of flag_count_lists should be divisible by 132.
  bytes flag_counts = 1;
  // The keys used to create the local ElGamal cipher. required.
  ElGamalKeys local_el_gamal_keys = 2;
  // Maximum frequency to display. Every count value greater than this value
  // is decrypted as the maximum_frequency.
  int32 maximum_frequency = 3;
  // The elliptical curve to work on.
  int64 curve_id = 4;
}

// The response of the DecryptCountAndFlag method.
message DecryptLastLayerFlagAndCountResponse {
  message FlagCount {
    // Decrypted is_not_destroyed flag. False indicates there are key conflict
    // at this register. True means all keys of this register are the same.
    bool is_not_destroyed = 1;
    // Decrypted count value, Caped by the maximum_frequency.
    int32 frequency = 2;
  }
  // (flag, count) result for each register index.
  repeated FlagCount flag_counts = 1;
}
{'fraction_non_alphanumeric': 0.0669416010015465, 'fraction_numerical': 0.013771264452463362, 'mean_word_length': 3.367963975554841, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4370663', 'n_tokens_mistral': 4303, 'n_tokens_neox': 3991, 'n_words': 1839}