68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
#include "hash/hmac.hpp"
|
|
#include "types.hpp"
|
|
#include "debug.hpp"
|
|
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
using util::hash::HMAC;
|
|
|
|
|
|
static const struct {
|
|
std::vector<uint8_t> key;
|
|
std::vector<uint8_t> dat;
|
|
HMAC::digest_t res;
|
|
} TESTS[] = {
|
|
// RFC 2104 test data, MD5
|
|
{
|
|
{ 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
|
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b },
|
|
{ 'H', 'i', ' ', 'T', 'h', 'e', 'r', 'e' },
|
|
{ { 0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c,
|
|
0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d } }
|
|
},
|
|
|
|
{
|
|
{ 'J', 'e', 'f', 'e' },
|
|
{ 'w', 'h', 'a', 't', ' ', 'd', 'o', ' ',
|
|
'y', 'a', ' ', 'w', 'a', 'n', 't', ' ',
|
|
'f', 'o', 'r', ' ', 'n', 'o', 't', 'h',
|
|
'i', 'n', 'g', '?' },
|
|
{ { 0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03,
|
|
0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38 } }
|
|
},
|
|
|
|
{
|
|
{ 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
|
|
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA },
|
|
{ 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
|
|
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
|
|
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
|
|
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
|
|
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
|
|
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
|
|
0xDD, 0xDD },
|
|
{ { 0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88,
|
|
0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6 } }
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
main (int, char**)
|
|
{
|
|
for (const auto &t: TESTS) {
|
|
util::hash::HMAC h (t.key.data (), t.key.size ());
|
|
h.update (t.dat.data (), t.dat.size ());
|
|
h.finish ();
|
|
|
|
if (h.digest () != t.res)
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|