summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2017-02-06 21:40:42 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2017-02-06 21:40:42 +0100
commit6386a0391a11fd3c5216dfe1478fda08ae8bccbc (patch)
tree0a6cd637a01b4431bf3ab56d322f607a8966fd52 /sys
parent486523bbc57b111d198432d2416e598c6d5c2d63 (diff)
libsec: handle signed asn.1 bigint to mpint conversion for x509
Diffstat (limited to 'sys')
-rw-r--r--sys/src/libsec/port/x509.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/sys/src/libsec/port/x509.c b/sys/src/libsec/port/x509.c
index 1555210f3..20cfb9a8a 100644
--- a/sys/src/libsec/port/x509.c
+++ b/sys/src/libsec/port/x509.c
@@ -2129,8 +2129,12 @@ asn1mpint(Elem *e)
if(is_int(e, &v))
return itomp(v, nil);
- if(is_bigint(e, &b))
- return betomp(b->data, b->len, nil);
+ if(is_bigint(e, &b)){
+ mpint *s = betomp(b->data, b->len, nil);
+ if(b->len > 0 && (b->data[0] & 0x80) != 0)
+ mpxtend(s, b->len*8, s);
+ return s;
+ }
return nil;
}
@@ -2466,7 +2470,15 @@ mkbigint(mpint *p)
e.tag.num = INTEGER;
e.val.tag = VBigInt;
e.val.u.bigintval = newbytes((mpsignif(p)+8)/8);
- mptober(p, e.val.u.bigintval->data, e.val.u.bigintval->len);
+ if(p->sign < 0){
+ mpint *s = mpnew(e.val.u.bigintval->len*8+1);
+ mpleft(mpone, e.val.u.bigintval->len*8, s);
+ mpadd(p, s, s);
+ mptober(s, e.val.u.bigintval->data, e.val.u.bigintval->len);
+ mpfree(s);
+ } else {
+ mptober(p, e.val.u.bigintval->data, e.val.u.bigintval->len);
+ }
return e;
}