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

Unified Diff: base/hmac_openssl.cc

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes comments by eroman Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/hmac_nss.cc ('k') | base/hmac_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/hmac_openssl.cc
===================================================================
--- base/hmac_openssl.cc (revision 81350)
+++ base/hmac_openssl.cc (working copy)
@@ -1,57 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/hmac.h"
-
-#include <openssl/hmac.h>
-
-#include <algorithm>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/openssl_util.h"
-#include "base/stl_util-inl.h"
-
-namespace base {
-
-struct HMACPlatformData {
- std::vector<unsigned char> key;
-};
-
-HMAC::HMAC(HashAlgorithm hash_alg)
- : hash_alg_(hash_alg), plat_(new HMACPlatformData()) {
- // Only SHA-1 and SHA-256 hash algorithms are supported now.
- DCHECK(hash_alg_ == SHA1 || hash_alg_ == SHA256);
-}
-
-bool HMAC::Init(const unsigned char* key, int key_length) {
- // Init must not be called more than once on the same HMAC object.
- DCHECK(plat_->key.empty());
-
- plat_->key.assign(key, key + key_length);
- return true;
-}
-
-HMAC::~HMAC() {
- // Zero out key copy.
- plat_->key.assign(plat_->key.size(), 0);
- STLClearObject(&plat_->key);
-}
-
-bool HMAC::Sign(const std::string& data,
- unsigned char* digest,
- int digest_length) {
- DCHECK_GE(digest_length, 0);
- DCHECK(!plat_->key.empty()); // Init must be called before Sign.
-
- ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> result(digest, digest_length);
- return ::HMAC(hash_alg_ == SHA1 ? EVP_sha1() : EVP_sha256(),
- &plat_->key[0], plat_->key.size(),
- reinterpret_cast<const unsigned char*>(data.data()),
- data.size(),
- result.safe_buffer(), NULL);
-}
-
-} // namespace base
« no previous file with comments | « base/hmac_nss.cc ('k') | base/hmac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698