]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/sha1.h
ucw docs: Hash routines
[libucw.git] / ucw / sha1.h
index 05dc485350a70fe9892de0f829c1fb96feeb2386..d9ca009e2bfea6c5e7ca8deb0bed443b7a4ba672 100644 (file)
 #ifndef _UCW_SHA1_H
 #define _UCW_SHA1_H
 
+/**
+ * Internal SHA1 state.
+ * You can consider it an opaque handle, if you want just hash
+ * functions.
+ */
 typedef struct {
   u32 h0,h1,h2,h3,h4;
   u32 nblocks;
@@ -21,18 +26,43 @@ typedef struct {
   int count;
 } sha1_context;
 
-void sha1_init(sha1_context *hd);
+void sha1_init(sha1_context *hd); /** Initialize new algorithm run in the @hd context. **/
+/**
+ * Push another @inlen bytes of data pointed to by @inbuf onto the
+ * SHA1 hash currently in @hd. You can call this any times you want on
+ * the same hash (and you do not need to reinitialize it by
+ * sha1_init()). It has the same effect as concatenating all the data
+ * together and passing them at once.
+ */
 void sha1_update(sha1_context *hd, const byte *inbuf, uns inlen);
+/**
+ * No more sha1_update() calls will be done. This terminates the hash
+ * and returns pointer to it.
+ *
+ * Note the pointer points into data in the @hd context. If it ceases
+ * to exist, the pointer becomes invalid.
+ */
 byte *sha1_final(sha1_context *hd);
 
-/* One-shot interface */
+/**
+ * Convenience one-shot function for SHA1 hash.
+ * It is equivalent to this snippet of code:
+ *
+ *  sha1_context hd;
+ *  sha1_init(&hd);
+ *  sha1_update(&hd, buffer, length);
+ *  memcpy(outbuf, sha1_final(&hd), 20);
+ */
 void sha1_hash_buffer(byte *outbuf, const byte *buffer, uns length);
 
-/* HMAC */
+/**
+ * SHA1 HMAC message authentication. If you provide @key and @data,
+ * the result will be stored in @outbuf.
+ */
 void sha1_hmac(byte *outbuf, const byte *key, uns keylen, const byte *data, uns datalen);
 
-#define SHA1_SIZE 20
-#define SHA1_HEX_SIZE 41
-#define SHA1_BLOCK_SIZE 64
+#define SHA1_SIZE 20 /** Size of the SHA1 hash in its binary representation **/
+#define SHA1_HEX_SIZE 41 /** Buffer length for a string containing SHA1 in hexadecimal format. **/
+#define SHA1_BLOCK_SIZE 64 /** SHA1 splits input to blocks of this size. **/
 
 #endif