1 | // |
---|---|
2 | // HMACEngineTest.cpp |
3 | // |
4 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
5 | // and Contributors. |
6 | // |
7 | // SPDX-License-Identifier: BSL-1.0 |
8 | // |
9 | |
10 | |
11 | #include "HMACEngineTest.h" |
12 | #include "Poco/CppUnit/TestCaller.h" |
13 | #include "Poco/CppUnit/TestSuite.h" |
14 | #include "Poco/HMACEngine.h" |
15 | #include "Poco/MD5Engine.h" |
16 | |
17 | |
18 | using Poco::HMACEngine; |
19 | using Poco::MD5Engine; |
20 | using Poco::DigestEngine; |
21 | |
22 | |
23 | HMACEngineTest::HMACEngineTest(const std::string& rName): CppUnit::TestCase(rName) |
24 | { |
25 | } |
26 | |
27 | |
28 | HMACEngineTest::~HMACEngineTest() |
29 | { |
30 | } |
31 | |
32 | |
33 | void HMACEngineTest::testHMAC() |
34 | { |
35 | // test vectors from RFC 2104 |
36 | |
37 | std::string key(16, 0x0b); |
38 | std::string data("Hi There"); |
39 | HMACEngine<MD5Engine> hmac1(key); |
40 | hmac1.update(data); |
41 | std::string digest = DigestEngine::digestToHex(hmac1.digest()); |
42 | assertTrue (digest == "9294727a3638bb1c13f48ef8158bfc9d"); |
43 | |
44 | key = "Jefe"; |
45 | data = "what do ya want for nothing?"; |
46 | HMACEngine<MD5Engine> hmac2(key); |
47 | hmac2.update(data); |
48 | digest = DigestEngine::digestToHex(hmac2.digest()); |
49 | assertTrue (digest == "750c783e6ab0b503eaa86e310a5db738"); |
50 | |
51 | key = std::string(16, char(0xaa)); |
52 | data = std::string(50, char(0xdd)); |
53 | HMACEngine<MD5Engine> hmac3(key); |
54 | hmac3.update(data); |
55 | digest = DigestEngine::digestToHex(hmac3.digest()); |
56 | assertTrue (digest == "56be34521d144c88dbb8c733f0e8b3f6"); |
57 | } |
58 | |
59 | |
60 | void HMACEngineTest::setUp() |
61 | { |
62 | } |
63 | |
64 | |
65 | void HMACEngineTest::tearDown() |
66 | { |
67 | } |
68 | |
69 | |
70 | CppUnit::Test* HMACEngineTest::suite() |
71 | { |
72 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HMACEngineTest"); |
73 | |
74 | CppUnit_addTest(pSuite, HMACEngineTest, testHMAC); |
75 | |
76 | return pSuite; |
77 | } |
78 |