Upload upstream chromium 71.0.3578.0
[platform/framework/web/chromium-efl.git] / crypto / hkdf.cc
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
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/logging.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(base::StringPiece secret,
20                        base::StringPiece salt,
21                        base::StringPiece 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 }  // namespace crypto