#include "crypto/openssl_error.h"
#include "log/log.h"
+#include <cassert>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/kdf.h>
const CryptoBuffer &info,
size_t derivedKeySize)
{
+ assert(!secret.empty() || !salt.empty() || !info.empty());
CryptoBuffer derivedKey(derivedKeySize);
if (derivedKeySize == 0)
#include "crypto/openssl_error.h"
#include "log/log.h"
+#include <cassert>
#include <openssl/hmac.h>
namespace Crypto {
CryptoBuffer HmacSha256(const CryptoBuffer &key, const CryptoBuffer &data)
{
+ assert(!key.empty() || !data.empty());
CryptoBuffer digest(EVP_MAX_MD_SIZE);
unsigned int digestLen;
EXPECT_TRUE(derivedKey.empty());
}
-TEST(HkdfSha256Test, empty_input)
-{
- const CryptoBuffer secret;
- const CryptoBuffer salt;
- const CryptoBuffer info;
- size_t derivedKeySize = 42;
-
- const CryptoBuffer expected = {0xeb, 0x70, 0xf0, 0x1d, 0xed, 0xe9, 0xaf, 0xaf, 0xa4, 0x49, 0xee,
- 0xe1, 0xb1, 0x28, 0x65, 0x04, 0xe1, 0xf6, 0x23, 0x88, 0xb3, 0xf7,
- 0xdd, 0x4f, 0x95, 0x66, 0x97, 0xb0, 0xe8, 0x28, 0xfe, 0x18, 0x1e,
- 0x59, 0xc2, 0xec, 0x0f, 0xe6, 0xe7, 0xe7, 0xac, 0x26};
-
- auto derivedKey = Crypto::HkdfSha256(secret, salt, info, derivedKeySize);
- EXPECT_EQ(derivedKey, expected);
-}
-
TEST(HkdfSha256Test, empty_secret)
{
const CryptoBuffer secret;
EXPECT_EQ(digest, expected);
}
-TEST(HmacSha256Test, EmptyKeyDataTestCase7)
-{
- const CryptoBuffer key;
- const CryptoBuffer data;
-
- const CryptoBuffer expected = {0xb6, 0x13, 0x67, 0x9a, 0x08, 0x14, 0xd9, 0xec, 0x77, 0x2f, 0x95,
- 0xd7, 0x78, 0xc3, 0x5f, 0xc5, 0xff, 0x16, 0x97, 0xc4, 0x93, 0x71,
- 0x56, 0x53, 0xc6, 0xc7, 0x12, 0x14, 0x42, 0x92, 0xc5, 0xad};
-
- auto digest = Crypto::HmacSha256(key, data);
- EXPECT_EQ(digest, expected);
-}