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

Unified Diff: base/hmac_mac.cc

Issue 218: HMAC-SHA1 implementation for Mac based on CommonCrypto (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 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.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_mac.cc
===================================================================
--- base/hmac_mac.cc (revision 0)
+++ base/hmac_mac.cc (revision 0)
@@ -0,0 +1,52 @@
+// Copyright (c) 2008 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 <CommonCrypto/CommonHMAC.h>
+
+#include "base/logging.h"
+
+namespace base {
+
+HMAC::HMAC(HashAlgorithm hash_alg, const unsigned char* key, int key_length)
+ : hash_alg_(hash_alg),
+ key_(reinterpret_cast<const char*>(key), key_length) {
+}
+
+HMAC::~HMAC() {
+ // Zero out key copy.
+ key_.assign(key_.length(), std::string::value_type());
+ key_.clear();
+ key_.reserve(0);
+}
+
+bool HMAC::Sign(const std::string& data,
+ unsigned char* digest,
+ int digest_length) {
+ CCHmacAlgorithm algorithm;
+ int algorithm_digest_length;
+ switch (hash_alg_) {
+ case SHA1:
+ algorithm = kCCHmacAlgSHA1;
+ algorithm_digest_length = CC_SHA1_DIGEST_LENGTH;
+ break;
+ default:
+ NOTREACHED();
+ return false;
+ }
+
+ if (digest_length < algorithm_digest_length) {
+ DCHECK(false);
+ return false;
+ }
+
+ CCHmac(algorithm,
+ key_.data(), key_.length(), data.data(), data.length(),
+ digest);
+
+ return true;
+}
+
+} // namespace base
Property changes on: base/hmac_mac.cc
___________________________________________________________________
Name: svn:eol-style
+ LF
« no previous file with comments | « base/hmac.cc ('k') | base/hmac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698