File: sha1.c

package info (click to toggle)
rdup 1.1.11-1.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,340 kB
  • ctags: 259
  • sloc: ansic: 3,840; sh: 3,361; exp: 271; makefile: 78; ruby: 36; perl: 4
file content (39 lines) | stat: -rw-r--r-- 722 bytes parent folder | download | duplicates (2)
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
37
38
39
/* sha1.c - copied from
   /usr/share/doc/libnettle-dev/examples/sha-example.c
   */

#include "rdup.h"

#ifdef HAVE_LIBNETTLE
#include <nettle/sha.h>
#endif /* HAVE_LIBNETTLE */

#ifndef HAVE_LIBNETTLE
int
sha1_stream( __attribute__((unused)) FILE *f, __attribute__((unused)) unsigned char *digest)
#else
int
sha1_stream(FILE *f, unsigned char *digest)
#endif

{

#ifdef HAVE_LIBNETTLE
	struct sha1_ctx ctx;
	uint8_t buffer[SHA1_DIGEST_SIZE];

	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);
#endif /* HAVE_LIBNETTLE */
	return 0;
}