Ejemplo n.º 1
0
bool uc_ecc_create_key(uc_ed25519_key *key) {
  if (!uc_init()) return false;

  wc_ed25519_init(key);
  if (wc_ed25519_make_key(&uc_random, ED25519_KEY_SIZE, key))
    return false;

//  UCDUMP("ECCPRV", key->k, ED25519_PRV_KEY_SIZE);
  UCDUMP("ECCPUB", key->p, ED25519_PUB_KEY_SIZE);

  return true;
}
Ejemplo n.º 2
0
ed25519_key *crypto_ed25519_generate() {
    ed25519_key *key = crypto_ed25519_new();

    WC_RNG rng;
    int r = wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key);
    if (r) {
        DEBUG("Failed to generate key (code %d)", r);
        crypto_ed25519_free(key);
        return NULL;
    }

    return key;
}
Ejemplo n.º 3
0
void bench_ed25519KeyGen(void) {
  ed25519_key genKey;
  double start, total, milliEach;
  int i;

  /* 256 bit */
  start = current_time(1);

  for (i = 0; i < genTimes; i++) {
    wc_ed25519_init(&genKey);
    wc_ed25519_make_key(&rng, 32, &genKey);
    wc_ed25519_free(&genKey);
  }

  total = current_time(0) - start;
  milliEach = total / genTimes / 1000;
  printf("\r\n");
  printf("ED25519  key generation  %6.3f milliseconds, avg over %d"
           " iterations\r\n", milliEach, genTimes);
}
Ejemplo n.º 4
0
void bench_ed25519KeySign(void) {
  int ret;
  ed25519_key genKey;
#ifdef HAVE_ED25519_SIGN
  double start, total, milliEach;
  int i;
  byte sig[ED25519_SIG_SIZE];
  byte msg[512];
  word32 x = 0;
#endif

  wc_ed25519_init(&genKey);

  ret = wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &genKey);
  if (ret != 0) {
    printf("ed25519_make_key failed\r\n");
    return;
  }

#ifdef HAVE_ED25519_SIGN
  /* make dummy msg */
  for (i = 0; i < (int) sizeof(msg); i++)
    msg[i] = (byte) i;

  start = current_time(1);

  for (i = 0; i < agreeTimes; i++) {
    x = sizeof(sig);
    ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
    if (ret != 0) {
      printf("ed25519_sign_msg failed\r\n");
      return;
    }
  }

  total = current_time(0) - start;
  milliEach = total / agreeTimes / 1000;  /* per second  */
  printf("ED25519  sign   time     %6.3f milliseconds, avg over %d"
           " iterations\r\n", milliEach, agreeTimes);

#ifdef HAVE_ED25519_VERIFY
  start = current_time(1);

  for (i = 0; i < agreeTimes; i++) {
    int verify = 0;
    ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
                                &genKey);
    if (ret != 0 || verify != 1) {
      printf("ed25519_verify_msg failed\r\n");
      return;
    }
  }

  total = current_time(0) - start;
  milliEach = total / agreeTimes / 1000;
  printf("ED25519  verify time     %6.3f milliseconds, avg over %d"
           " iterations\r\n", milliEach, agreeTimes);
#endif /* HAVE_ED25519_VERIFY */
#endif /* HAVE_ED25519_SIGN */

  wc_ed25519_free(&genKey);
}