<p>Hello,</p>
<p>I've generated a EC p-521 cert key pair as such:</p>
<p>Private: openssl ecparam -out test/ec512-wrong-private.pem -name secp521r1 -genkey</p>
<p>Public: openssl ec -in test/ec512-private.pem -pubout > test/ec512-public.pem</p>
<p>When using ecdsa.Sign() to create a signature, the byte sizes of r and s are not consistent to the curve points byte sizes in the certificate.</p>
<p>IE, I checked the values by</p>
<p>fmt.Println(len(r.Bytes()))</p>
<p>fmt.Println(len(s.Bytes()))</p>
<p>The funny part is that this fluctuates. Sometimes its correct and sometimes its not. The problem is that if r or s are off then signature validation will fail.</p>
<p>Note that I tested P-256:</p>
<p>openssl ecparam -out test/ec256-private.pem -name prime256v1 -genkey</p>
<p>openssl ec -in test/ec256-private.pem -pubout > test/ec256-public.pem</p>
<p>And P-384</p>
<p>openssl ecparam -out test/ec384-private.pem -name secp384r1 -genkey</p>
<p>openssl ec -in test/ec384-private.pem -pubout > test/ec384-public.pem</p>
<p>and they work fine...</p>
<p>Question is, why aren't the byte slice lengths consistent for r and s when using P-521? The P-256 and P-384 are.</p>
<hr/>**评论:**<br/><br/>giovannibajo: <pre><p>Please post a repro on playground that reproduces the problem, also including the generated keys in the source code (assuming it's just a test and you can share them).</p></pre>scythelx: <pre><p><a href="http://play.golang.org/p/yhg_2jvS0e" rel="nofollow">http://play.golang.org/p/yhg_2jvS0e</a></p></pre>scythelx: <pre><p>I was able to resolve by using a asn1 encoding on the r, s big.Int values. IE so I'm able to consistently unmarshal the data.</p></pre>minyosdy: <pre><p>Because sometimes the upper 8+ bits of r or s are zero.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传