OLD | NEW |
---|---|
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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "crypto/hmac.h" | 8 #include "crypto/hmac.h" |
9 | 9 |
10 namespace crypto { | 10 namespace crypto { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 | 65 |
66 result = hmac.Sign(base::StringPiece(buf.get(), j), digest, sizeof(digest)); | 66 result = hmac.Sign(base::StringPiece(buf.get(), j), digest, sizeof(digest)); |
67 DCHECK(result); | 67 DCHECK(result); |
68 | 68 |
69 memcpy(&output_[i*sizeof(digest)], digest, sizeof(digest)); | 69 memcpy(&output_[i*sizeof(digest)], digest, sizeof(digest)); |
70 previous = base::StringPiece(reinterpret_cast<char*>(digest), | 70 previous = base::StringPiece(reinterpret_cast<char*>(digest), |
71 sizeof(digest)); | 71 sizeof(digest)); |
72 } | 72 } |
73 | 73 |
74 size_t j = 0; | 74 size_t j = 0; |
75 client_write_key_ = base::StringPiece(reinterpret_cast<char*>(&output_[j]), | 75 // On Windows, when output's size is zero, dereference of 0'th element results |
wtc
2013/03/14 00:38:08
output's => the size of output_
because "output_'
ramant (doing other things)
2013/03/14 03:05:15
Deleted this comment
ramant (doing other things)
2013/03/14 03:26:20
Added the comment.
| |
76 key_bytes_to_generate); | 76 // in a crash. C++11 solves this problem by passing std::vector's data. |
wtc
2013/03/14 00:38:08
This should read:
C++11 solves this problem by a
ramant (doing other things)
2013/03/14 03:05:15
Changed the code to use output_.data() + j. Thanks
ramant (doing other things)
2013/03/14 03:26:20
Added the comment. output_.data() + j is not suppo
| |
77 j += key_bytes_to_generate; | 77 if (key_bytes_to_generate > 0) { |
78 server_write_key_ = base::StringPiece(reinterpret_cast<char*>(&output_[j]), | 78 client_write_key_ = base::StringPiece(reinterpret_cast<char*>(&output_[j]), |
79 key_bytes_to_generate); | 79 key_bytes_to_generate); |
80 j += key_bytes_to_generate; | 80 j += key_bytes_to_generate; |
81 client_write_iv_ = base::StringPiece(reinterpret_cast<char*>(&output_[j]), | 81 server_write_key_ = base::StringPiece(reinterpret_cast<char*>(&output_[j]), |
82 iv_bytes_to_generate); | 82 key_bytes_to_generate); |
83 j += iv_bytes_to_generate; | 83 j += key_bytes_to_generate; |
84 server_write_iv_ = base::StringPiece(reinterpret_cast<char*>(&output_[j]), | 84 } |
85 iv_bytes_to_generate); | 85 |
86 if (iv_bytes_to_generate > 0) { | |
87 client_write_iv_ = base::StringPiece(reinterpret_cast<char*>(&output_[j]), | |
88 iv_bytes_to_generate); | |
89 j += iv_bytes_to_generate; | |
90 server_write_iv_ = base::StringPiece(reinterpret_cast<char*>(&output_[j]), | |
91 iv_bytes_to_generate); | |
92 } | |
86 } | 93 } |
87 | 94 |
88 HKDF::~HKDF() { | 95 HKDF::~HKDF() { |
89 } | 96 } |
90 | 97 |
91 } // namespace crypto | 98 } // namespace crypto |
OLD | NEW |