| 1 |
// Copyright (c) 2018, Google Inc. |
| 2 |
// SPDX-License-Identifier: ISC |
| 3 |
|
| 4 |
#ifndef OPENSSL_HEADER_CRYPTO_TEST_WYCHEPROOF_UTIL_H |
| 5 |
#define OPENSSL_HEADER_CRYPTO_TEST_WYCHEPROOF_UTIL_H |
| 6 |
|
| 7 |
#include <openssl/base.h> |
| 8 |
|
| 9 |
#include <string> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
|
| 13 |
// This header contains convenience functions for Wycheproof tests. |
| 14 |
|
| 15 |
static constexpr const char kWycheproofV1Path[] = |
| 16 |
"third_party/vectors/converted/wycheproof/testvectors_v1/"; |
| 17 |
|
| 18 |
class FileTest; |
| 19 |
|
| 20 |
enum class WycheproofRawResult { |
| 21 |
kValid, |
| 22 |
kInvalid, |
| 23 |
kAcceptable, |
| 24 |
}; |
| 25 |
|
| 26 |
struct WycheproofResult { |
| 27 |
WycheproofRawResult raw_result; |
| 28 |
std::vector<std::string> flags; |
| 29 |
|
| 30 |
// IsValid returns true if the Wycheproof test should be considered valid. A |
| 31 |
// test result of "acceptable" is treated as valid if all flags are included |
| 32 |
// in |acceptable_flags| and invalid otherwise. |
| 33 |
bool IsValid(const std::vector<std::string> &acceptable_flags = {}) const; |
| 34 |
|
| 35 |
// StringifyFlags returns a printable string of all flags. |
| 36 |
std::string StringifyFlags(); |
| 37 |
|
| 38 |
// HasFlag returns true if |flag| is present in the flags vector. |
| 39 |
bool HasFlag(const std::string &flag) const; |
| 40 |
}; |
| 41 |
|
| 42 |
// GetWycheproofResult sets |*out| to the parsed "result" and "flags" keys of |t|. |
| 43 |
bool GetWycheproofResult(FileTest *t, WycheproofResult *out); |
| 44 |
|
| 45 |
// GetWycheproofDigest returns a digest function using the Wycheproof name, or |
| 46 |
// nullptr on error. |
| 47 |
const EVP_MD *GetWycheproofDigest(FileTest *t, const char *key, |
| 48 |
bool instruction); |
| 49 |
|
| 50 |
// GetWycheproofCurve returns a curve using the Wycheproof name, or nullptr on |
| 51 |
// error. |
| 52 |
const EC_GROUP *GetWycheproofCurve(FileTest *t, const char *key, |
| 53 |
bool instruction); |
| 54 |
|
| 55 |
// GetWycheproofBIGNUM returns a BIGNUM in the Wycheproof format, or nullptr on |
| 56 |
// error. |
| 57 |
bssl::UniquePtr<BIGNUM> GetWycheproofBIGNUM(FileTest *t, const char *key, |
| 58 |
bool instruction); |
| 59 |
|
| 60 |
|
| 61 |
#endif // OPENSSL_HEADER_CRYPTO_TEST_WYCHEPROOF_UTIL_H |