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

Unified Diff: crypto/hmac.h

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 | « crypto/encryptor_win.cc ('k') | crypto/hmac_mac.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/hmac.h
===================================================================
--- crypto/hmac.h (revision 0)
+++ crypto/hmac.h (revision 0)
@@ -0,0 +1,60 @@
+// 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.
+
+// Utility class for calculating the HMAC for a given message. We currently
+// only support SHA1 for the hash algorithm, but this can be extended easily.
+
+#ifndef CRYPTO_HMAC_H_
+#define CRYPTO_HMAC_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace crypto {
+
+// Simplify the interface and reduce includes by abstracting out the internals.
+struct HMACPlatformData;
+
+class HMAC {
+ public:
+ // The set of supported hash functions. Extend as required.
+ enum HashAlgorithm {
+ SHA1,
+ SHA256,
+ };
+
+ explicit HMAC(HashAlgorithm hash_alg);
+ ~HMAC();
+
+ // Initializes this instance using |key| of the length |key_length|. Call Init
+ // only once. It returns false on the second or later calls.
+ bool Init(const unsigned char* key, int key_length);
+
+ // Initializes this instance using |key|. Call Init only once. It returns
+ // false on the second or later calls.
+ bool Init(const std::string& key) {
+ return Init(reinterpret_cast<const unsigned char*>(key.data()),
+ static_cast<int>(key.size()));
+ }
+
+ // Calculates the HMAC for the message in |data| using the algorithm supplied
+ // to the constructor and the key supplied to the Init method. The HMAC is
+ // returned in |digest|, which has |digest_length| bytes of storage available.
+ bool Sign(const std::string& data, unsigned char* digest, int digest_length);
+
+ // TODO(albertb): Add a Verify method.
+
+ private:
+ HashAlgorithm hash_alg_;
+ scoped_ptr<HMACPlatformData> plat_;
+
+ DISALLOW_COPY_AND_ASSIGN(HMAC);
+};
+
+} // namespace crypto
+
+#endif // CRYPTO_HMAC_H_
Property changes on: crypto\hmac.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « crypto/encryptor_win.cc ('k') | crypto/hmac_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698