-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
/// @brief Constructor for specific hash algorithm
///
/// @param hash_algorithm The hash algorithm
- explicit HashImpl(const HashAlgorithm hash_algorithm) {
+ explicit HashImpl(const HashAlgorithm hash_algorithm)
+ : hash_algorithm_(hash_algorithm), hash_() {
Botan::HashFunction* hash;
try {
hash = Botan::get_hash(btn::getHashAlgorithmName(hash_algorithm));
/// @brief Destructor
~HashImpl() { }
+ /// @brief Returns the HashAlgorithm of the object
+ HashAlgorithm getHashAlgorithm() const {
+ return (hash_algorithm_);
+ }
+
/// @brief Returns the output size of the digest
///
/// @return output size of the digest
}
private:
- /// \brief The protected pointer to the Botan HashFunction object
+ /// @brief The hash algorithm
+ HashAlgorithm hash_algorithm_;
+
+ /// @brief The protected pointer to the Botan HashFunction object
boost::scoped_ptr<Botan::HashFunction> hash_;
};
delete impl_;
}
+HashAlgorithm
+Hash:getHashAlgorithm() const {
+ return (impl_->getHashAlgorithm());
+}
+
size_t
Hash::getOutputLength() const {
return (impl_->getOutputLength());
-// Copyright (C) 2011, 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
/// @param secret_len The length of the secret
/// @param hash_algorithm The hash algorithm
explicit HMACImpl(const void* secret, size_t secret_len,
- const HashAlgorithm hash_algorithm) {
+ const HashAlgorithm hash_algorithm)
+ : hash_algorithm_(hash_algorithm), hmac_() {
Botan::HashFunction* hash;
try {
hash = Botan::get_hash(btn::getHashAlgorithmName(hash_algorithm));
~HMACImpl() {
}
+ /// @brief Returns the HashAlgorithm of the object
+ HashAlgorithm getHashAlgorithm() const {
+ return (hash_algorithm_);
+ }
+
/// @brief Returns the output size of the digest
///
/// @return output size of the digest
}
private:
- /// \brief The protected pointer to the Botan HMAC object
+ /// @brief The hash algorithm
+ HashAlgorithm hash_algorithm_;
+
+ /// @brief The protected pointer to the Botan HMAC object
boost::scoped_ptr<Botan::HMAC> hmac_;
};
delete impl_;
}
+HashAlgorithm
+HMAC:getHashAlgorithm() const {
+ return (impl_->getHashAlgorithm());
+}
+
size_t
HMAC::getOutputLength() const {
return (impl_->getOutputLength());
/// \brief Destructor
~Hash();
+ /// \brief Returns the HashAlgorithm of the object
+ HashAlgorithm getHashAlgorithm() const;
+
/// \brief Returns the output size of the digest
///
/// \return output size of the digest
/// \brief Destructor
~HMAC();
+ /// \brief Returns the HashAlgorithm of the object
+ HashAlgorithm getHashAlgorithm() const;
+
/// \brief Returns the output size of the digest
///
/// \return output size of the digest
}
found = true;
if (line[strlen(line) - 1] == '\n') {
- line[strlen(line) -1] = 0;
+ line[strlen(line) - 1] = 0;
}
break;
}
-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
/// @brief Constructor for specific hash algorithm
///
/// @param hash_algorithm The hash algorithm
- explicit HashImpl(const HashAlgorithm hash_algorithm) {
+ explicit HashImpl(const HashAlgorithm hash_algorithm)
+ : hash_algorithm_(hash_algorithm), md_() {
const EVP_MD* algo = ossl::getHashAlgorithm(hash_algorithm);
if (algo == 0) {
isc_throw(isc::cryptolink::UnsupportedAlgorithm,
}
}
+ /// @brief Returns the HashAlgorithm of the object
+ HashAlgorithm getHashAlgorithm() const {
+ return (hash_algorithm_);
+ }
+
/// @brief Returns the output size of the digest
///
/// @return output size of the digest
}
private:
+ /// @brief The hash algorithm
+ HashAlgorithm hash_algorithm_;
+
/// @brief The protected pointer to the OpenSSL EVP_MD_CTX structure
boost::scoped_ptr<EVP_MD_CTX> md_;
};
delete impl_;
}
+HashAlgorithm
+Hash::getHashAlgorithm() const {
+ return (impl_->getHashAlgorithm());
+}
+
size_t
Hash::getOutputLength() const {
return (impl_->getOutputLength());
-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
/// @param secret_len The length of the secret
/// @param hash_algorithm The hash algorithm
explicit HMACImpl(const void* secret, size_t secret_len,
- const HashAlgorithm hash_algorithm) {
+ const HashAlgorithm hash_algorithm)
+ : hash_algorithm_(hash_algorithm), md_() {
const EVP_MD* algo = ossl::getHashAlgorithm(hash_algorithm);
if (algo == 0) {
isc_throw(UnsupportedAlgorithm,
}
}
+ /// @brief Returns the HashAlgorithm of the object
+ HashAlgorithm getHashAlgorithm() const {
+ return (hash_algorithm_);
+ }
+
/// @brief Returns the output size of the digest
///
/// @return output size of the digest
}
private:
+ /// @brief The hash algorithm
+ HashAlgorithm hash_algorithm_;
/// @brief The protected pointer to the OpenSSL HMAC_CTX structure
boost::scoped_ptr<HMAC_CTX> md_;
delete impl_;
}
+HashAlgorithm
+HMAC::getHashAlgorithm() const {
+ return (impl_->getHashAlgorithm());
+}
+
size_t
HMAC::getOutputLength() const {
return (impl_->getOutputLength());
-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
SHA512, hash_expected4, 64);
}
+namespace {
+ /// @brief Get the hash algorithm
+ /// @param alg Hash algorithm enum
+ /// @return Hash algorithm enum
+ HashAlgorithm
+ digestHashAlgorithm(HashAlgorithm alg) {
+ boost::shared_ptr<Hash> hash_digest(
+ CryptoLink::getCryptoLink().createHash(alg),
+ deleteHash);
+ return (hash_digest->getHashAlgorithm());
+ }
+}
+
+TEST(HashTest, HashAlgorithm) {
+ EXPECT_EQ(MD5, digestHashAlgorithm(MD5));
+ EXPECT_EQ(SHA1, digestHashAlgorithm(SHA1));
+ EXPECT_EQ(SHA256, digestHashAlgorithm(SHA256));
+ EXPECT_EQ(SHA224, digestHashAlgorithm(SHA224));
+ EXPECT_EQ(SHA384, digestHashAlgorithm(SHA384));
+ EXPECT_EQ(SHA512, digestHashAlgorithm(SHA512));
+}
+
namespace {
/// @brief Compute the vector digest length
/// @param alg Hash algorithm enum
-// Copyright (C) 2011, 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
hmac_expected5, 16);
}
+namespace {
+ /// @brief Get the hash algorithm
+ /// @param alg Hash algorithm enum
+ /// @return Hash algorithm enum
+ HashAlgorithm
+ signHashAlgorithm(HashAlgorithm alg) {
+ boost::shared_ptr<HMAC> hmac_sign(
+ CryptoLink::getCryptoLink().createHMAC("asdf", 4, alg),
+ deleteHMAC);
+ return (hmac_sign->getHashAlgorithm());
+ }
+}
+
+TEST(HMACTest, HashAlgorithm) {
+ EXPECT_EQ(MD5, signHashAlgorithm(MD5));
+ EXPECT_EQ(SHA1, signHashAlgorithm(SHA1));
+ EXPECT_EQ(SHA256, signHashAlgorithm(SHA256));
+ EXPECT_EQ(SHA224, signHashAlgorithm(SHA224));
+ EXPECT_EQ(SHA384, signHashAlgorithm(SHA384));
+ EXPECT_EQ(SHA512, signHashAlgorithm(SHA512));
+}
+
namespace {
/// @brief Compute the vector signature length
/// @param alg Hash algorithm enum