Issue with ecdsa.Sign when using P-521 with SHA-512

polaris · · 776 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello,</p> <p>I&#39;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 &gt; 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 &gt; 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 &gt; test/ec384-public.pem</p> <p>and they work fine...</p> <p>Question is, why aren&#39;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&#39;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&#39;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

776 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传