summaryrefslogtreecommitdiff
path: root/t/sha1_driver.c
blob: 212cbf8d619d52885da274aab7283fdf37772697 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <assert.h>
#include <stdio.h>

typedef struct ctx_s {
    int h[5];
    int bytes;
    char buf[64];
} ctx;

void sha1_init(ctx*);
void sha1_update(ctx*, const char*, int);
void sha1_final(unsigned char*, ctx*);

int main(int argc, char* argv[]) {
    ctx c;
    int i;
    size_t len;
    char buf[1024];
    unsigned char md[20];
    FILE* f;

    assert(argc == 2);
    f = fopen(argv[1], "r");
    sha1_init(&c);
    while (!feof(f)) {
        len = fread(buf, 1, 1024, f);
        sha1_update(&c, buf, (int) len);
    }
    sha1_final(md, &c);
    for (i = 0; i < 20; i++) {
        printf("%02x", md[i]);
    }
    putchar('\n');
    fclose(f);
    return 0;
}