changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: sys/src/libventi: implement vtsha1 and vtsha1check functions

changeset 7365: e40a49d58913
parent 7364: 4947baafd1f3
child 7366: a5fb3861b449
author: David du Colombier <0intro@gmail.com>
date: Fri, 06 Sep 2019 11:55:18 -0700
files: sys/include/venti.h sys/src/libventi/mkfile sys/src/libventi/sha1.c
description: sys/src/libventi: implement vtsha1 and vtsha1check functions
     1.1--- a/sys/include/venti.h
     1.2+++ b/sys/include/venti.h
     1.3@@ -380,6 +380,10 @@ int	vtwritepacket(VtConn*, uchar score[V
     1.4 int	vtsync(VtConn*);
     1.5 int	vtping(VtConn*);
     1.6 
     1.7+/* sha1 */
     1.8+void	vtsha1(uchar score[VtScoreSize], uchar*, int);
     1.9+int	vtsha1check(uchar score[VtScoreSize], uchar*, int);
    1.10+
    1.11 /*
    1.12  * Data blocks and block cache.
    1.13  */
     2.1--- a/sys/src/libventi/mkfile
     2.2+++ b/sys/src/libventi/mkfile
     2.3@@ -24,6 +24,7 @@ OFILES=\
     2.4 	scorefmt.$O\
     2.5 	send.$O\
     2.6 	server.$O\
     2.7+	sha1.$O\
     2.8 	srvhello.$O\
     2.9 	strdup.$O\
    2.10 	string.$O\
     3.1new file mode 100644
     3.2--- /dev/null
     3.3+++ b/sys/src/libventi/sha1.c
     3.4@@ -0,0 +1,28 @@
     3.5+#include <u.h>
     3.6+#include <libc.h>
     3.7+#include <venti.h>
     3.8+#include <libsec.h>
     3.9+
    3.10+void
    3.11+vtsha1(uchar score[VtScoreSize], uchar *p, int n)
    3.12+{
    3.13+	DigestState ds;
    3.14+
    3.15+	memset(&ds, 0, sizeof ds);
    3.16+	sha1(p, n, score, &ds);
    3.17+}
    3.18+
    3.19+int
    3.20+vtsha1check(uchar score[VtScoreSize], uchar *p, int n)
    3.21+{
    3.22+	DigestState ds;
    3.23+	uchar score2[VtScoreSize];
    3.24+
    3.25+	memset(&ds, 0, sizeof ds);
    3.26+	sha1(p, n, score2, &ds);
    3.27+	if(memcmp(score, score2, VtScoreSize) != 0) {
    3.28+		werrstr("vtsha1check failed");
    3.29+		return -1;
    3.30+	}
    3.31+	return 0;
    3.32+}