test_ed25519.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <stddef.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <stdio.h>
  6. #include "types.h"
  7. #include "base16.h"
  8. #include "ed25519/ed25519.h"
  9. #include "ed25519/ed25519_impl_pre.h"
  10. #include "testutil.h"
  11. struct pktest {
  12. const char *seed;
  13. const char *secret;
  14. const char *public;
  15. } test0[] = {
  16. {
  17. "26c76712d89d906e6672dafa614c42e5cb1caac8c6568e4d2493087db51f0d36",
  18. "c0a4de23cc64392d85aa1da82b3defddbea946d13bb053bf8489fa9296281f49"
  19. "5022f1f7ec0dcf52f07d4c7965c4eaed121d5d88d0a8ff546b06116a20e97755",
  20. "c2247870536a192d142d056abefca68d6193158e7c1a59c1654c954eccaff894",
  21. },
  22. {
  23. "fba7a5366b5cb98c2667a18783f5cf8f4f8d1a2ce939ad22a6e685edde85128d",
  24. "18a8a69a06790dac778e882f7e868baacfa12521a5c058f5194f3a729184514a"
  25. "2a656fe7799c3e41f43d756da8d9cd47a061316cfe6147e23ea2f90d1ca45f30",
  26. "1519a3b15816a1aafab0b213892026ebf5c0dc232c58b21088d88cb90e9b940d"
  27. },
  28. };
  29. #define SEEDBYTES 32
  30. #define SECRETKEYBYTES 64
  31. #define PUBLICKEYBYTES 32
  32. int main(void)
  33. {
  34. u8 seedbuf[SEEDBYTES];
  35. u8 secretbuf1[SECRETKEYBYTES];
  36. u8 secretbuf2[SECRETKEYBYTES];
  37. u8 publicbuf1[PUBLICKEYBYTES];
  38. u8 publicbuf2[PUBLICKEYBYTES];
  39. u8 mask;
  40. char str1[1024], str2[1024];
  41. for (size_t i = 0; i < sizeof(test0)/sizeof(test0[0]); ++i) {
  42. base16_from(seedbuf, &mask, test0[i].seed);
  43. base16_from(secretbuf1, &mask, test0[i].secret);
  44. base16_from(publicbuf1, &mask, test0[i].public);
  45. ed25519_seckey_expand(secretbuf2, seedbuf);
  46. WARNF(memcmp(secretbuf1, secretbuf2, SECRETKEYBYTES) == 0) {
  47. base16_to(str1, secretbuf1, sizeof(secretbuf1));
  48. base16_to(str2, secretbuf2, sizeof(secretbuf2));
  49. fprintf(stderr, "expected: %s got %s\n", str1, str2);
  50. }
  51. ed25519_pubkey(publicbuf2, secretbuf1);
  52. WARNF(memcmp(publicbuf1, publicbuf2, PUBLICKEYBYTES) == 0) {
  53. base16_to(str1, publicbuf1, sizeof(publicbuf1));
  54. base16_to(str2, publicbuf2, sizeof(publicbuf2));
  55. fprintf(stderr, "expected: %s got %s\n", str1, str2);
  56. }
  57. }
  58. return 0;
  59. }
  60. #include "ed25519/ed25519_impl_post.h"