diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/liboventi/plan9-sha1.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/liboventi/plan9-sha1.c')
-rwxr-xr-x | sys/src/liboventi/plan9-sha1.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/sys/src/liboventi/plan9-sha1.c b/sys/src/liboventi/plan9-sha1.c new file mode 100755 index 000000000..c602efed8 --- /dev/null +++ b/sys/src/liboventi/plan9-sha1.c @@ -0,0 +1,78 @@ +#include <u.h> +#include <libc.h> +#include <oventi.h> +#include <libsec.h> + +static void encode(uchar*, u32int*, ulong); +extern void vtSha1Block(u32int *s, uchar *p, ulong len); + +struct VtSha1 +{ + DigestState *s; +}; + +VtSha1 * +vtSha1Alloc(void) +{ + VtSha1 *s; + + s = vtMemAlloc(sizeof(VtSha1)); + vtSha1Init(s); + return s; +} + +void +vtSha1Free(VtSha1 *s) +{ + if(s == nil) + return; + if(s->s != nil) + free(s->s); + vtMemFree(s); +} + +void +vtSha1Init(VtSha1 *s) +{ + s->s = nil; +} + +void +vtSha1Update(VtSha1 *s, uchar *p, int len) +{ + s->s = sha1(p, len, nil, s->s); +} + +void +vtSha1Final(VtSha1 *s, uchar *digest) +{ + sha1(nil, 0, digest, s->s); + s->s = nil; +} + +void +vtSha1(uchar sha1[VtScoreSize], uchar *p, int n) +{ + VtSha1 s; + + vtSha1Init(&s); + vtSha1Update(&s, p, n); + vtSha1Final(&s, sha1); +} + +int +vtSha1Check(uchar score[VtScoreSize], uchar *p, int n) +{ + VtSha1 s; + uchar score2[VtScoreSize]; + + vtSha1Init(&s); + vtSha1Update(&s, p, n); + vtSha1Final(&s, score2); + + if(memcmp(score, score2, VtScoreSize) != 0) { + vtSetError("vtSha1Check failed"); + return 0; + } + return 1; +} |