From 83b247a771a514792b972216e1ad32ae1f3fc316 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 21 Jan 2012 10:01:20 +0100 Subject: libventi: add functions vtsha1 and vtsha1check These functions are equivalent to vtSha1 and vtSha1Check from the old libventi and are particularly used by Fossil. R=rsc http://codereview.appspot.com/5555064 --- include/venti.h | 4 ++++ src/libventi/mkfile | 1 + src/libventi/sha1.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/libventi/sha1.c diff --git a/include/venti.h b/include/venti.h index d6b753b8..45c0aab8 100644 --- a/include/venti.h +++ b/include/venti.h @@ -381,6 +381,10 @@ int vtwritepacket(VtConn*, uchar score[VtScoreSize], uint type, Packet *p); 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. */ diff --git a/src/libventi/mkfile b/src/libventi/mkfile index 289262ac..37881855 100644 --- a/src/libventi/mkfile +++ b/src/libventi/mkfile @@ -24,6 +24,7 @@ OFILES=\ scorefmt.$O\ send.$O\ server.$O\ + sha1.$O\ srvhello.$O\ strdup.$O\ string.$O\ diff --git a/src/libventi/sha1.c b/src/libventi/sha1.c new file mode 100644 index 00000000..358f923d --- /dev/null +++ b/src/libventi/sha1.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +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; +} -- cgit v1.2.3