summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/hmac.h14
-rw-r--r--crypto/hmac_mac.cc6
2 files changed, 14 insertions, 6 deletions
diff --git a/crypto/hmac.h b/crypto/hmac.h
index 73d6dc3..e52d519 100644
--- a/crypto/hmac.h
+++ b/crypto/hmac.h
@@ -10,6 +10,7 @@
#pragma once
#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_piece.h"
#include "crypto/crypto_api.h"
@@ -38,11 +39,11 @@ class CRYPTO_API HMAC {
// Initializes this instance using |key| of the length |key_length|. Call Init
// only once. It returns false on the second or later calls.
// TODO(abarth): key_length should be a size_t.
- bool Init(const unsigned char* key, int key_length);
+ bool Init(const unsigned char* key, int key_length) WARN_UNUSED_RESULT;
// Initializes this instance using |key|. Call Init only once. It returns
// false on the second or later calls.
- bool Init(const base::StringPiece& key) {
+ bool Init(const base::StringPiece& key) WARN_UNUSED_RESULT {
return Init(reinterpret_cast<const unsigned char*>(key.data()),
static_cast<int>(key.size()));
}
@@ -52,7 +53,7 @@ class CRYPTO_API HMAC {
// returned in |digest|, which has |digest_length| bytes of storage available.
// TODO(abarth): digest_length should be a size_t.
bool Sign(const base::StringPiece& data, unsigned char* digest,
- int digest_length) const;
+ int digest_length) const WARN_UNUSED_RESULT;
// Verifies that the HMAC for the message in |data| equals the HMAC provided
// in |digest|, using the algorithm supplied to the constructor and the key
@@ -62,12 +63,13 @@ class CRYPTO_API HMAC {
// undermine the cryptographic integrity. |digest| must be exactly
// |DigestLength()| bytes long.
bool Verify(const base::StringPiece& data,
- const base::StringPiece& digest) const;
+ const base::StringPiece& digest) const WARN_UNUSED_RESULT;
// Verifies a truncated HMAC, behaving identical to Verify(), except
// that |digest| is allowed to be smaller than |DigestLength()|.
- bool VerifyTruncated(const base::StringPiece& data,
- const base::StringPiece& digest) const;
+ bool VerifyTruncated(
+ const base::StringPiece& data,
+ const base::StringPiece& digest) const WARN_UNUSED_RESULT;
private:
HashAlgorithm hash_alg_;
diff --git a/crypto/hmac_mac.cc b/crypto/hmac_mac.cc
index f9a00cd..36caa0d 100644
--- a/crypto/hmac_mac.cc
+++ b/crypto/hmac_mac.cc
@@ -42,6 +42,12 @@ HMAC::~HMAC() {
bool HMAC::Sign(const base::StringPiece& data,
unsigned char* digest,
int digest_length) const {
+ if (plat_->key_.empty()) {
+ // Init has not been called or has failed.
+ NOTREACHED();
+ return false;
+ }
+
CCHmacAlgorithm algorithm;
int algorithm_digest_length;
switch (hash_alg_) {