diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-08-15 17:10:10 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-08-15 17:10:10 +0200 |
commit | c0e5d9280dd156631bd398463dbb6a65aff37d19 (patch) | |
tree | 6883a55241a95fa9a2314b8d6189d2aa492e888f /c/sha1/main.c | |
parent | a97a4077ddc33f2abd53a37540158d4448adf915 (diff) |
Implement SHA-1
Diffstat (limited to 'c/sha1/main.c')
-rw-r--r-- | c/sha1/main.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/c/sha1/main.c b/c/sha1/main.c new file mode 100644 index 0000000..9ea4aab --- /dev/null +++ b/c/sha1/main.c @@ -0,0 +1,37 @@ +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "sha1.h" + +static uint8_t bigbuf1[1000000]; +static uint8_t bigbuf2[1000000]; + +int +main(int argc, char **argv) +{ + (void)argc; + + int e = 0; + sha1_t s; + uint8_t dgst[SHA1DGSTSZ]; + + memset(bigbuf1, 'a', sizeof(bigbuf1)); + memset(bigbuf2, 'b', sizeof(bigbuf2)); + + sha1init(&s); + e |= sha1hash(&s, bigbuf1, sizeof(bigbuf1)); + e |= sha1hash(&s, bigbuf2, sizeof(bigbuf2)); + sha1end(&s, dgst); + + if (e != 0) { + fprintf(stderr, "%s: %s\n", argv[0], strerror(e)); + exit(EXIT_FAILURE); + } + + for (int i = 0; i < sizeof(dgst); i++) + printf("%02" PRIx8, dgst[i]); + putchar('\n'); + return EXIT_SUCCESS; +} |