genkeys.c 982 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <openssl/rand.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "ptwist.h"
  5. int main(int argc, char **argv)
  6. {
  7. byte privkey[PTWIST_BYTES];
  8. byte maingen[PTWIST_BYTES];
  9. byte twistgen[PTWIST_BYTES];
  10. byte mainpub[PTWIST_BYTES];
  11. byte twistpub[PTWIST_BYTES];
  12. FILE *fp;
  13. RAND_seed("12345678901234567890", 20);
  14. /* Pick a random private key */
  15. RAND_bytes(privkey, PTWIST_BYTES);
  16. /* Load the generators of the main and twist curves */
  17. memset(maingen, 0, PTWIST_BYTES);
  18. maingen[0] = 2;
  19. memset(twistgen, 0, PTWIST_BYTES);
  20. /* Create the pubkeys */
  21. ptwist_pointmul(mainpub, maingen, privkey);
  22. ptwist_pointmul(twistpub, twistgen, privkey);
  23. /* Save the privkey and pubkeys */
  24. fp = fopen("privkey", "wb");
  25. fwrite(privkey, PTWIST_BYTES, 1, fp);
  26. fclose(fp);
  27. fp = fopen("pubkey", "wb");
  28. fwrite(mainpub, PTWIST_BYTES, 1, fp);
  29. fwrite(twistpub, PTWIST_BYTES, 1, fp);
  30. fclose(fp);
  31. return 0;
  32. }