xref: /aosp_15_r20/external/boringssl/src/crypto/test/wycheproof_util.h (revision 8fb009dc861624b67b6cdb62ea21f0f22d0c584b)
1 /* 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 
20 #include <string>
21 #include <vector>
22 
23 
24 // This header contains convenience functions for Wycheproof tests.
25 
26 class FileTest;
27 
28 enum class WycheproofRawResult {
29   kValid,
30   kInvalid,
31   kAcceptable,
32 };
33 
34 struct 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|.
45 bool GetWycheproofResult(FileTest *t, WycheproofResult *out);
46 
47 // GetWycheproofDigest returns a digest function using the Wycheproof name, or
48 // nullptr on error.
49 const 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.
54 const EC_GROUP *GetWycheproofCurve(FileTest *t, const char *key,
55                                    bool instruction);
56 
57 // GetWycheproofBIGNUM returns a BIGNUM in the Wycheproof format, or nullptr on
58 // error.
59 bssl::UniquePtr<BIGNUM> GetWycheproofBIGNUM(FileTest *t, const char *key,
60                                             bool instruction);
61 
62 
63 #endif  // OPENSSL_HEADER_CRYPTO_TEST_WYCHEPROOF_UTIL_H
64