1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
8 * \brief Implements SHA1 creation over WRBUF
19 #include <yaz/wrbuf.h>
24 #include <nettle/sha.h>
27 int wrbuf_sha1_write(WRBUF b, const char *cp, size_t sz, int hexit)
31 uint8_t digest[SHA1_DIGEST_SIZE];
34 sha1_update(&ctx, sz, (uint8_t *) cp);
35 sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
40 for (i = 0; i < SHA1_DIGEST_SIZE; i++)
41 wrbuf_printf(b, "%02x", digest[i]);
44 wrbuf_write(b, (const char *) digest, SHA1_DIGEST_SIZE);
49 const unsigned char *digest_buf;
50 int digest_len = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
52 e = gcry_md_open(&hd, GCRY_MD_SHA1, 0);
55 gcry_md_write(hd, cp, sz);
57 digest_buf = gcry_md_read(hd, GCRY_MD_SHA1);
61 for (i = 0; i < digest_len; i++)
62 wrbuf_printf(b, "%02x", digest_buf[i]);
65 wrbuf_write(b, (const char *) digest_buf, digest_len);
73 int wrbuf_sha1_puts(WRBUF b, const char *cp, int hexit)
75 return wrbuf_sha1_write(b, cp, strlen(cp), hexit);
81 * c-file-style: "Stroustrup"
82 * indent-tabs-mode: nil
84 * vim: shiftwidth=4 tabstop=8 expandtab