code: plan9front

Download patch

ref: cb091e75393b176ccb02c68f0ecfcfbb8bc49376
parent: 63ae9ed53a04fac853693f8d319a4bbc1f6b5f49
author: David du Colombier <0intro@gmail.com>
date: Fri Sep 6 07:55:18 EDT 2019

sys/src/libventi: implement vtsha1 and vtsha1check functions

--- a/sys/include/venti.h
+++ b/sys/include/venti.h
@@ -380,6 +380,10 @@
 int	vtsync(VtConn*);
 int	vtping(VtConn*);
 
+/* sha1 */
+void	vtsha1(uchar score[VtScoreSize], uchar*, int);
+int	vtsha1check(uchar score[VtScoreSize], uchar*, int);
+
 /*
  * Data blocks and block cache.
  */
--- a/sys/src/libventi/mkfile
+++ b/sys/src/libventi/mkfile
@@ -24,6 +24,7 @@
 	scorefmt.$O\
 	send.$O\
 	server.$O\
+	sha1.$O\
 	srvhello.$O\
 	strdup.$O\
 	string.$O\
--- /dev/null
+++ b/sys/src/libventi/sha1.c
@@ -1,0 +1,28 @@
+#include <u.h>
+#include <libc.h>
+#include <venti.h>
+#include <libsec.h>
+
+void
+vtsha1(uchar score[VtScoreSize], uchar *p, int n)
+{
+	DigestState ds;
+
+	memset(&ds, 0, sizeof ds);
+	sha1(p, n, score, &ds);
+}
+
+int
+vtsha1check(uchar score[VtScoreSize], uchar *p, int n)
+{
+	DigestState ds;
+	uchar score2[VtScoreSize];
+
+	memset(&ds, 0, sizeof ds);
+	sha1(p, n, score2, &ds);
+	if(memcmp(score, score2, VtScoreSize) != 0) {
+		werrstr("vtsha1check failed");
+		return -1;
+	}
+	return 0;
+}