changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: factotum: rsa: use mptober() to get right adjusted result instead of mptobe() and memset()

changeset 6936: 9419715d8845
parent 6935: a143989c4608
child 6937: 62ba89f5ffb8
author: cinap_lenrek@felloff.net
date: Tue, 04 Dec 2018 19:34:36 +0100
files: sys/src/cmd/auth/factotum/rsa.c
description: factotum: rsa: use mptober() to get right adjusted result instead of mptobe() and memset()
     1.1--- a/sys/src/cmd/auth/factotum/rsa.c
     1.2+++ b/sys/src/cmd/auth/factotum/rsa.c
     1.3@@ -131,7 +131,7 @@ rsaread(Fsstate *fss, void *va, uint *n)
     1.4 	State *s;
     1.5 	mpint *m;
     1.6 	Keyinfo ki;
     1.7-	int len, r;
     1.8+	int len;
     1.9 
    1.10 	s = fss->ps;
    1.11 	switch(fss->phase){
    1.12@@ -160,13 +160,9 @@ rsaread(Fsstate *fss, void *va, uint *n)
    1.13 		len = (mpsignif(priv->pub.n)+7)/8;
    1.14 		if(len > *n)
    1.15 			return failure(fss, "signature buffer too short");
    1.16+		*n = len;
    1.17 		m = rsadecrypt(priv, s->digest, nil);
    1.18-		r = mptobe(m, (uchar*)va, len, nil);
    1.19-		if(r < len){
    1.20-			memmove((uchar*)va+len-r, va, r);
    1.21-			memset(va, 0, len-r);
    1.22-		}
    1.23-		*n = len;
    1.24+		mptober(m, (uchar*)va, len);
    1.25 		mpfree(m);
    1.26 		fss->phase = Established;
    1.27 		return RpcOk;