diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-02 21:01:35 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-02 21:01:35 +0000 |
commit | db163f8b20b0a6c512e1ad21bab9af15a8c9c218 (patch) | |
tree | d996613019feaafbddcb3652afd665d18cb34377 /base/hmac_mac.cc | |
parent | dd6335b14a4bb6c466f782b54783c73938d4e4ca (diff) | |
download | chromium_src-db163f8b20b0a6c512e1ad21bab9af15a8c9c218.zip chromium_src-db163f8b20b0a6c512e1ad21bab9af15a8c9c218.tar.gz chromium_src-db163f8b20b0a6c512e1ad21bab9af15a8c9c218.tar.bz2 |
Implement HMAC-SHA-256.
R=albertb
BUG=none
TEST=added new HMAC unit tests
Review URL: http://codereview.chromium.org/1513012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43522 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/hmac_mac.cc')
-rw-r--r-- | base/hmac_mac.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/base/hmac_mac.cc b/base/hmac_mac.cc index bbc9330..97dcbf5 100644 --- a/base/hmac_mac.cc +++ b/base/hmac_mac.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -16,8 +16,8 @@ struct HMACPlatformData { HMAC::HMAC(HashAlgorithm hash_alg) : hash_alg_(hash_alg), plat_(new HMACPlatformData()) { - // Only SHA-1 digest is supported now. - DCHECK(hash_alg_ == SHA1); + // 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) { @@ -49,6 +49,10 @@ bool HMAC::Sign(const std::string& data, algorithm = kCCHmacAlgSHA1; algorithm_digest_length = CC_SHA1_DIGEST_LENGTH; break; + case SHA256: + algorithm = kCCHmacAlgSHA256; + algorithm_digest_length = CC_SHA256_DIGEST_LENGTH; + break; default: NOTREACHED(); return false; |