blob: d823e7af63972226b68a0cde7ff1848ab1a80411 [file] [log] [blame]
Robert Sloan2424d842017-05-01 07:46:28 -07001/* 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
Robert Sloan8ff03552017-06-14 12:40:58 -070016// and emits the corresponding response.
Robert Sloan2424d842017-05-01 07:46:28 -070017
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
30static bool TestECDSA2PKV(FileTest *t, void *arg) {
31 int nid = GetECGroupNIDFromInstruction(t);
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];
46 ERR_error_string_n(ERR_get_error(), buf, sizeof(buf));
47 printf("%sResult = F (%s)\r\n\r\n", t->CurrentTestToString().c_str(), buf);
48 }
49 ERR_clear_error();
50 return true;
51}
52
Robert Sloan8ff03552017-06-14 12:40:58 -070053int cavp_ecdsa2_pkv_test_main(int argc, char **argv) {
Robert Sloan2424d842017-05-01 07:46:28 -070054 if (argc != 2) {
55 fprintf(stderr, "usage: %s <test file>\n",
56 argv[0]);
57 return 1;
58 }
59
Robert Sloan8ff03552017-06-14 12:40:58 -070060 FileTest::Options opts;
61 opts.path = argv[1];
62 opts.callback = TestECDSA2PKV;
63 opts.silent = true;
64 opts.comment_callback = EchoComment;
65 return FileTestMain(opts);
Robert Sloan2424d842017-05-01 07:46:28 -070066}