/*
 * Copyright 2019 Contributors to the Parsec project.
 * SPDX-License-Identifier: Apache-2.0
 */
syntax = "proto3";

package psa_algorithm;

message Algorithm {
  message None {}
  enum Hash {
    HASH_NONE = 0; // This default variant should not be used.
    MD2 = 1 [ deprecated = true ];
    MD4 = 2 [ deprecated = true ];
    MD5 = 3 [ deprecated = true ];
    RIPEMD160 = 4;
    SHA_1 = 5 [ deprecated = true ];
    SHA_224 = 6;
    SHA_256 = 7;
    SHA_384 = 8;
    SHA_512 = 9;
    SHA_512_224 = 10;
    SHA_512_256 = 11;
    SHA3_224 = 12;
    SHA3_256 = 13;
    SHA3_384 = 14;
    SHA3_512 = 15;
  }
  message Mac {
    message FullLength {
      message Hmac { Hash hash_alg = 1; }
      message CbcMac {}
      message Cmac {}

      oneof variant {
        Hmac hmac = 1;
        CbcMac cbc_mac = 2;
        Cmac cmac = 3;
      }
    }
    message Truncated {
      FullLength mac_alg = 1;
      uint32 mac_length = 2;
    }

    oneof variant {
      FullLength full_length = 1;
      Truncated truncated = 2;
    }
  }
  enum Cipher {
    CIPHER_NONE = 0; // This default variant should not be used.
    STREAM_CIPHER = 1;
    CTR = 2;
    CFB = 3;
    OFB = 4;
    XTS = 5;
    ECB_NO_PADDING = 6;
    CBC_NO_PADDING = 7;
    CBC_PKCS7 = 8;
  }
  message Aead {
    enum AeadWithDefaultLengthTag {
      AEAD_WITH_DEFAULT_LENGTH_TAG_NONE =
          0; // This default variant should not be used.
      CCM = 1;
      GCM = 2;
      CHACHA20_POLY1305 = 3;
    }
    message AeadWithShortenedTag {
      AeadWithDefaultLengthTag aead_alg = 1;
      uint32 tag_length = 2;
    }

    oneof variant {
      AeadWithDefaultLengthTag aead_with_default_length_tag = 1;
      AeadWithShortenedTag aead_with_shortened_tag = 2;
    }
  }
  message AsymmetricSignature {
    message SignHash {
      message Any {}

      oneof variant {
        Any any = 1;
        Hash specific = 2;
      }
    }
    message RsaPkcs1v15Sign { SignHash hash_alg = 1; }
    message RsaPkcs1v15SignRaw {}
    message RsaPss { SignHash hash_alg = 1; }
    message Ecdsa { SignHash hash_alg = 1; }
    message EcdsaAny {}
    message DeterministicEcdsa { SignHash hash_alg = 1; }

    oneof variant {
      RsaPkcs1v15Sign rsa_pkcs1v15_sign = 1;
      RsaPkcs1v15SignRaw rsa_pkcs1v15_sign_raw = 2;
      RsaPss rsa_pss = 3;
      Ecdsa ecdsa = 4;
      EcdsaAny ecdsa_any = 5;
      DeterministicEcdsa deterministic_ecdsa = 6;
    }
  }
  message AsymmetricEncryption {
    message RsaPkcs1v15Crypt {}
    message RsaOaep { Hash hash_alg = 1; }

    oneof variant {
      RsaPkcs1v15Crypt rsa_pkcs1v15_crypt = 1;
      RsaOaep rsa_oaep = 2;
    }
  }
  message KeyAgreement {
    enum Raw {
      RAW_NONE = 0; // This default variant should not be used.
      FFDH = 1;
      ECDH = 2;
    }
    message WithKeyDerivation {
      Raw ka_alg = 1;
      KeyDerivation kdf_alg = 2;
    }

    oneof variant {
      Raw raw = 1;
      WithKeyDerivation with_key_derivation = 2;
    }
  }
  message KeyDerivation {
    message Hkdf { Hash hash_alg = 1; }
    message Tls12Prf { Hash hash_alg = 1; }
    message Tls12PskToMs { Hash hash_alg = 1; }

    oneof variant {
      Hkdf hkdf = 1;
      Tls12Prf tls12_prf = 2;
      Tls12PskToMs tls12_psk_to_ms = 3;
    }
  }

  oneof variant {
    None none = 1;
    Hash hash = 2;
    Mac mac = 3;
    Cipher cipher = 4;
    Aead aead = 5;
    AsymmetricSignature asymmetric_signature = 6;
    AsymmetricEncryption asymmetric_encryption = 7;
    KeyAgreement key_agreement = 8;
    KeyDerivation key_derivation = 9;
  }
}
