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.
7 #include <CommonCrypto/CommonHMAC.h>
9 #include "base/logging.h"
13 struct HMACPlatformData
{
17 HMAC::HMAC(HashAlgorithm hash_alg
, const unsigned char* key
, int key_length
)
18 : hash_alg_(hash_alg
), plat_(new HMACPlatformData()) {
19 plat_
->key_
.assign(reinterpret_cast<const char*>(key
), key_length
);
24 plat_
->key_
.assign(plat_
->key_
.length(), std::string::value_type());
26 plat_
->key_
.reserve(0);
31 bool HMAC::Sign(const std::string
& data
,
32 unsigned char* digest
,
34 CCHmacAlgorithm algorithm
;
35 int algorithm_digest_length
;
38 algorithm
= kCCHmacAlgSHA1
;
39 algorithm_digest_length
= CC_SHA1_DIGEST_LENGTH
;
46 if (digest_length
< algorithm_digest_length
) {
52 plat_
->key_
.data(), plat_
->key_
.length(), data
.data(), data
.length(),