简体   繁体   English

如何添加两个curve25519点

[英]How do I add two curve25519 points

I have two points ([32]byte) on curve25519.我在curve25519上有两个点([32]字节)。 How do I add them (a + b).我如何添加它们(a + b)。 I obviously can't do it using big.Int, since they aren't numbers but points on the curve.我显然不能使用 big.Int 来做到这一点,因为它们不是数字而是曲线上的点。 I haven't found so far any library to do something similar to what I can do using edwards25519 :到目前为止,我还没有找到任何库来做类似于我可以使用edwards25519做的事情:

a := [32]byte // I get that from another function
b := [32]byte // also from another function
pointA, _ := new(edwards25519.Point).SetBytes(a)
pointB, _ := new(edwards25519.Point).SetBytes(b)
pointC := pointA.Add(pointA, pointB)

fmt.Println(pointC.Bytes())

I already tried using this and converting the result to the montgomery curve using &edwards25519.Point{}.BytesMontgomery() , but I was not able to import neither a nor b into the edwards25519 curve, since they are points on the curve25519.我已经尝试使用它并使用&edwards25519.Point{}.BytesMontgomery()将结果转换为蒙哥马利曲线,但我无法将ab都导入 edwards25519 曲线,因为它们是曲线 25519 上的点。

You can use libsodium to achieve this with two steps.您可以通过两个步骤使用libsodium来实现此目的。

  1. Start with Edwards25519/Ed25519 keys, generate two public keys/points, then call crypto_core_ed25519_add ( documentation ).Edwards25519/Ed25519密钥开始,生成两个公钥/点,然后调用crypto_core_ed25519_add文档)。

  2. Covert the resultant to curve25519 using crypto_sign_ed25519_pk_to_curve25519 via birational map ( documentation ).通过双有理 map(文档)使用crypto_sign_ed25519_pk_to_curve25519将结果转换为curve25519

There are bindings for Go . Go有绑定。 You need to be careful and not use some "random" lib, this stuff is hard to get right and hard to do in constant time (avoid side channels).您需要小心,不要使用一些“随机”库,这些东西很难在恒定时间内正确且难以完成(避免侧通道)。

RFC 7748 provides the formulas to map (x, y) Ed25519 Edwards points to (u, v) Curve25519 Montgomery points and vice versa. RFC 7748将公式提供给 map (x, y) Ed25519 Edwards指向(u, v) Curve25519 Montgomery点,反之亦然。

The birational maps are:双有理图是:

 (u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)
 (x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM