| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <openssl/hmac.h> | |
| 8 | |
| 9 #include <algorithm> | 7 #include <algorithm> |
| 10 #include <vector> | 8 #include <vector> |
| 11 | 9 |
| 12 #include "base/logging.h" | 10 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 15 #include "crypto/openssl_util.h" | 13 #include "crypto/openssl_util.h" |
| 14 #include "third_party/boringssl/src/include/openssl/hmac.h" |
| 16 | 15 |
| 17 namespace crypto { | 16 namespace crypto { |
| 18 | 17 |
| 19 struct HMACPlatformData { | 18 struct HMACPlatformData { |
| 20 std::vector<unsigned char> key; | 19 std::vector<unsigned char> key; |
| 21 }; | 20 }; |
| 22 | 21 |
| 23 HMAC::HMAC(HashAlgorithm hash_alg) : hash_alg_(hash_alg) { | 22 HMAC::HMAC(HashAlgorithm hash_alg) : hash_alg_(hash_alg) { |
| 24 // Only SHA-1 and SHA-256 hash algorithms are supported now. | 23 // Only SHA-1 and SHA-256 hash algorithms are supported now. |
| 25 DCHECK(hash_alg_ == SHA1 || hash_alg_ == SHA256); | 24 DCHECK(hash_alg_ == SHA1 || hash_alg_ == SHA256); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 DCHECK(plat_); // Init must be called before Sign. | 46 DCHECK(plat_); // Init must be called before Sign. |
| 48 | 47 |
| 49 ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> result(digest, digest_length); | 48 ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> result(digest, digest_length); |
| 50 return !!::HMAC(hash_alg_ == SHA1 ? EVP_sha1() : EVP_sha256(), | 49 return !!::HMAC(hash_alg_ == SHA1 ? EVP_sha1() : EVP_sha256(), |
| 51 vector_as_array(&plat_->key), plat_->key.size(), | 50 vector_as_array(&plat_->key), plat_->key.size(), |
| 52 reinterpret_cast<const unsigned char*>(data.data()), | 51 reinterpret_cast<const unsigned char*>(data.data()), |
| 53 data.size(), result.safe_buffer(), NULL); | 52 data.size(), result.safe_buffer(), NULL); |
| 54 } | 53 } |
| 55 | 54 |
| 56 } // namespace crypto | 55 } // namespace crypto |
| OLD | NEW |