Skip to content

Commit accb61e

Browse files
authored
lib: DER signature decoding correction
1 parent 03e06e1 commit accb61e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/elliptic/ec/signature.js

+10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ function getLength(buf, p) {
3838
return false;
3939
}
4040

41+
if(buf[p.place] === 0x00) {
42+
return false;
43+
}
44+
4145
var val = 0;
4246
for (var i = 0, off = p.place; i < octetLen; i++, off++) {
4347
val <<= 8;
@@ -86,6 +90,9 @@ Signature.prototype._importDER = function _importDER(data, enc) {
8690
if (rlen === false) {
8791
return false;
8892
}
93+
if ((data[p.place] & 128) !== 0) {
94+
return false;
95+
}
8996
var r = data.slice(p.place, rlen + p.place);
9097
p.place += rlen;
9198
if (data[p.place++] !== 0x02) {
@@ -98,6 +105,9 @@ Signature.prototype._importDER = function _importDER(data, enc) {
98105
if (data.length !== slen + p.place) {
99106
return false;
100107
}
108+
if ((data[p.place] & 128) !== 0) {
109+
return false;
110+
}
101111
var s = data.slice(p.place, slen + p.place);
102112
if (r[0] === 0) {
103113
if (r[1] & 0x80) {

lib/elliptic/eddsa/signature.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function Signature(eddsa, sig) {
2121
sig = parseBytes(sig);
2222

2323
if (Array.isArray(sig)) {
24+
assert(sig.length === eddsa.encodingLength * 2, 'Signature has invalid size');
2425
sig = {
2526
R: sig.slice(0, eddsa.encodingLength),
2627
S: sig.slice(eddsa.encodingLength),

0 commit comments

Comments
 (0)