David Benjamin | 90801c1 | 2017-04-28 17:08:45 -0400 | [diff] [blame] | 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 |
Martin Kreichgauer | bf21849 | 2017-05-03 17:10:14 -0700 | [diff] [blame] | 16 | // and emits the corresponding response. |
David Benjamin | 90801c1 | 2017-04-28 17:08:45 -0400 | [diff] [blame] | 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 | |
Adam Langley | 58e4499 | 2017-04-28 16:45:49 -0700 | [diff] [blame] | 26 | #include "../crypto/test/file_test.h" |
David Benjamin | 90801c1 | 2017-04-28 17:08:45 -0400 | [diff] [blame] | 27 | #include "cavp_test_util.h" |
| 28 | |
| 29 | |
| 30 | static 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 | |
Martin Kreichgauer | ddfcc6a | 2017-05-03 14:12:39 -0700 | [diff] [blame] | 53 | int cavp_ecdsa2_pkv_test_main(int argc, char **argv) { |
David Benjamin | 90801c1 | 2017-04-28 17:08:45 -0400 | [diff] [blame] | 54 | if (argc != 2) { |
| 55 | fprintf(stderr, "usage: %s <test file>\n", |
| 56 | argv[0]); |
| 57 | return 1; |
| 58 | } |
| 59 | |
Adam Langley | d79bc9d | 2017-05-30 15:37:27 -0700 | [diff] [blame^] | 60 | 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); |
David Benjamin | 90801c1 | 2017-04-28 17:08:45 -0400 | [diff] [blame] | 66 | } |