1*e7b1675dSTing-Kang Chang// Copyright 2017 Google Inc. 2*e7b1675dSTing-Kang Chang// 3*e7b1675dSTing-Kang Chang// Licensed under the Apache License, Version 2.0 (the "License"); 4*e7b1675dSTing-Kang Chang// you may not use this file except in compliance with the License. 5*e7b1675dSTing-Kang Chang// You may obtain a copy of the License at 6*e7b1675dSTing-Kang Chang// 7*e7b1675dSTing-Kang Chang// http://www.apache.org/licenses/LICENSE-2.0 8*e7b1675dSTing-Kang Chang// 9*e7b1675dSTing-Kang Chang// Unless required by applicable law or agreed to in writing, software 10*e7b1675dSTing-Kang Chang// distributed under the License is distributed on an "AS IS" BASIS, 11*e7b1675dSTing-Kang Chang// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*e7b1675dSTing-Kang Chang// See the License for the specific language governing permissions and 13*e7b1675dSTing-Kang Chang// limitations under the License. 14*e7b1675dSTing-Kang Chang// 15*e7b1675dSTing-Kang Chang//////////////////////////////////////////////////////////////////////////////// 16*e7b1675dSTing-Kang Chang 17*e7b1675dSTing-Kang Chang// Definitions for Cloud Crypto SDK (Tink) library. 18*e7b1675dSTing-Kang Changsyntax = "proto3"; 19*e7b1675dSTing-Kang Chang 20*e7b1675dSTing-Kang Changpackage google.crypto.tink; 21*e7b1675dSTing-Kang Chang 22*e7b1675dSTing-Kang Changoption java_package = "com.google.crypto.tink.proto"; 23*e7b1675dSTing-Kang Changoption java_multiple_files = true; 24*e7b1675dSTing-Kang Changoption go_package = "github.com/google/tink/go/proto/tink_go_proto"; 25*e7b1675dSTing-Kang Changoption objc_class_prefix = "TINKPB"; 26*e7b1675dSTing-Kang Chang 27*e7b1675dSTing-Kang Chang// Each instantiation of a Tink primitive is identified by type_url, 28*e7b1675dSTing-Kang Chang// which is a global URL pointing to a *Key-proto that holds key material 29*e7b1675dSTing-Kang Chang// and other parameters of the instantiation. For standard Tink key types 30*e7b1675dSTing-Kang Chang// the value of type_url follows the structure of type_url-field of 31*e7b1675dSTing-Kang Chang// google.protobuf.Any-protos, and is given as: 32*e7b1675dSTing-Kang Chang// 33*e7b1675dSTing-Kang Chang// type.googleapis.com/packagename.messagename 34*e7b1675dSTing-Kang Chang// 35*e7b1675dSTing-Kang Chang// For example, for an HMAC key defined in proto google.cloud.tink.HmacKey 36*e7b1675dSTing-Kang Chang// the value of type_url is: 37*e7b1675dSTing-Kang Chang// 38*e7b1675dSTing-Kang Chang// type.googleapis.com/google.cloud.tink.HmacKey 39*e7b1675dSTing-Kang Chang// 40*e7b1675dSTing-Kang Chang// For each type_url, in addition to the *Key proto, there exist two 41*e7b1675dSTing-Kang Chang// related structures: 42*e7b1675dSTing-Kang Chang// 1. *Params: parameters of an instantiation of the primitive, 43*e7b1675dSTing-Kang Chang// needed when a key is being used. 44*e7b1675dSTing-Kang Chang// 2. *KeyFormat: parameters needed to generate a new key; these 45*e7b1675dSTing-Kang Chang// include the corresponding Params, since when a factory generates 46*e7b1675dSTing-Kang Chang// a key based on KeyFormat, it must add Params to the resulting 47*e7b1675dSTing-Kang Chang// key proto with the actual key material. 48*e7b1675dSTing-Kang Chang// The actual *KeyFormat proto is wrapped in a KeyTemplate message. 49*e7b1675dSTing-Kang Chang// By convention, the name of the *KeyFormat-proto must be equal 50*e7b1675dSTing-Kang Chang// to the name of the *Key-proto from type_url-field suffixed with "Format". 51*e7b1675dSTing-Kang Chang 52*e7b1675dSTing-Kang Changmessage KeyTemplate { 53*e7b1675dSTing-Kang Chang // Required. The type_url of the key type in format 54*e7b1675dSTing-Kang Chang // type.googleapis.com/packagename.messagename -- see above for details. 55*e7b1675dSTing-Kang Chang // This is typically the protobuf type URL of the *Key proto. In particular, 56*e7b1675dSTing-Kang Chang // this is different of the protobuf type URL of the *KeyFormat proto. 57*e7b1675dSTing-Kang Chang string type_url = 1; 58*e7b1675dSTing-Kang Chang 59*e7b1675dSTing-Kang Chang // Required. The serialized *KeyFormat proto. 60*e7b1675dSTing-Kang Chang bytes value = 2; 61*e7b1675dSTing-Kang Chang 62*e7b1675dSTing-Kang Chang // Required. The type of prefix used when computing some primitives to 63*e7b1675dSTing-Kang Chang // identify the ciphertext/signature, etc. 64*e7b1675dSTing-Kang Chang OutputPrefixType output_prefix_type = 3; 65*e7b1675dSTing-Kang Chang} 66*e7b1675dSTing-Kang Chang 67*e7b1675dSTing-Kang Changenum KeyStatusType { 68*e7b1675dSTing-Kang Chang UNKNOWN_STATUS = 0; 69*e7b1675dSTing-Kang Chang ENABLED = 1; // Can be used for crypto operations. 70*e7b1675dSTing-Kang Chang DISABLED = 2; // Cannot be used, but exists and can become ENABLED. 71*e7b1675dSTing-Kang Chang DESTROYED = 3; // Key data does not exist in this Keyset any more. 72*e7b1675dSTing-Kang Chang} 73*e7b1675dSTing-Kang Chang 74*e7b1675dSTing-Kang Chang// Tink produces and accepts ciphertexts or signatures that consist 75*e7b1675dSTing-Kang Chang// of a prefix and a payload. The payload and its format is determined 76*e7b1675dSTing-Kang Chang// entirely by the primitive, but the prefix has to be one of the following 77*e7b1675dSTing-Kang Chang// 4 types: 78*e7b1675dSTing-Kang Chang// - Legacy: prefix is 5 bytes, starts with \x00 and followed by a 4-byte 79*e7b1675dSTing-Kang Chang// key id that is computed from the key material. In addition to 80*e7b1675dSTing-Kang Chang// that, signature schemes and MACs will add a \x00 byte to the 81*e7b1675dSTing-Kang Chang// end of the data being signed / MACed when operating on keys 82*e7b1675dSTing-Kang Chang// with this OutputPrefixType. 83*e7b1675dSTing-Kang Chang// - Crunchy: prefix is 5 bytes, starts with \x00 and followed by a 4-byte 84*e7b1675dSTing-Kang Chang// key id that is generated randomly. 85*e7b1675dSTing-Kang Chang// - Tink : prefix is 5 bytes, starts with \x01 and followed by 4-byte 86*e7b1675dSTing-Kang Chang// key id that is generated randomly. 87*e7b1675dSTing-Kang Chang// - Raw : prefix is 0 byte, i.e., empty. 88*e7b1675dSTing-Kang Changenum OutputPrefixType { 89*e7b1675dSTing-Kang Chang UNKNOWN_PREFIX = 0; 90*e7b1675dSTing-Kang Chang TINK = 1; 91*e7b1675dSTing-Kang Chang LEGACY = 2; 92*e7b1675dSTing-Kang Chang RAW = 3; 93*e7b1675dSTing-Kang Chang CRUNCHY = 4; 94*e7b1675dSTing-Kang Chang} 95*e7b1675dSTing-Kang Chang 96*e7b1675dSTing-Kang Chang// Each *Key proto by convention contains a version field, which 97*e7b1675dSTing-Kang Chang// identifies the version of the key. 98*e7b1675dSTing-Kang Chang// message SomeInstantiationKey { 99*e7b1675dSTing-Kang Chang// uint32 version = 1; 100*e7b1675dSTing-Kang Chang// ... 101*e7b1675dSTing-Kang Chang// } 102*e7b1675dSTing-Kang Chang// If a key type does not mention anything else, only version 0 is currently 103*e7b1675dSTing-Kang Chang// specified. An implementation must only accept keys with versions it knows, 104*e7b1675dSTing-Kang Chang// and must reject all keys with unknown version. 105*e7b1675dSTing-Kang Chang 106*e7b1675dSTing-Kang Chang// For public key primitives, the public and private keys are distinct entities 107*e7b1675dSTing-Kang Chang// and represent distinct primitives. However, by convention, the private key 108*e7b1675dSTing-Kang Chang// of a public-key primitive contains the corresponding public key proto. 109*e7b1675dSTing-Kang Chang 110*e7b1675dSTing-Kang Chang// The actual *Key-proto is wrapped in a KeyData message, which in addition 111*e7b1675dSTing-Kang Chang// to this serialized proto contains also type_url identifying the 112*e7b1675dSTing-Kang Chang// definition of *Key-proto (as in KeyFormat-message), and some extra metadata 113*e7b1675dSTing-Kang Chang// about the type key material. 114*e7b1675dSTing-Kang Changmessage KeyData { 115*e7b1675dSTing-Kang Chang // Required. 116*e7b1675dSTing-Kang Chang string type_url = 1; // In format type.googleapis.com/packagename.messagename 117*e7b1675dSTing-Kang Chang // Required. 118*e7b1675dSTing-Kang Chang // Contains specific serialized *Key proto 119*e7b1675dSTing-Kang Chang bytes value = 2; // Placeholder for ctype. 120*e7b1675dSTing-Kang Chang enum KeyMaterialType { 121*e7b1675dSTing-Kang Chang UNKNOWN_KEYMATERIAL = 0; 122*e7b1675dSTing-Kang Chang SYMMETRIC = 1; 123*e7b1675dSTing-Kang Chang ASYMMETRIC_PRIVATE = 2; 124*e7b1675dSTing-Kang Chang ASYMMETRIC_PUBLIC = 3; 125*e7b1675dSTing-Kang Chang REMOTE = 4; // points to a remote key, i.e., in a KMS. 126*e7b1675dSTing-Kang Chang } 127*e7b1675dSTing-Kang Chang // Required. 128*e7b1675dSTing-Kang Chang KeyMaterialType key_material_type = 3; 129*e7b1675dSTing-Kang Chang} 130*e7b1675dSTing-Kang Chang 131*e7b1675dSTing-Kang Chang// A Tink user works usually not with single keys, but with keysets, 132*e7b1675dSTing-Kang Chang// to enable key rotation. The keys in a keyset can belong to different 133*e7b1675dSTing-Kang Chang// implementations/key types, but must all implement the same primitive. 134*e7b1675dSTing-Kang Chang// Any given keyset (and any given key) can be used for one primitive only. 135*e7b1675dSTing-Kang Changmessage Keyset { 136*e7b1675dSTing-Kang Chang message Key { 137*e7b1675dSTing-Kang Chang // Contains the actual, instantiation specific key proto. 138*e7b1675dSTing-Kang Chang // By convention, each key proto contains a version field. 139*e7b1675dSTing-Kang Chang KeyData key_data = 1; 140*e7b1675dSTing-Kang Chang 141*e7b1675dSTing-Kang Chang KeyStatusType status = 2; 142*e7b1675dSTing-Kang Chang 143*e7b1675dSTing-Kang Chang // Identifies a key within a keyset, is a part of metadata 144*e7b1675dSTing-Kang Chang // of a ciphertext/signature. 145*e7b1675dSTing-Kang Chang uint32 key_id = 3; 146*e7b1675dSTing-Kang Chang 147*e7b1675dSTing-Kang Chang // Determines the prefix of the ciphertexts/signatures produced by this key. 148*e7b1675dSTing-Kang Chang // This value is copied verbatim from the key template. 149*e7b1675dSTing-Kang Chang OutputPrefixType output_prefix_type = 4; 150*e7b1675dSTing-Kang Chang } 151*e7b1675dSTing-Kang Chang 152*e7b1675dSTing-Kang Chang // Identifies key used to generate new crypto data (encrypt, sign). 153*e7b1675dSTing-Kang Chang // Required. 154*e7b1675dSTing-Kang Chang uint32 primary_key_id = 1; 155*e7b1675dSTing-Kang Chang 156*e7b1675dSTing-Kang Chang // Actual keys in the Keyset. 157*e7b1675dSTing-Kang Chang // Required. 158*e7b1675dSTing-Kang Chang repeated Key key = 2; 159*e7b1675dSTing-Kang Chang} 160*e7b1675dSTing-Kang Chang 161*e7b1675dSTing-Kang Chang// Represents a "safe" Keyset that doesn't contain any actual key material, 162*e7b1675dSTing-Kang Chang// thus can be used for logging or monitoring. Most fields are copied from 163*e7b1675dSTing-Kang Chang// Keyset. 164*e7b1675dSTing-Kang Changmessage KeysetInfo { 165*e7b1675dSTing-Kang Chang message KeyInfo { 166*e7b1675dSTing-Kang Chang // the type url of this key, 167*e7b1675dSTing-Kang Chang // e.g., type.googleapis.com/google.crypto.tink.HmacKey. 168*e7b1675dSTing-Kang Chang string type_url = 1; 169*e7b1675dSTing-Kang Chang 170*e7b1675dSTing-Kang Chang // See Keyset.Key.status. 171*e7b1675dSTing-Kang Chang KeyStatusType status = 2; 172*e7b1675dSTing-Kang Chang 173*e7b1675dSTing-Kang Chang // See Keyset.Key.key_id. 174*e7b1675dSTing-Kang Chang uint32 key_id = 3; 175*e7b1675dSTing-Kang Chang 176*e7b1675dSTing-Kang Chang // See Keyset.Key.output_prefix_type. 177*e7b1675dSTing-Kang Chang OutputPrefixType output_prefix_type = 4; 178*e7b1675dSTing-Kang Chang } 179*e7b1675dSTing-Kang Chang 180*e7b1675dSTing-Kang Chang // See Keyset.primary_key_id. 181*e7b1675dSTing-Kang Chang uint32 primary_key_id = 1; 182*e7b1675dSTing-Kang Chang 183*e7b1675dSTing-Kang Chang // KeyInfos in the KeysetInfo. 184*e7b1675dSTing-Kang Chang // Each KeyInfo is corresponding to a Key in the corresponding Keyset. 185*e7b1675dSTing-Kang Chang repeated KeyInfo key_info = 2; 186*e7b1675dSTing-Kang Chang} 187*e7b1675dSTing-Kang Chang 188*e7b1675dSTing-Kang Chang// Represents a keyset that is encrypted with a master key. 189*e7b1675dSTing-Kang Changmessage EncryptedKeyset { 190*e7b1675dSTing-Kang Chang // Required. 191*e7b1675dSTing-Kang Chang bytes encrypted_keyset = 2; 192*e7b1675dSTing-Kang Chang // Optional. 193*e7b1675dSTing-Kang Chang KeysetInfo keyset_info = 3; 194*e7b1675dSTing-Kang Chang} 195