shithub: riscv

Download patch

ref: 79bfff6437def01409c373f3e053d092d84ad20e
parent: c5393d612fd2a0e4ff3f9557dcb6adb2ad27391f
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Dec 4 14:34:36 EST 2018

factotum: rsa: use mptober() to get right adjusted result instead of mptobe() and memset()

--- a/sys/src/cmd/auth/factotum/rsa.c
+++ b/sys/src/cmd/auth/factotum/rsa.c
@@ -131,7 +131,7 @@
 	State *s;
 	mpint *m;
 	Keyinfo ki;
-	int len, r;
+	int len;
 
 	s = fss->ps;
 	switch(fss->phase){
@@ -160,13 +160,9 @@
 		len = (mpsignif(priv->pub.n)+7)/8;
 		if(len > *n)
 			return failure(fss, "signature buffer too short");
-		m = rsadecrypt(priv, s->digest, nil);
-		r = mptobe(m, (uchar*)va, len, nil);
-		if(r < len){
-			memmove((uchar*)va+len-r, va, r);
-			memset(va, 0, len-r);
-		}
 		*n = len;
+		m = rsadecrypt(priv, s->digest, nil);
+		mptober(m, (uchar*)va, len);
 		mpfree(m);
 		fss->phase = Established;
 		return RpcOk;