shithub: riscv

Download patch

ref: 5256f4063e381bb7a6f175ea397202e93f8be4b1
parent: 02b3c609ed7deb369722617c20f69c5f3f73e570
author: cinap_lenrek <[email protected]>
date: Sun Feb 5 22:50:03 EST 2017

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

--- a/sys/src/libsec/port/x509.c
+++ b/sys/src/libsec/port/x509.c
@@ -2461,15 +2461,12 @@
 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;
 }