OpenSSL ECDSA signatures longer than expected

百般思念 提交于 2019-12-01 18:48:22

Most chips will, for efficiency reasons, just output the r and s as a byte array or octet string, where each r and s is the same as the field size (i.e. key size) in octets. Another approach is to output r and s as a sequence of numbers, because in the end, that is what r and s are. Using ASN.1 this becomes a SEQUENCE of INTEGER values.

To convert from such a sequence you can first BER decode using a BER parser to retrieve the integer. Then implement an I2OSP algorithm (integer to octet stream primitive) which requires the value and the key size in bytes/octets as arguments. The number should be in big integer form, but that's fine as ASN.1 BER encoded integers are also big integers. Basically you must left pad with zero bytes if the number is too small. Then you concatenate the number.

I won't go into OS2IP which converts a byte array to an integer. Note thought that if you encode it in BER form then the integers should not be left padded with zero bytes. So some trickery is required still.

So although the signature changes form, the signature still stays valid; you can simply convert between one form and the other and the signature will still verify - as long as you use the right library for the job, obviously.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!