MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / Double

Method Double

libi2pd/Ed25519.cpp:265–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263 }
264
265 void Ed25519::Double (EDDSAPoint& p, BN_CTX * ctx) const
266 {
267 BN_CTX_start (ctx);
268 BIGNUM * x2 = BN_CTX_get (ctx), * y2 = BN_CTX_get (ctx), * z2 = BN_CTX_get (ctx), * t2 = BN_CTX_get (ctx);
269
270 BN_sqr (x2, p.x, ctx); // x2 = A = x^2
271 BN_sqr (y2, p.y, ctx); // y2 = B = y^2
272 if (p.t)
273 BN_sqr (t2, p.t, ctx); // t2 = t^2
274 else
275 {
276 BN_mul (t2, p.x, p.y, ctx); // t = x*y
277 BN_sqr (t2, t2, ctx); // t2 = t^2
278 }
279 BN_mul (t2, t2, d, ctx); // t2 = C = d*t^2
280 if (p.z)
281 BN_sqr (z2, p.z, ctx); // z2 = D = z^2
282 else
283 BN_one (z2); // z2 = 1
284
285 BIGNUM * E = BN_CTX_get (ctx), * F = BN_CTX_get (ctx), * G = BN_CTX_get (ctx), * H = BN_CTX_get (ctx);
286 // E = (x+y)*(x+y)-A-B = x^2+y^2+2xy-A-B = 2xy
287 BN_mul (E, p.x, p.y, ctx);
288 BN_lshift1 (E, E); // E =2*x*y
289 BN_sub (F, z2, t2); // F = D - C
290 BN_add (G, z2, t2); // G = D + C
291 BN_add (H, y2, x2); // H = B + A
292
293 BN_mod_mul (p.x, E, F, q, ctx); // x2 = E*F
294 BN_mod_mul (p.y, G, H, q, ctx); // y2 = G*H
295 if (!p.z) p.z = BN_new ();
296 BN_mod_mul (p.z, F, G, q, ctx); // z2 = F*G
297 if (!p.t) p.t = BN_new ();
298 BN_mod_mul (p.t, E, H, q, ctx); // t2 = E*H
299
300 BN_CTX_end (ctx);
301 }
302
303 EDDSAPoint Ed25519::Mul (const EDDSAPoint& p, const BIGNUM * e, BN_CTX * ctx) const
304 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected