git: 9front

Download patch

ref: 8f9953893cf7b27b364ba7c9bd062a65aef6b149
parent: ca77cceb2a07b9645a83a07bd769ea9a3df73ed7
author: cinap_lenrek <cinap_lenrek@felloff.net>
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;
 }
 
--