| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/hmac.h" | 5 #include "crypto/hmac.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> |
| 10 | 11 |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "crypto/secure_util.h" | 13 #include "crypto/secure_util.h" |
| 13 #include "crypto/symmetric_key.h" | 14 #include "crypto/symmetric_key.h" |
| 14 | 15 |
| 15 namespace crypto { | 16 namespace crypto { |
| 16 | 17 |
| 17 bool HMAC::Init(SymmetricKey* key) { | 18 bool HMAC::Init(SymmetricKey* key) { |
| 18 std::string raw_key; | 19 std::string raw_key; |
| 19 bool result = key->GetRawKey(&raw_key) && Init(raw_key); | 20 bool result = key->GetRawKey(&raw_key) && Init(raw_key); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 40 if (digest.size() != DigestLength()) | 41 if (digest.size() != DigestLength()) |
| 41 return false; | 42 return false; |
| 42 return VerifyTruncated(data, digest); | 43 return VerifyTruncated(data, digest); |
| 43 } | 44 } |
| 44 | 45 |
| 45 bool HMAC::VerifyTruncated(const base::StringPiece& data, | 46 bool HMAC::VerifyTruncated(const base::StringPiece& data, |
| 46 const base::StringPiece& digest) const { | 47 const base::StringPiece& digest) const { |
| 47 if (digest.empty()) | 48 if (digest.empty()) |
| 48 return false; | 49 return false; |
| 49 size_t digest_length = DigestLength(); | 50 size_t digest_length = DigestLength(); |
| 50 scoped_ptr<unsigned char[]> computed_digest( | 51 std::unique_ptr<unsigned char[]> computed_digest( |
| 51 new unsigned char[digest_length]); | 52 new unsigned char[digest_length]); |
| 52 if (!Sign(data, computed_digest.get(), digest_length)) | 53 if (!Sign(data, computed_digest.get(), digest_length)) |
| 53 return false; | 54 return false; |
| 54 | 55 |
| 55 return SecureMemEqual(digest.data(), computed_digest.get(), | 56 return SecureMemEqual(digest.data(), computed_digest.get(), |
| 56 std::min(digest.size(), digest_length)); | 57 std::min(digest.size(), digest_length)); |
| 57 } | 58 } |
| 58 | 59 |
| 59 } // namespace crypto | 60 } // namespace crypto |
| OLD | NEW |