Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/contrib/lax_der_parsing.c
Show All 26 Lines | int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) { | ||||
/* Sequence length bytes */ | /* Sequence length bytes */ | ||||
if (pos == inputlen) { | if (pos == inputlen) { | ||||
return 0; | return 0; | ||||
} | } | ||||
lenbyte = input[pos++]; | lenbyte = input[pos++]; | ||||
if (lenbyte & 0x80) { | if (lenbyte & 0x80) { | ||||
lenbyte -= 0x80; | lenbyte -= 0x80; | ||||
if (pos + lenbyte > inputlen) { | if (lenbyte > inputlen - pos) { | ||||
return 0; | return 0; | ||||
} | } | ||||
pos += lenbyte; | pos += lenbyte; | ||||
} | } | ||||
/* Integer tag byte for R */ | /* Integer tag byte for R */ | ||||
if (pos == inputlen || input[pos] != 0x02) { | if (pos == inputlen || input[pos] != 0x02) { | ||||
return 0; | return 0; | ||||
} | } | ||||
pos++; | pos++; | ||||
/* Integer length for R */ | /* Integer length for R */ | ||||
if (pos == inputlen) { | if (pos == inputlen) { | ||||
return 0; | return 0; | ||||
} | } | ||||
lenbyte = input[pos++]; | lenbyte = input[pos++]; | ||||
if (lenbyte & 0x80) { | if (lenbyte & 0x80) { | ||||
lenbyte -= 0x80; | lenbyte -= 0x80; | ||||
if (pos + lenbyte > inputlen) { | if (lenbyte > inputlen - pos) { | ||||
return 0; | return 0; | ||||
} | } | ||||
while (lenbyte > 0 && input[pos] == 0) { | while (lenbyte > 0 && input[pos] == 0) { | ||||
pos++; | pos++; | ||||
lenbyte--; | lenbyte--; | ||||
} | } | ||||
if (lenbyte >= sizeof(size_t)) { | if (lenbyte >= sizeof(size_t)) { | ||||
return 0; | return 0; | ||||
Show All 21 Lines | int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) { | ||||
/* Integer length for S */ | /* Integer length for S */ | ||||
if (pos == inputlen) { | if (pos == inputlen) { | ||||
return 0; | return 0; | ||||
} | } | ||||
lenbyte = input[pos++]; | lenbyte = input[pos++]; | ||||
if (lenbyte & 0x80) { | if (lenbyte & 0x80) { | ||||
lenbyte -= 0x80; | lenbyte -= 0x80; | ||||
if (pos + lenbyte > inputlen) { | if (lenbyte > inputlen - pos) { | ||||
return 0; | return 0; | ||||
} | } | ||||
while (lenbyte > 0 && input[pos] == 0) { | while (lenbyte > 0 && input[pos] == 0) { | ||||
pos++; | pos++; | ||||
lenbyte--; | lenbyte--; | ||||
} | } | ||||
if (lenbyte >= sizeof(size_t)) { | if (lenbyte >= sizeof(size_t)) { | ||||
return 0; | return 0; | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |