[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / crypto / hkdf.cc
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "crypto/hkdf.h"
6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <memory>
11
12 #include "base/check.h"
13 #include "crypto/hmac.h"
14 #include "third_party/boringssl/src/include/openssl/digest.h"
15 #include "third_party/boringssl/src/include/openssl/hkdf.h"
16
17 namespace crypto {
18
19 std::string HkdfSha256(std::string_view secret,
20                        std::string_view salt,
21                        std::string_view info,
22                        size_t derived_key_size) {
23   std::string key;
24   key.resize(derived_key_size);
25   int result = ::HKDF(
26       reinterpret_cast<uint8_t*>(&key[0]), derived_key_size, EVP_sha256(),
27       reinterpret_cast<const uint8_t*>(secret.data()), secret.size(),
28       reinterpret_cast<const uint8_t*>(salt.data()), salt.size(),
29       reinterpret_cast<const uint8_t*>(info.data()), info.size());
30   DCHECK(result);
31   return key;
32 }
33
34 std::vector<uint8_t> HkdfSha256(base::span<const uint8_t> secret,
35                                 base::span<const uint8_t> salt,
36                                 base::span<const uint8_t> info,
37                                 size_t derived_key_size) {
38   std::vector<uint8_t> ret;
39   ret.resize(derived_key_size);
40   int result =
41       ::HKDF(ret.data(), derived_key_size, EVP_sha256(), secret.data(),
42              secret.size(), salt.data(), salt.size(), info.data(), info.size());
43   DCHECK(result);
44   return ret;
45 }
46
47 }  // namespace crypto