7 /* Forward reference from sshecc.c */
8 struct ec_point *ecp_mul(const struct ec_point *a, const Bignum b);
10 int ec_generate(struct ec_key *key, int bits, progfn_t pfn,
13 struct ec_point *publicKey;
15 if (!ec_nist_alg_and_curve_by_bits(bits, &key->publicKey.curve,
19 key->privateKey = bignum_random_in_range(One, key->publicKey.curve->w.n);
20 if (!key->privateKey) return 0;
22 publicKey = ec_public(key->privateKey, key->publicKey.curve);
24 freebn(key->privateKey);
25 key->privateKey = NULL;
29 key->publicKey.x = publicKey->x;
30 key->publicKey.y = publicKey->y;
31 key->publicKey.z = NULL;
37 int ec_edgenerate(struct ec_key *key, int bits, progfn_t pfn,
40 struct ec_point *publicKey;
42 if (!ec_ed_alg_and_curve_by_bits(bits, &key->publicKey.curve,
47 /* EdDSA secret keys are just 32 bytes of hash preimage; the
48 * 64-byte SHA-512 hash of that key will be used when signing,
49 * but the form of the key stored on disk is the preimage
51 Bignum privMax = bn_power_2(bits);
52 if (!privMax) return 0;
53 key->privateKey = bignum_random_in_range(Zero, privMax);
55 if (!key->privateKey) return 0;
58 publicKey = ec_public(key->privateKey, key->publicKey.curve);
60 freebn(key->privateKey);
61 key->privateKey = NULL;
65 key->publicKey.x = publicKey->x;
66 key->publicKey.y = publicKey->y;
67 key->publicKey.z = NULL;