1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 /////////////////////////////////////////////////////////////////////////////// 16 17 #ifndef TINK_HYBRID_INTERNAL_HPKE_UTIL_H_ 18 #define TINK_HYBRID_INTERNAL_HPKE_UTIL_H_ 19 20 #include "tink/util/statusor.h" 21 #include "proto/hpke.pb.h" 22 23 namespace crypto { 24 namespace tink { 25 namespace internal { 26 27 // Values from https://www.rfc-editor.org/rfc/rfc9180.html#section-7.1. 28 enum class HpkeKem { 29 kUnknownKem = 0x0, 30 kX25519HkdfSha256 = 0x20, 31 }; 32 33 // Values from https://www.rfc-editor.org/rfc/rfc9180.html#section-7.2. 34 enum class HpkeKdf { 35 kUnknownKdf = 0x0, 36 kHkdfSha256 = 0x1, 37 }; 38 39 // Values from https://www.rfc-editor.org/rfc/rfc9180.html#section-7.3. 40 enum class HpkeAead { 41 kUnknownAead = 0x0, 42 kAes128Gcm = 0x1, 43 kAes256Gcm = 0x2, 44 kChaCha20Poly1305 = 0x3, 45 }; 46 47 struct HpkeParams { 48 HpkeKem kem; 49 HpkeKdf kdf; 50 HpkeAead aead; 51 }; 52 53 // Converts a google::crypto::tink::HpkeParams proto to an HpkeParams struct. 54 util::StatusOr<HpkeParams> HpkeParamsProtoToStruct( 55 google::crypto::tink::HpkeParams params); 56 57 // Returns the encapsulated key length (in bytes) for the specified `kem`. 58 util::StatusOr<int32_t> HpkeEncapsulatedKeyLength( 59 google::crypto::tink::HpkeKem kem); 60 61 } // namespace internal 62 } // namespace tink 63 } // namespace crypto 64 65 #endif // TINK_HYBRID_INTERNAL_HPKE_UTIL_H_ 66