Skip to content

Commit

Permalink
PBKDF2 with HMAC-MD5 (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberjunk committed Mar 21, 2024
1 parent 7ee5b51 commit 9decbfe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions include/CppCore.Test/Crypto/PBKDF2.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ namespace CppCore { namespace Test { namespace Crypto
class PBKDF2
{
public:
INLINE static bool md5test1()
{
uint8_t digest[16];
uint8_t expect[16] = {
0x3b,0x3e,0x22,0xac,0x59,0x98,0x7a,0x43,
0x9e,0x40,0x19,0xf9,0xda,0x8f,0x45,0x20
};

PBKDF2MD5 pbkdf2;
pbkdf2.create("Test", 4, "Hello", 5, 1000, digest, sizeof(digest));

if (::memcmp(digest, expect, 16) != 0)
return false;

return true;
}

INLINE static bool sha256test1()
{
uint8_t digest[32];
Expand Down Expand Up @@ -88,6 +105,7 @@ namespace CppCore { namespace Test { namespace VS { namespace Crypto {
TEST_CLASS(PBKDF2)
{
public:
TEST_METHOD(MD5TEST1) { Assert::AreEqual(true, CppCore::Test::Crypto::PBKDF2::md5test1()); }
TEST_METHOD(SHA256TEST1) { Assert::AreEqual(true, CppCore::Test::Crypto::PBKDF2::sha256test1()); }
TEST_METHOD(SHA512TEST1) { Assert::AreEqual(true, CppCore::Test::Crypto::PBKDF2::sha512test1()); }
TEST_METHOD(SHA512TEST2) { Assert::AreEqual(true, CppCore::Test::Crypto::PBKDF2::sha512test2()); }
Expand Down
5 changes: 5 additions & 0 deletions include/CppCore/Crypto/PBKDF2.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ namespace CppCore
}
};

/// <summary>
/// PBKDF2 with HMAC-MD5
/// </summary>
using PBKDF2MD5 = PBKDF2<HMACMD5>;

/// <summary>
/// PBKDF2 with HMAC-SHA256
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/CppCore.Test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ int main()
std::cout << "-------------------------------" << std::endl;
std::cout << " CppCore::Crypto::PBKDF2" << std::endl;
std::cout << "-------------------------------" << std::endl;
TEST(CppCore::Test::Crypto::PBKDF2::md5test1, "md5test1: ", std::endl);
TEST(CppCore::Test::Crypto::PBKDF2::sha256test1, "sha256test1: ", std::endl);
TEST(CppCore::Test::Crypto::PBKDF2::sha512test1, "sha512test1: ", std::endl);
TEST(CppCore::Test::Crypto::PBKDF2::sha512test2, "sha512test2: ", std::endl);
Expand Down

0 comments on commit 9decbfe

Please sign in to comment.