// 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 google.crypto.tink;

import "proto/common.proto";
import "proto/tink.proto";

option java_package = "com.google.crypto.tink.proto";
option java_multiple_files = true;
option go_package = "github.com/google/tink/proto/cecpq2_aead_hkdf_go_proto";

// Protos for keys for CECPQ2 with HKDF and AEAD encryption.
//
// These definitions follow loosely ECIES ISO 18033-2 standard
// (Elliptic Curve Integrated Encryption Scheme, see
// http://www.shoup.net/iso/std6.pdf), with but with some differences:
//  * use of CECPQ2 as the KEM instead of ECC-only KEM
//  * use of HKDF key derivation function (instead of KDF1 and KDF2) enabling
//  the use
//    of optional parameters to the key derivation function, which strenghten
//    the overall security and allow for binding the key material to
//    application-specific information (cf. RFC 5869,
//    https://tools.ietf.org/html/rfc5869)
//  * use of modern AEAD schemes rather than "manual composition" of symmetric
//  encryption
//    with message authentication codes (as in DEM1, DEM2, and DEM3 schemes of
//    ISO 18033-2)
//
// CECPQ2-keys represent HybridEncryption resp. HybridDecryption primitives.

// Parameters of KEM (Key Encapsulation Mechanism)
message Cecpq2HkdfKemParams {
  // Required.
  EllipticCurveType curve_type = 1;

  // Required.
  EcPointFormat ec_point_format = 2;

  // Required.
  HashType hkdf_hash_type = 3;

  // Optional.
  bytes hkdf_salt = 11;
}

// Parameters of AEAD DEM (Data Encapsulation Mechanism).
message Cecpq2AeadDemParams {
  // Contains e.g. AesCtrHmacAeadKeyFormat or AesGcmKeyFormat.
  // Required.
  KeyTemplate aead_dem = 2;
}

message Cecpq2AeadHkdfParams {
  // Key Encapsulation Mechanism.
  // Required.
  Cecpq2HkdfKemParams kem_params = 1;

  // Data Encapsulation Mechanism.
  // Required.
  Cecpq2AeadDemParams dem_params = 2;
}

// Cecpq2AeadHkdfPublicKey represents HybridEncryption primitive.
// key_type: type.googleapis.com/google.crypto.tink.Cecpq2AeadHkdfPublicKey
message Cecpq2AeadHkdfPublicKey {
  // Required.
  uint32 version = 1;
  // Required.
  Cecpq2AeadHkdfParams params = 2;

  // X25519 public key: Affine coordinates of the public key in bigendian
  // representation. The public key is a point (x, y) on the Curve25519.
  // Required.
  bytes x25519_public_key_x = 3;
  // Required.
  bytes x25519_public_key_y = 4;

  // HRSS public key:
  // Required.
  bytes hrss_public_key_marshalled = 5;
}

// Cecpq2KdfAeadPrivateKey represents HybridDecryption primitive.
// key_type: type.googleapis.com/google.crypto.tink.Cecpq2AeadHkdfPrivateKey
message Cecpq2AeadHkdfPrivateKey {
  // Required.
  uint32 version = 1;

  // Required.
  Cecpq2AeadHkdfPublicKey public_key = 2;

  // X25519 private key:
  // Required.
  bytes x25519_private_key = 3;  // Big integer in bigendian representation.

  // HRSS private key seed:
  // Required.
  bytes hrss_private_key_seed = 4;
}

message Cecpq2AeadHkdfKeyFormat {
  // Required.
  Cecpq2AeadHkdfParams params = 1;
}
