diff options
author | Werner Koch <[email protected]> | 2015-02-26 14:35:49 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2015-02-26 14:35:49 +0000 |
commit | 2e7a3ed39007deb561a9175f7fccd52946c85d28 (patch) | |
tree | be0c423c5f2ec5049d1480da3c75c7cd7efe3875 | |
parent | Allow requesting only an IPGP certtype with dns_cert(). (diff) | |
download | gnupg-2e7a3ed39007deb561a9175f7fccd52946c85d28.tar.gz gnupg-2e7a3ed39007deb561a9175f7fccd52946c85d28.zip |
Add convenience function to hash a buffer.
* cipher/sha1.c (sha1_hash_buffer): New.
Signed-off-by: Werner Koch <[email protected]>
-rw-r--r-- | cipher/sha1.c | 19 | ||||
-rw-r--r-- | include/cipher.h | 1 |
2 files changed, 19 insertions, 1 deletions
diff --git a/cipher/sha1.c b/cipher/sha1.c index 309b38691..898a9a1fb 100644 --- a/cipher/sha1.c +++ b/cipher/sha1.c @@ -52,7 +52,7 @@ static void burn_stack (int bytes) { char buf[128]; - + wipememory(buf,sizeof buf); bytes -= sizeof buf; if (bytes > 0) @@ -323,6 +323,23 @@ sha1_read( SHA1_CONTEXT *hd ) return hd->buf; } + +/**************** + * Shortcut functions which puts the hash value of the supplied buffer + * into outbuf which must have a size of 20 bytes. + */ +void +sha1_hash_buffer (char *outbuf, const char *buffer, size_t length) +{ + SHA1_CONTEXT hd; + + sha1_init (&hd); + sha1_write (&hd, (byte*)buffer, length); + sha1_final (&hd); + memcpy (outbuf, hd.buf, 20); +} + + /**************** * Return some information about the algorithm. We need algo here to * distinguish different flavors of the algorithm. diff --git a/include/cipher.h b/include/cipher.h index dcc304521..dd4af18cb 100644 --- a/include/cipher.h +++ b/include/cipher.h @@ -157,6 +157,7 @@ void md_stop_debug( MD_HANDLE a ); } while(0) void rmd160_hash_buffer (char *outbuf, const char *buffer, size_t length); +void sha1_hash_buffer (char *outbuf, const char *buffer, size_t length); /*-- cipher.c --*/ |