Facebook
From Yuriy Zernovoy, 1 Month ago, written in C++.
Embed
Download Paste or View Raw
Hits: 165
  1. #include <stdio.h>
  2. #include <memory.h>
  3. //#include <assert.h>
  4. #include "ed25519.cuh"
  5. #include "ge.cuh"
  6. #include "sha512.cuh"
  7. #include "onion.cuh"
  8.  
  9.  
  10. void print_value_hex (void *value, int length) {
  11.     for (int i = 0; i < length; ++i) {
  12.         printf("X", ((unsigned char*)value)[i]);
  13.     }
  14. }
  15.  
  16. #define PRINT_VALUE_HEX(_value) print_value_hex(_value, sizeof(_value))
  17.  
  18. // choose desirable components
  19. #define CREATE_SEED
  20. #define CALCULATE_KEYS_HERE
  21. #define CALCULATE_CHECKSUM
  22.  
  23. int main(int argc, char **argv) {
  24.     unsigned char seed[32];
  25.     unsigned char private_key[64];
  26.     unsigned char public_key[32];
  27.     unsigned char checksum[200];
  28.  
  29.     printf("---------- Test batch with single key pair ----------\n");
  30.  
  31. #ifdef CREATE_SEED
  32.     ed25519_kernel_create_seed(seed,1);
  33. #else
  34.     memcpy (seed, "01234567890123456789012345678901", 32);
  35. #endif
  36.  printf ("seed is:\n");
  37.  PRINT_VALUE_HEX(seed);
  38.  printf ("\n");
  39.  
  40. #ifdef CALCULATE_KEYS_HERE
  41.     ge_p3 A;
  42.  
  43.     sha512(seed, 32, private_key);
  44.     private_key[0] &= 248;
  45.     private_key[31] &= 63;
  46.     private_key[31] |= 64;
  47.  
  48.     ge_scalarmult_base(&A, private_key);
  49.     ge_p3_tobytes(public_key, &A);
  50. #else
  51.     ed25519_kernel_create_keypair_batch (public_key, private_key, seed, 1);
  52. #endif
  53.  
  54.     printf("Private Key\n");
  55.  PRINT_VALUE_HEX(private_key);
  56.  printf ("\n");
  57.  
  58.     printf("Public Key\n");
  59.  PRINT_VALUE_HEX(public_key);
  60.  printf ("\n");
  61.  
  62. #ifdef CALCULATE_CHECKSUM
  63.     onion_address (public_key, checksum);
  64.  
  65.     printf("Checksum\n");
  66.  PRINT_VALUE_HEX(checksum);
  67.  printf ("\n");
  68. #endif
  69.  
  70.     return 0;
  71. }
  72.  
  73.