Пример #1
0
CAMLprim value stub_sha1_finalize(value ctx)
{
	CAMLparam1(ctx);
	CAMLlocal1(result);

	result = caml_alloc_string(20);
	sha1_finalize(GET_CTX_STRUCT(ctx), (sha1_digest *) result);

	CAMLreturn(result);
}
Пример #2
0
static inline int sha1_file(char *filename, uint8_t *digest)
{
	#define BLKSIZE 4096
	unsigned char buf[BLKSIZE];
	int fd; ssize_t n;
	struct sha1_ctx ctx;

	fd = open(filename, O_RDONLY);
	if (fd == -1)
		return 1;
	sha1_init(&ctx);
	while ((n = read(fd, buf, BLKSIZE)) > 0)
		sha1_update(&ctx, buf, n);
	if (n == 0)
		sha1_finalize(&ctx, digest);
	close(fd);
	return n < 0;
	#undef BLKSIZE
}
Пример #3
0
static inline int sha1_file(char *filename, sha1_digest *digest)
{
	unsigned char buf[BLKSIZE];
	int fd; ssize_t n;
	struct sha1_ctx ctx;

#ifdef WIN32
	fd = open(filename, O_RDONLY);
#else
	fd = open(filename, O_RDONLY | O_CLOEXEC);
#endif
	if (fd == -1)
		return 1;
	sha1_init(&ctx);
	while ((n = read(fd, buf, BLKSIZE)) > 0)
		sha1_update(&ctx, buf, n);
	if (n == 0)
		sha1_finalize(&ctx, digest);
	close(fd);
	return n < 0;
}
Пример #4
0
value sha1sum(value data) {
  CAMLparam1(data);

  char *msg = String_val(data);
  size_t msglen = caml_string_length(data);

  struct sha1_ctx ctx;

  sha1_init(&ctx);
  sha1_update(&ctx, (unsigned char *)msg, msglen);

  sha1_digest digest;
  sha1_finalize(&ctx, &digest);

  char hex[41];
  sha1_to_hex(&digest, hex);

  CAMLlocal1(result);
  result = caml_copy_string(hex);
  CAMLreturn(result);
}
Пример #5
0
static void crypt_finalize(void)
{
	sha1_finalize();
	return;
}