Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: crypto/hkdf.cc

Issue 1870233002: Convert crypto to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « crypto/encryptor_unittest.cc ('k') | crypto/hmac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "crypto/hkdf.h" 5 #include "crypto/hkdf.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory>
11
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "crypto/hmac.h" 13 #include "crypto/hmac.h"
13 14
14 namespace crypto { 15 namespace crypto {
15 16
16 const size_t kSHA256HashLength = 32; 17 const size_t kSHA256HashLength = 32;
17 18
18 HKDF::HKDF(const base::StringPiece& secret, 19 HKDF::HKDF(const base::StringPiece& secret,
19 const base::StringPiece& salt, 20 const base::StringPiece& salt,
20 const base::StringPiece& info, 21 const base::StringPiece& info,
21 size_t key_bytes_to_generate, 22 size_t key_bytes_to_generate,
(...skipping 26 matching lines...) Expand all
48 const size_t material_length = 2 * key_bytes_to_generate + 49 const size_t material_length = 2 * key_bytes_to_generate +
49 2 * iv_bytes_to_generate + 50 2 * iv_bytes_to_generate +
50 subkey_secret_bytes_to_generate; 51 subkey_secret_bytes_to_generate;
51 const size_t n = (material_length + kSHA256HashLength-1) / 52 const size_t n = (material_length + kSHA256HashLength-1) /
52 kSHA256HashLength; 53 kSHA256HashLength;
53 DCHECK_LT(n, 256u); 54 DCHECK_LT(n, 256u);
54 55
55 output_.resize(n * kSHA256HashLength); 56 output_.resize(n * kSHA256HashLength);
56 base::StringPiece previous; 57 base::StringPiece previous;
57 58
58 scoped_ptr<char[]> buf(new char[kSHA256HashLength + info.size() + 1]); 59 std::unique_ptr<char[]> buf(new char[kSHA256HashLength + info.size() + 1]);
59 uint8_t digest[kSHA256HashLength]; 60 uint8_t digest[kSHA256HashLength];
60 61
61 HMAC hmac(HMAC::SHA256); 62 HMAC hmac(HMAC::SHA256);
62 result = hmac.Init(prk, sizeof(prk)); 63 result = hmac.Init(prk, sizeof(prk));
63 DCHECK(result); 64 DCHECK(result);
64 65
65 for (size_t i = 0; i < n; i++) { 66 for (size_t i = 0; i < n; i++) {
66 memcpy(buf.get(), previous.data(), previous.size()); 67 memcpy(buf.get(), previous.data(), previous.size());
67 size_t j = previous.size(); 68 size_t j = previous.size();
68 memcpy(buf.get() + j, info.data(), info.size()); 69 memcpy(buf.get() + j, info.data(), info.size());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 if (subkey_secret_bytes_to_generate) { 102 if (subkey_secret_bytes_to_generate) {
102 subkey_secret_ = base::StringPiece(reinterpret_cast<char*>(&output_[j]), 103 subkey_secret_ = base::StringPiece(reinterpret_cast<char*>(&output_[j]),
103 subkey_secret_bytes_to_generate); 104 subkey_secret_bytes_to_generate);
104 } 105 }
105 } 106 }
106 107
107 HKDF::~HKDF() { 108 HKDF::~HKDF() {
108 } 109 }
109 110
110 } // namespace crypto 111 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/encryptor_unittest.cc ('k') | crypto/hmac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698