blob: 67e0ed3fe97f59e2095a90b490b332d74f290e81 [file] [log] [blame]
David Benjamin40d76f42018-04-26 17:35:53 -04001/* Copyright (c) 2018, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15#ifndef OPENSSL_HEADER_CRYPTO_TEST_WYCHEPROOF_UTIL_H
16#define OPENSSL_HEADER_CRYPTO_TEST_WYCHEPROOF_UTIL_H
17
18#include <openssl/base.h>
19
David Benjamin906bbef2019-12-14 02:04:44 -050020#include <string>
21#include <vector>
22
David Benjamin40d76f42018-04-26 17:35:53 -040023
24// This header contains convenience functions for Wycheproof tests.
25
26class FileTest;
27
David Benjamin906bbef2019-12-14 02:04:44 -050028enum class WycheproofRawResult {
David Benjamin40d76f42018-04-26 17:35:53 -040029 kValid,
30 kInvalid,
31 kAcceptable,
32};
33
David Benjamin906bbef2019-12-14 02:04:44 -050034struct WycheproofResult {
35 WycheproofRawResult raw_result;
36 std::vector<std::string> flags;
37
38 // IsValid returns true if the Wycheproof test should be considered valid. A
39 // test result of "acceptable" is treated as valid if all flags are included
40 // in |acceptable_flags| and invalid otherwise.
41 bool IsValid(const std::vector<std::string> &acceptable_flags = {}) const;
42};
43
44// GetWycheproofResult sets |*out| to the parsed "result" and "flags" keys of |t|.
David Benjamin40d76f42018-04-26 17:35:53 -040045bool GetWycheproofResult(FileTest *t, WycheproofResult *out);
46
47// GetWycheproofDigest returns a digest function using the Wycheproof name, or
48// nullptr on error.
49const EVP_MD *GetWycheproofDigest(FileTest *t, const char *key,
50 bool instruction);
51
52// GetWycheproofCurve returns a curve using the Wycheproof name, or nullptr on
53// error.
54bssl::UniquePtr<EC_GROUP> GetWycheproofCurve(FileTest *t, const char *key,
55 bool instruction);
56
David Benjamin3f944672018-04-30 11:57:44 -040057// GetWycheproofBIGNUM returns a BIGNUM in the Wycheproof format, or nullptr on
58// error.
59bssl::UniquePtr<BIGNUM> GetWycheproofBIGNUM(FileTest *t, const char *key,
60 bool instruction);
61
David Benjamin40d76f42018-04-26 17:35:53 -040062
63#endif // OPENSSL_HEADER_CRYPTO_TEST_WYCHEPROOF_UTIL_H