[go: up one dir, main page]

File: sha1.c

package info (click to toggle)
rdup 1.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,996 kB
  • ctags: 185
  • sloc: ansic: 3,326; sh: 3,221; exp: 166; makefile: 64
file content (34 lines) | stat: -rw-r--r-- 644 bytes parent folder | download
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
/* sha1.c - copied from
   /usr/share/doc/libnettle-dev/examples/sha-example.c
   */

#include "rdup.h"
#include <nettle/sha.h>

int
sha1_stream(__attribute__((unused)) FILE *f, unsigned char *digest)
{
#ifdef HAVE_LIBNETTLE
	uint8_t buffer[SHA1_DIGEST_SIZE + 1];
	struct sha1_ctx ctx;

	sha1_init(&ctx);
	for (;;)
	{
		guint done = fread(buffer, 1, sizeof(buffer), f);
		sha1_update(&ctx, done, buffer);
		if (done < sizeof(buffer))
			break;
	}
	if (ferror(f))
		return -1;

	sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
#else
	int i;
	for(i = 0; i < SHA1_DIGEST_SIZE; i++) {
		digest[i] = '\0';
	}
#endif /* HAVE_LIBNETTLE */
	return 0;  
}