You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

60 line
2.2 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 <gtest/gtest.h>
  17. #include <openssl/curve25519.h>
  18. #include "../internal.h"
  19. #include "../test/file_test.h"
  20. #include "../test/test_util.h"
  21. TEST(Ed25519Test, TestVectors) {
  22. FileTestGTest("crypto/curve25519/ed25519_tests.txt", [](FileTest *t) {
  23. std::vector<uint8_t> private_key, public_key, message, expected_signature;
  24. ASSERT_TRUE(t->GetBytes(&private_key, "PRIV"));
  25. ASSERT_EQ(64u, private_key.size());
  26. ASSERT_TRUE(t->GetBytes(&public_key, "PUB"));
  27. ASSERT_EQ(32u, public_key.size());
  28. ASSERT_TRUE(t->GetBytes(&message, "MESSAGE"));
  29. ASSERT_TRUE(t->GetBytes(&expected_signature, "SIG"));
  30. ASSERT_EQ(64u, expected_signature.size());
  31. uint8_t signature[64];
  32. ASSERT_TRUE(ED25519_sign(signature, message.data(), message.size(),
  33. private_key.data()));
  34. EXPECT_EQ(Bytes(expected_signature), Bytes(signature));
  35. EXPECT_TRUE(ED25519_verify(message.data(), message.size(), signature,
  36. public_key.data()));
  37. });
  38. }
  39. TEST(Ed25519Test, KeypairFromSeed) {
  40. uint8_t public_key1[32], private_key1[64];
  41. ED25519_keypair(public_key1, private_key1);
  42. uint8_t seed[32];
  43. OPENSSL_memcpy(seed, private_key1, sizeof(seed));
  44. uint8_t public_key2[32], private_key2[64];
  45. ED25519_keypair_from_seed(public_key2, private_key2, seed);
  46. EXPECT_EQ(Bytes(public_key1), Bytes(public_key2));
  47. EXPECT_EQ(Bytes(private_key1), Bytes(private_key2));
  48. }