Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

64 linhas
2.0 KiB

  1. /* Copyright (c) 2015, 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. #include <stdint.h>
  15. #include <string.h>
  16. #include <openssl/curve25519.h>
  17. #include "../test/file_test.h"
  18. static bool TestSignature(FileTest *t, void *arg) {
  19. std::vector<uint8_t> private_key, public_key, message, expected_signature;
  20. if (!t->GetBytes(&private_key, "PRIV") ||
  21. private_key.size() != 64 ||
  22. !t->GetBytes(&public_key, "PUB") ||
  23. public_key.size() != 32 ||
  24. !t->GetBytes(&message, "MESSAGE") ||
  25. !t->GetBytes(&expected_signature, "SIG") ||
  26. expected_signature.size() != 64) {
  27. return false;
  28. }
  29. uint8_t signature[64];
  30. if (!ED25519_sign(signature, message.data(), message.size(),
  31. private_key.data())) {
  32. t->PrintLine("ED25519_sign failed");
  33. return false;
  34. }
  35. if (!t->ExpectBytesEqual(expected_signature.data(), expected_signature.size(),
  36. signature, sizeof(signature))) {
  37. return false;
  38. }
  39. if (!ED25519_verify(message.data(), message.size(), signature,
  40. public_key.data())) {
  41. t->PrintLine("ED25519_verify failed");
  42. return false;
  43. }
  44. return true;
  45. }
  46. int main(int argc, char **argv) {
  47. if (argc != 2) {
  48. fprintf(stderr, "%s <test input.txt>\n", argv[0]);
  49. return 1;
  50. }
  51. return FileTestMain(TestSignature, nullptr, argv[1]);
  52. }