crypto: add public function xmpp_sha1_digest()
For example, XEP-0115 requires binary digest to be base64-encoded. Add short function to simplify such a digest computation for a single buffer. This function doesn't allocate memory. Therefore, it can't fail and doesn't require strophe context (xmpp_ctx_t).
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
newer
|
newer
|
||||||
- Support of handlers with the same callback function, but different
|
- Support of handlers with the same callback function, but different
|
||||||
userdata
|
userdata
|
||||||
|
- New public function xmpp_sha1_digest()
|
||||||
|
|
||||||
0.9.1
|
0.9.1
|
||||||
- Fixed bug #95 (DNS lookup failing on Cygwin)
|
- Fixed bug #95 (DNS lookup failing on Cygwin)
|
||||||
|
|||||||
28
src/crypto.c
28
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);
|
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
|
/** 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
|
* @param ctx a Strophe context onject
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -409,6 +409,8 @@ char *xmpp_uuid_gen(xmpp_ctx_t *ctx);
|
|||||||
typedef struct _xmpp_sha1_t xmpp_sha1_t;
|
typedef struct _xmpp_sha1_t xmpp_sha1_t;
|
||||||
|
|
||||||
char *xmpp_sha1(xmpp_ctx_t *ctx, const unsigned char *data, size_t len);
|
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);
|
xmpp_sha1_t *xmpp_sha1_new(xmpp_ctx_t *ctx);
|
||||||
void xmpp_sha1_free(xmpp_sha1_t *sha1);
|
void xmpp_sha1_free(xmpp_sha1_t *sha1);
|
||||||
|
|||||||
Reference in New Issue
Block a user