fix multiple leading zeros padding in ECDSA sig conversion

This commit is contained in:
Kees Monshouwer 2017-06-22 13:21:54 +02:00 committed by Peter van Dijk
parent 171594a92d
commit ca2a932485

View File

@ -527,18 +527,18 @@ public class SignUtils
len = (byte) (6 + r_src_len + s_src_len);
// leading zeroes are forbidden
if (signature[r_src_pos] == 0) {
r_src_pos++; r_src_len--; len--;
while (signature[r_src_pos] == 0 && r_src_len > 0) {
r_src_pos++; r_src_len--; len--;
}
if (signature[s_src_pos] == 0) {
s_src_pos++; s_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 (signature[r_src_pos] < 0) {
r_pad = 1; len++;
if (r_src_len > 0 && signature[r_src_pos] < 0) {
r_pad = 1; len++;
}
if (signature[s_src_pos] < 0) {
if (s_src_len > 0 && signature[s_src_pos] < 0) {
s_pad = 1; len++;
}
byte[] sig = new byte[len];