From 5256f4063e381bb7a6f175ea397202e93f8be4b1 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 6 Feb 2017 03:50:03 +0100 Subject: libsec: fix mkbigint(), asn.1 uses two's compement signed representation quick fix is to bias the rounding so the msb will always be zero. should write proper conversion code to actually deal with signed mpints... also for asn1mpint()... -- cinap --- sys/src/libsec/port/x509.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sys/src/libsec/port/x509.c b/sys/src/libsec/port/x509.c index 4e151915a..1555210f3 100644 --- a/sys/src/libsec/port/x509.c +++ b/sys/src/libsec/port/x509.c @@ -2461,15 +2461,12 @@ static Elem mkbigint(mpint *p) { Elem e; - uchar *buf; - int buflen; e.tag.class = Universal; e.tag.num = INTEGER; e.val.tag = VBigInt; - buflen = mptobe(p, nil, 0, &buf); - e.val.u.bigintval = makebytes(buf, buflen); - free(buf); + e.val.u.bigintval = newbytes((mpsignif(p)+8)/8); + mptober(p, e.val.u.bigintval->data, e.val.u.bigintval->len); return e; } -- cgit v1.2.3