Skip to content

Commit 14c7dbd

Browse files
Simplify control flow in DER parsing
1 parent ec8f20b commit 14c7dbd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/ecdsa_impl.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ static int secp256k1_der_parse_integer(secp256k1_scalar *r, const unsigned char
128128
/* Negative. */
129129
overflow = 1;
130130
}
131-
while (rlen > 0 && **sig == 0) {
132-
/* Skip leading zero bytes */
131+
/* There is at most one leading zero byte:
132+
* if there were two leading zero bytes, we would have failed and returned 0
133+
* because of excessive 0x00 padding already. */
134+
if (rlen > 0 && **sig == 0) {
135+
/* Skip leading zero byte */
133136
rlen--;
134137
(*sig)++;
135138
}

0 commit comments

Comments
 (0)