Merge pull request #4 from PowerDNS/ecdsa-pad

fix leading zero padding in ECDSA sig conversion
This commit is contained in:
David Blacka 2017-06-23 09:55:28 -04:00 committed by GitHub
commit de2216f259
2 changed files with 16 additions and 3 deletions

View File

@ -1,3 +1,7 @@
2017-06-22 Peter van Dijk <peter.van.dijk@powerdns.com>, Kees Monshouwer <mind04@monshouwer.eu>
* Fix leading zero(s) padding in ECDSA sig conversion
2017-01-06 David Blacka <davidb@verisign.com> 2017-01-06 David Blacka <davidb@verisign.com>
* Released version 0.13 * Released version 0.13

View File

@ -526,10 +526,19 @@ public class SignUtils
s_src_pos = (byte) (r_src_pos + r_src_len); s_pad = 0; s_src_pos = (byte) (r_src_pos + r_src_len); s_pad = 0;
len = (byte) (6 + r_src_len + s_src_len); len = (byte) (6 + r_src_len + s_src_len);
if (signature[r_src_pos] < 0) { // leading zeroes are forbidden
while (signature[r_src_pos] == 0 && r_src_len > 0) {
r_src_pos++; r_src_len--; len--;
}
while (signature[s_src_pos] == 0 && s_src_len > 0) {
s_src_pos++; s_src_len--; len--;
}
// except when they are mandatory
if (r_src_len > 0 && signature[r_src_pos] < 0) {
r_pad = 1; len++; r_pad = 1; len++;
} }
if (signature[s_src_pos] < 0) { if (s_src_len > 0 && signature[s_src_pos] < 0) {
s_pad = 1; len++; s_pad = 1; len++;
} }
byte[] sig = new byte[len]; byte[] sig = new byte[len];