xref: /aosp_15_r20/external/tink/cc/subtle/hkdf.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2017 Google Inc.
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_SUBTLE_HKDF_H_
18 #define TINK_SUBTLE_HKDF_H_
19 
20 #include <string>
21 
22 #include "absl/strings/string_view.h"
23 #include "tink/subtle/common_enums.h"
24 #include "tink/util/secret_data.h"
25 #include "tink/util/status.h"
26 #include "tink/util/statusor.h"
27 
28 namespace crypto {
29 namespace tink {
30 namespace subtle {
31 
32 // TODO(wiktorg) delete non-SecretData variant once all clients are migrated
33 class Hkdf {
34  public:
35   // Computes hkdf according to RFC5869.
36   static crypto::tink::util::StatusOr<std::string> ComputeHkdf(
37       HashType hash, absl::string_view ikm, absl::string_view salt,
38       absl::string_view info, size_t out_len);
39   static crypto::tink::util::StatusOr<util::SecretData> ComputeHkdf(
40       HashType hash, const util::SecretData& ikm, absl::string_view salt,
41       absl::string_view info, size_t out_len);
42 
43   // Computes symmetric key for ECIES with HKDF from the provided parameters.
44   // This function follows Shoup's recommendation of including ECIES
45   // ephemeral KEM bytes into the commputation of the symmetric key
46   // (cf. http://eprint.iacr.org/2001/112.pdf, Sections 15.6 and 15.6.1)
47   static crypto::tink::util::StatusOr<util::SecretData>
48   ComputeEciesHkdfSymmetricKey(HashType hash, absl::string_view kem_bytes,
49                                const util::SecretData& shared_secret,
50                                absl::string_view salt, absl::string_view info,
51                                size_t out_len);
52 };
53 }  // namespace subtle
54 }  // namespace tink
55 }  // namespace crypto
56 
57 #endif  // TINK_SUBTLE_HKDF_H_
58