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> | 7 #include <openssl/hmac.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 plat_->key.assign(plat_->key.size(), 0); | 47 plat_->key.assign(plat_->key.size(), 0); |
48 STLClearObject(&plat_->key); | 48 STLClearObject(&plat_->key); |
49 } | 49 } |
50 | 50 |
51 bool HMAC::Sign(const base::StringPiece& data, | 51 bool HMAC::Sign(const base::StringPiece& data, |
52 unsigned char* digest, | 52 unsigned char* digest, |
53 size_t digest_length) const { | 53 size_t digest_length) const { |
54 DCHECK(!plat_->key.empty()); // Init must be called before Sign. | 54 DCHECK(!plat_->key.empty()); // Init must be called before Sign. |
55 | 55 |
56 ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> result(digest, digest_length); | 56 ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> result(digest, digest_length); |
57 return ::HMAC(hash_alg_ == SHA1 ? EVP_sha1() : EVP_sha256(), | 57 return ::HMAC(hash_alg_ == SHA1 ? EVP_sha1() : EVP_sha256(), |
Ryan Sleevi
2014/10/01 20:34:03
Can also go the cheap way that's more idiomatic fo
davidben
2014/10/02 00:21:36
Done.
| |
58 &plat_->key[0], plat_->key.size(), | 58 &plat_->key[0], plat_->key.size(), |
59 reinterpret_cast<const unsigned char*>(data.data()), | 59 reinterpret_cast<const unsigned char*>(data.data()), |
60 data.size(), | 60 data.size(), |
61 result.safe_buffer(), NULL); | 61 result.safe_buffer(), NULL) != NULL; |
62 } | 62 } |
63 | 63 |
64 } // namespace crypto | 64 } // namespace crypto |
OLD | NEW |