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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/hmac.cc ('k') | base/hmac_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/hmac.h"
6
7 #include <CommonCrypto/CommonHMAC.h>
8
9 #include "base/logging.h"
10
11 namespace base {
12
13 HMAC::HMAC(HashAlgorithm hash_alg, const unsigned char* key, int key_length)
14 : hash_alg_(hash_alg),
15 key_(reinterpret_cast<const char*>(key), key_length) {
16 }
17
18 HMAC::~HMAC() {
19 // Zero out key copy.
20 key_.assign(key_.length(), std::string::value_type());
21 key_.clear();
22 key_.reserve(0);
23 }
24
25 bool HMAC::Sign(const std::string& data,
26 unsigned char* digest,
27 int digest_length) {
28 CCHmacAlgorithm algorithm;
29 int algorithm_digest_length;
30 switch (hash_alg_) {
31 case SHA1:
32 algorithm = kCCHmacAlgSHA1;
33 algorithm_digest_length = CC_SHA1_DIGEST_LENGTH;
34 break;
35 default:
36 NOTREACHED();
37 return false;
38 }
39
40 if (digest_length < algorithm_digest_length) {
41 DCHECK(false);
42 return false;
43 }
44
45 CCHmac(algorithm,
46 key_.data(), key_.length(), data.data(), data.length(),
47 digest);
48
49 return true;
50 }
51
52 } // namespace base
OLDNEW
« 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