123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "keygen.hpp"
- extern const scalar_t bn_n;
- extern const curvepoint_fp_t bn_curvegen;
- extern const twistpoint_fp2_t bn_twistgen;
- void keygen(PublicKey& public_key, PrivateKey& private_key)
- {
- Fp i1, j1, k1, l1, i2, j2, k2, l2;
-
- while (true)
- {
- j1.set_random();
- k1.set_random();
- l1.set_random();
- if (!l1.is_zero())
- {
- i1 = (j1 * k1 + Fp(1)) / l1;
- break;
- }
- }
- while (true)
- {
- j2.set_random();
- k2.set_random();
- l2.set_random();
- if (!l2.is_zero())
- {
- i2 = (j2 * k2 + Fp(1)) / l2;
- break;
- }
- }
- private_key.set(i1, j1, k1, l1, i2, j2, k2, l2);
-
- curvepoint_fp_t c1, c2, c3, c4;
-
- curvepoint_fp_scalarmult_vartime(c1, bn_curvegen, i1.to_scalar());
- curvepoint_fp_makeaffine(c1);
- curvepoint_fp_scalarmult_vartime(c2, bn_curvegen, j1.to_scalar());
- curvepoint_fp_makeaffine(c2);
- Bipoint<curvepoint_fp_t> b1(c1, c2);
- twistpoint_fp2_t t1, t2, t3, t4;
- twistpoint_fp2_scalarmult_vartime(t1, bn_twistgen,i2.scalar());
- twistpoint_fp2_makeaffine(t1);
- twistpoint_fp2_scalarmult_vartime(t2, bn_twistgen,j2.scalar());
- twistpoint_fp2_makeaffine(t2);
- Bipoint<twistpoint_fp2_t> b2(t1, t2);
-
- scalar_t s1, s2, s3, s4;
- scalar_setrandom(s1, bn_n);
- scalar_setrandom(s2, bn_n);
- scalar_setrandom(s3, bn_n);
- scalar_setrandom(s4, bn_n);
-
- curvepoint_fp_scalarmult_vartime(c3, bn_curvegen, s1);
- curvepoint_fp_makeaffine(c3);
- curvepoint_fp_scalarmult_vartime(c4, bn_curvegen, s2);
- curvepoint_fp_makeaffine(c4);
- Bipoint<curvepoint_fp_t> b3(c3, c4);
-
- twistpoint_fp2_scalarmult_vartime(t3, bn_twistgen, s3);
- twistpoint_fp2_makeaffine(t3);
- twistpoint_fp2_scalarmult_vartime(t4, bn_twistgen, s4);
- twistpoint_fp2_makeaffine(t4);
-
- Bipoint<twistpoint_fp2_t> b4(t3, t4);
-
- public_key.set(b1, b2, b3, b4);
- }
|