From 7a4ee46d253e291044bba2d0c54b818b67ac013c Mon Sep 17 00:00:00 2001 From: rsc Date: Sun, 23 Nov 2003 17:54:58 +0000 Subject: Initial stab at Venti. --- src/cmd/venti/score.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/cmd/venti/score.c (limited to 'src/cmd/venti/score.c') diff --git a/src/cmd/venti/score.c b/src/cmd/venti/score.c new file mode 100644 index 00000000..0809e84f --- /dev/null +++ b/src/cmd/venti/score.c @@ -0,0 +1,43 @@ +#include "stdinc.h" +#include "dat.h" +#include "fns.h" + +u8int zeroscore[VtScoreSize]; + +void +scoremem(u8int *score, u8int *buf, int n) +{ + DigestState s; + + memset(&s, 0, sizeof s); + sha1(buf, n, score, &s); +} + +static int +hexv(int c) +{ + if(c >= '0' && c <= '9') + return c - '0'; + if(c >= 'a' && c <= 'f') + return c - 'a' + 10; + if(c >= 'A' && c <= 'F') + return c - 'A' + 10; + return -1; +} + +int +strscore(char *s, u8int *score) +{ + int i, c, d; + + for(i = 0; i < VtScoreSize; i++){ + c = hexv(s[2 * i]); + if(c < 0) + return -1; + d = hexv(s[2 * i + 1]); + if(d < 0) + return -1; + score[i] = (c << 4) + d; + } + return s[2 * i] == '\0'; +} -- cgit v1.2.3