2015-12-17 09:36:09 +00:00
|
|
|
/*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 K. Isom <coder@kyleisom.net>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __EMSHA_TEST_UTILS_HH
|
|
|
|
#define __EMSHA_TEST_UTILS_HH
|
|
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
|
2023-10-18 06:43:18 +00:00
|
|
|
#include <emsha/emsha.h>
|
|
|
|
#include <emsha/sha256.h>
|
|
|
|
#include <emsha/hmac.h>
|
2015-12-17 09:36:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
// How many times should a test result be checked? The goal is to
|
|
|
|
// ensure that the 'result' method is idempotent. My science teachers
|
|
|
|
// always said 5 data points was the minimum you needed, so there you
|
|
|
|
// go. Thanks, Mr. Franklin.
|
|
|
|
constexpr uint32_t RESULT_ITERATIONS = 5;
|
|
|
|
|
|
|
|
|
|
|
|
// Test data structures.
|
|
|
|
|
2023-10-18 06:43:18 +00:00
|
|
|
struct hashTest {
|
2015-12-17 09:36:09 +00:00
|
|
|
std::string output;
|
|
|
|
std::string input;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-10-18 06:43:18 +00:00
|
|
|
struct hmacTest {
|
2015-12-17 09:36:09 +00:00
|
|
|
std::uint8_t key[256];
|
|
|
|
std::uint32_t keylen;
|
|
|
|
std::string input;
|
|
|
|
std::string output;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// General-purpose debuggery.
|
2023-10-18 06:43:18 +00:00
|
|
|
void DumpHexString(std::string&, std::uint8_t *, std::uint32_t);
|
2015-12-17 10:00:45 +00:00
|
|
|
void dump_pair(std::uint8_t *, std::uint8_t *);
|
2015-12-17 09:36:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
// SHA-256 testing functions.
|
2023-10-18 10:39:27 +00:00
|
|
|
emsha::EMSHAResult runHashTest(const struct hashTest& test, const std::string& label);
|
2023-10-18 06:43:18 +00:00
|
|
|
int runHashTests(const struct hashTest *tests, const std::size_t nTests,
|
|
|
|
const std::string& label);
|
2015-12-17 09:36:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
// HMAC-SHA-256 testery.
|
2023-10-18 10:39:27 +00:00
|
|
|
emsha::EMSHAResult runHMACTest(struct hmacTest& test, const std::string& label);
|
2023-10-18 06:43:18 +00:00
|
|
|
int runHMACTests(const struct hmacTest *tests, std::size_t nTests,
|
|
|
|
const std::string& label);
|
2015-12-17 09:36:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef EMSHA_NO_HEXSTRING
|
|
|
|
namespace emsha {
|
|
|
|
void hexstring(uint8_t *dest, uint8_t *src, uint32_t srclen);
|
|
|
|
}
|
|
|
|
#endif // EMSHA_NO_HEXSTRING
|
|
|
|
|
|
|
|
|
|
|
|
#endif // __EMSHA_TEST_UTILS_HH
|