为什么 P-521 公钥 X,Y 有时是 65 字节有时是 66 字节 [英] Why P-521 public key X,Y some time is 65 bytes some time is 66 bytes

查看:74
本文介绍了为什么 P-521 公钥 X,Y 有时是 65 字节有时是 66 字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 golang 生成 P-521 公钥.源代码看起来像这样:

I use golang generate the P-521 public key. source code look like that:

curve:=elliptic.P521()
priv, x, y, err := elliptic.GenerateKey(curve, rand.Reader)
xBytes:=x.Bytes()
yBytes:=y.bytes()
//len(xBytes)  some time is 65 bytes ,some time is 66 bytes 

为什么 P-521 公钥 X、Y 不像 P-256 或 P-384 具有固定公钥长度?

Why P-521 public key X,Y not like P-256 or P-384 that have a fixed public key length?

推荐答案

secp521r1 使用 521 位素数字段.因此 X 或 Y 坐标表示为 521 位数字.是的,521,不是 512.

secp521r1 uses a 521-bit prime field. So the X or Y coordinates are represented as 521-bit numbers. Yes, 521, not 512.

521 位是 65 个完整字节,还有一位剩余.在公钥的固定大小编码中,最高有效字节的 7 个最高有效位始终设置为 0,第 8 位将为 1 或 0(因此整个字节为 0x00 或 0x01).

521 bits is 65 full bytes and one bit left over. In a fixed-size encoding of the public key the most significant byte would always have the 7 most significant bits set to 0, and the 8th bit will be 1 or 0 (so the whole byte is 0x00 or 0x01).

由于坐标空间不是完全的所有 521 位数字,因此为任何特定点设置高位的可能性略低于 50%.

Since the coordinate space isn't quite all of the 521-bit numbers, you have a slightly less than 50% chance of the high bit being set for any particular point.

Go 的方法似乎使用最小字节表示返回值.所以你应该看到类似

Go's method seems to be returning the value using a minimum-byte representation. So you should see something like

  • 66 字节:49% 的时间
  • 65 字节:50% 的时间
  • 64 字节(前 9 位全为 0):0.2%
  • (63 字节及以下是可能的,但百分比非常小)

这篇关于为什么 P-521 公钥 X,Y 有时是 65 字节有时是 66 字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆