123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #include "keygen.hpp"
- extern const curvepoint_fp_t bn_curvegen;
- extern const twistpoint_fp2_t bn_twistgen;
- void keygen(PublicKey& public_key, PrivateKey& private_key)
- {
- Scalar a1, b1, c1, d1, a2, b2, c2, d2;
-
- while (true)
- {
- a1.set_random();
- b1.set_random();
- c1.set_random();
- if (a1 != 0)
- {
- d1 = (b1 * c1 + Scalar(1)) / a1;
- break;
- }
- }
- while (true)
- {
- a2.set_random();
- b2.set_random();
- c2.set_random();
- if (a2 != 0)
- {
- d2 = (b2 * c2 + Scalar(1)) / a2;
- break;
- }
- }
- private_key.set(a1, b1, c1, d1, a2, b2, c2, d2);
-
- Scalar r1, r2, r3, r4;
- r1.set_random();
- r2.set_random();
- r3.set_random();
- r4.set_random();
- curvepoint_fp_t g_part1, g_part2, g_a1, g_b1;
- g_part1 = r1 * bn_curvegen;
- g_part2 = r2 * bn_curvegen;
- g_a1 = a1 * bn_curvegen;
- g_b1 = b1 * bn_curvegen;
- Bipoint<curvepoint_fp_t> full_g(g_part1, g_part2);
- Bipoint<curvepoint_fp_t> full_g1(g_a1, g_b1);
- twistpoint_fp2_t h_part1, h_part2, h_a2, h_b2;
- h_part1 = r3 * bn_twistgen;
- h_part2 = r4 * bn_twistgen;
- h_a2 = a2 * bn_twistgen;
- h_b2 = b2 * bn_twistgen;
- Bipoint<twistpoint_fp2_t> full_h(h_part1, h_part2);
- Bipoint<twistpoint_fp2_t> full_h1(h_a2, h_b2);
- full_g.make_affine();
- full_g1.make_affine();
- full_h.make_affine();
- full_h1.make_affine();
-
- public_key.set(full_g, full_h, full_g1, full_h1);
- }
|