Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

67 rader
2.1 KiB

  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. // cavp_ecdsa2_pkv_test processes a NIST CAVP ECDSA2 PKV test vector request file
  15. // and emits the corresponding response.
  16. #include <vector>
  17. #include <openssl/bn.h>
  18. #include <openssl/crypto.h>
  19. #include <openssl/ec_key.h>
  20. #include <openssl/err.h>
  21. #include <openssl/nid.h>
  22. #include "../crypto/test/file_test.h"
  23. #include "cavp_test_util.h"
  24. static bool TestECDSA2PKV(FileTest *t, void *arg) {
  25. int nid = GetECGroupNIDFromInstruction(t);
  26. if (nid == NID_undef) {
  27. return false;
  28. }
  29. bssl::UniquePtr<EC_KEY> key(EC_KEY_new_by_curve_name(nid));
  30. bssl::UniquePtr<BIGNUM> qx = GetBIGNUM(t, "Qx");
  31. bssl::UniquePtr<BIGNUM> qy = GetBIGNUM(t, "Qy");
  32. if (!key || !qx || !qy) {
  33. return false;
  34. }
  35. if (EC_KEY_set_public_key_affine_coordinates(key.get(), qx.get(), qy.get())) {
  36. printf("%sResult = P\r\n\r\n", t->CurrentTestToString().c_str());
  37. } else {
  38. char buf[256];
  39. ERR_error_string_n(ERR_get_error(), buf, sizeof(buf));
  40. printf("%sResult = F (%s)\r\n\r\n", t->CurrentTestToString().c_str(), buf);
  41. }
  42. ERR_clear_error();
  43. return true;
  44. }
  45. int cavp_ecdsa2_pkv_test_main(int argc, char **argv) {
  46. if (argc != 2) {
  47. fprintf(stderr, "usage: %s <test file>\n",
  48. argv[0]);
  49. return 1;
  50. }
  51. FileTest::Options opts;
  52. opts.path = argv[1];
  53. opts.callback = TestECDSA2PKV;
  54. opts.silent = true;
  55. opts.comment_callback = EchoComment;
  56. return FileTestMain(opts);
  57. }