diff --git a/ChangeLog b/ChangeLog index 99db50c..60d76c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ newer - Support of handlers with the same callback function, but different userdata + - New public function xmpp_sha1_digest() 0.9.1 - Fixed bug #95 (DNS lookup failing on Cygwin) diff --git a/src/crypto.c b/src/crypto.c index 4bc4863..6bad32e 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -81,7 +81,35 @@ char *xmpp_sha1(xmpp_ctx_t *ctx, const unsigned char *data, size_t len) return digest_to_string_alloc(ctx, digest); } +/** Compute SHA1 message digest + * Stores digest in user's buffer which must be at least XMPP_SHA1_DIGEST_SIZE + * bytes long. + * + * @param data buffer for digest computation + * @param len size of the data buffer + * @param digest output buffer of XMPP_SHA1_DIGEST_SIZE bytes + * + * @ingroup Digests + */ +void xmpp_sha1_digest(const unsigned char *data, size_t len, + unsigned char *digest) +{ + crypto_SHA1((const uint8_t *)data, len, digest); +} + /** Create new SHA1 object + * SHA1 object is used to compute SHA1 digest of a buffer that is split + * in multiple chunks or provided in stream mode. A single buffer can be + * processed by short functions xmpp_sha1() and xmpp_sha1_digest(). + * Follow the next use-case for xmpp_sha1_t object: + * @code + * xmpp_sha1_t *sha1 = xmpp_sha1_new(ctx); + * // Repeat update for all chunks of data + * xmpp_sha1_update(sha1, data, len); + * xmpp_sha1_final(sha1); + * char *digest = xmpp_sha1_to_string_alloc(sha1); + * xmpp_sha1_free(sha1); + * @endcode * * @param ctx a Strophe context onject * diff --git a/strophe.h b/strophe.h index 5288f77..8e474b1 100644 --- a/strophe.h +++ b/strophe.h @@ -409,6 +409,8 @@ char *xmpp_uuid_gen(xmpp_ctx_t *ctx); typedef struct _xmpp_sha1_t xmpp_sha1_t; char *xmpp_sha1(xmpp_ctx_t *ctx, const unsigned char *data, size_t len); +void xmpp_sha1_digest(const unsigned char *data, size_t len, + unsigned char *digest); xmpp_sha1_t *xmpp_sha1_new(xmpp_ctx_t *ctx); void xmpp_sha1_free(xmpp_sha1_t *sha1);