algorithm - How do I sign a curve25519 key in golang?
问题描述
I am trying to implement the X3DH algorithm from Signal in Go. However, I got stuck on how to sign the Public Signed PreKey.
Per the specifications it is supposed to be an X25519 key. In looking at previous implementations on Github they generated a [32]byte
key from the curve25519
package and then converted it to an ed25519
key and then signed it.
However, the packages they used for the conversion are deprecated (github.com/agl/ed25519
). Therefore, I either need to be able to convert the keys to ed25519
so I can sign them with the current ed25519
package (golang.org/x/crypto/25519
) or implement a sign and verify function for curve25519
keys.
解决方案
这需要一个公共的curve25519 密钥并将其转换为一个ed25519 的公共密钥。我没有编写此代码,但似乎正在做上面伍德斯托克所说的事情。欢迎提供更多信息:
func Verify(publicKey [32]byte, message []byte, signature *[64]byte) bool {
publicKey[31] &= 0x7F
/* Convert the Curve25519 public key into an Ed25519 public key. In
particular, convert Curve25519's "montgomery" x-coordinate into an
Ed25519 "edwards" y-coordinate:
ed_y = (mont_x - 1) / (mont_x + 1)
NOTE: mont_x=-1 is converted to ed_y=0 since fe_invert is mod-exp
Then move the sign bit into the pubkey from the signature.
*/
var edY, one, montX, montXMinusOne, montXPlusOne FieldElement
FeFromBytes(&montX, &publicKey)
FeOne(&one)
FeSub(&montXMinusOne, &montX, &one)
FeAdd(&montXPlusOne, &montX, &one)
FeInvert(&montXPlusOne, &montXPlusOne)
FeMul(&edY, &montXMinusOne, &montXPlusOne)
var A_ed [32]byte
FeToBytes(&A_ed, &edY)
A_ed[31] |= signature[63] & 0x80
signature[63] &= 0x7F
var sig = make([]byte, 64)
var aed = make([]byte, 32)
copy(sig, signature[:])
copy(aed, A_ed[:])
return ed25519.Verify(aed, message, sig)
这使用“golang.org/x/crypto/ed25519/internal”中的函数
推荐阅读
- azure - 为什么 sendgrid 营销部门会未经授权
- angular - 如果复选框选中角度 6,则启用文本框
- python - Keras 训练卡在 LSTM 中
- python - Mac OS Python 安装搞砸了
- javascript - html, css, img(svg) 转pdf 使用js jspdf
- node.js - 使用 npm 模块 basic_auth
- gnu-make - 有没有办法扩展 Makefile 宏来创建规则?
- angular - 在子组件Angular 5控件值访问器中访问父表单验证
- reactjs - ReactJS:材质 ui 断点
- oracle - Oracle SQL Developer 初始化欢迎页面时出现问题