cavp_ecdsa2_pkv_test.cc
Go to the documentation of this file.
1 /* Copyright (c) 2017, 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 // cavp_ecdsa2_pkv_test processes a NIST CAVP ECDSA2 PKV test vector request file
16 // and emits the corresponding response.
17 
18 #include <vector>
19 
20 #include <openssl/bn.h>
21 #include <openssl/crypto.h>
22 #include <openssl/ec_key.h>
23 #include <openssl/err.h>
24 #include <openssl/nid.h>
25 
26 #include "../crypto/test/file_test.h"
27 #include "cavp_test_util.h"
28 
29 
30 static bool TestECDSA2PKV(FileTest *t, void *arg) {
32  if (nid == NID_undef) {
33  return false;
34  }
35  bssl::UniquePtr<EC_KEY> key(EC_KEY_new_by_curve_name(nid));
36  bssl::UniquePtr<BIGNUM> qx = GetBIGNUM(t, "Qx");
37  bssl::UniquePtr<BIGNUM> qy = GetBIGNUM(t, "Qy");
38  if (!key || !qx || !qy) {
39  return false;
40  }
41 
42  if (EC_KEY_set_public_key_affine_coordinates(key.get(), qx.get(), qy.get())) {
43  printf("%sResult = P\r\n\r\n", t->CurrentTestToString().c_str());
44  } else {
45  char buf[256];
47  printf("%sResult = F (%s)\r\n\r\n", t->CurrentTestToString().c_str(), buf);
48  }
50  return true;
51 }
52 
53 int cavp_ecdsa2_pkv_test_main(int argc, char **argv) {
54  if (argc != 2) {
55  fprintf(stderr, "usage: %s <test file>\n",
56  argv[0]);
57  return 1;
58  }
59 
61  opts.path = argv[1];
62  opts.callback = TestECDSA2PKV;
63  opts.silent = true;
64  opts.comment_callback = EchoComment;
65  return FileTestMain(opts);
66 }
bn.h
EC_KEY_new_by_curve_name
#define EC_KEY_new_by_curve_name
Definition: boringssl_prefix_symbols.h:1356
FileTestMain
int FileTestMain(FileTestFunc run_test, void *arg, const char *path)
Definition: file_test.cc:399
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
printf
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Definition: cs_driver.c:91
cstest_report.opts
opts
Definition: cstest_report.py:81
ERR_get_error
#define ERR_get_error
Definition: boringssl_prefix_symbols.h:1419
python_utils.port_server.stderr
stderr
Definition: port_server.py:51
cavp_test_util.h
GetECGroupNIDFromInstruction
int GetECGroupNIDFromInstruction(FileTest *t, const char **out_str)
Definition: cavp_test_util.cc:172
FileTest
Definition: file_test.h:90
err.h
crypto.h
arg
Definition: cmdline.cc:40
cavp_ecdsa2_pkv_test_main
int cavp_ecdsa2_pkv_test_main(int argc, char **argv)
Definition: cavp_ecdsa2_pkv_test.cc:53
ec_key.h
NID_undef
#define NID_undef
Definition: nid.h:85
EchoComment
void EchoComment(const std::string &comment)
Definition: cavp_test_util.cc:218
ERR_error_string_n
#define ERR_error_string_n
Definition: boringssl_prefix_symbols.h:1416
EC_KEY_set_public_key_affine_coordinates
#define EC_KEY_set_public_key_affine_coordinates
Definition: boringssl_prefix_symbols.h:1368
GetBIGNUM
static bssl::UniquePtr< BIGNUM > GetBIGNUM(FileTest *t, const char *key)
Definition: ecdh_test.cc:62
nid
int nid
Definition: cipher_extra.c:71
nid.h
key
const char * key
Definition: hpack_parser_table.cc:164
ERR_clear_error
#define ERR_clear_error
Definition: boringssl_prefix_symbols.h:1413
FileTest::Options
Definition: file_test.h:104
TestECDSA2PKV
static bool TestECDSA2PKV(FileTest *t, void *arg)
Definition: cavp_ecdsa2_pkv_test.cc:30


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:52