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.

44 lines
1.9 KiB

  1. #define TEST_NAME "ed25519_convert"
  2. #include "cmptest.h"
  3. static const unsigned char keypair_seed[crypto_sign_ed25519_SEEDBYTES]
  4. = { 0x42, 0x11, 0x51, 0xa4, 0x59, 0xfa, 0xea, 0xde, 0x3d, 0x24, 0x71,
  5. 0x15, 0xf9, 0x4a, 0xed, 0xae, 0x42, 0x31, 0x81, 0x24, 0x09, 0x5a,
  6. 0xfa, 0xbe, 0x4d, 0x14, 0x51, 0xa5, 0x59, 0xfa, 0xed, 0xee };
  7. int main(void)
  8. {
  9. unsigned char ed25519_pk[crypto_sign_ed25519_PUBLICKEYBYTES];
  10. unsigned char ed25519_skpk[crypto_sign_ed25519_SECRETKEYBYTES];
  11. unsigned char curve25519_pk[crypto_scalarmult_curve25519_BYTES];
  12. unsigned char curve25519_pk2[crypto_scalarmult_curve25519_BYTES];
  13. unsigned char curve25519_sk[crypto_scalarmult_curve25519_BYTES];
  14. char curve25519_pk_hex[crypto_scalarmult_curve25519_BYTES * 2 + 1];
  15. char curve25519_sk_hex[crypto_scalarmult_curve25519_BYTES * 2 + 1];
  16. unsigned int i;
  17. crypto_sign_ed25519_seed_keypair(ed25519_pk, ed25519_skpk, keypair_seed);
  18. crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk);
  19. crypto_sign_ed25519_sk_to_curve25519(curve25519_sk, ed25519_skpk);
  20. sodium_bin2hex(curve25519_pk_hex, sizeof curve25519_pk_hex, curve25519_pk,
  21. sizeof curve25519_pk);
  22. sodium_bin2hex(curve25519_sk_hex, sizeof curve25519_sk_hex, curve25519_sk,
  23. sizeof curve25519_sk);
  24. printf("curve25519 pk: [%s]\n", curve25519_pk_hex);
  25. printf("curve25519 sk: [%s]\n", curve25519_sk_hex);
  26. for (i = 0U; i < 500U; i++) {
  27. crypto_sign_ed25519_keypair(ed25519_pk, ed25519_skpk);
  28. crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk);
  29. crypto_sign_ed25519_sk_to_curve25519(curve25519_sk, ed25519_skpk);
  30. crypto_scalarmult_curve25519_base(curve25519_pk2, curve25519_sk);
  31. if (memcmp(curve25519_pk, curve25519_pk2, sizeof curve25519_pk) != 0) {
  32. printf("conversion failed\n");
  33. }
  34. }
  35. printf("ok\n");
  36. return 0;
  37. }