hmac: style cleanups, wire up docs
authorMarko Kreen <markokr@gmail.com>
Thu, 10 May 2012 20:57:36 +0000 (23:57 +0300)
committerMarko Kreen <markokr@gmail.com>
Thu, 10 May 2012 20:57:36 +0000 (23:57 +0300)
doc/mainpage.dox
usual/hmac.c
usual/hmac.h

index 88cc190523a3335830416abb65c98d7d6914c497..9a52091bff3119ba1e2aabf163946b022a92ebff 100644 (file)
@@ -57,6 +57,7 @@
  * <tr><td>  <usual/cfparser.h>      </td><td>  Config parser   </td></tr>
  * <tr><td>  <usual/crc32.h>         </td><td>  CRC32   </td></tr>
  * <tr><td>  <usual/endian.h>        </td><td>  Endianess conversion   </td></tr>
+ * <tr><td>  <usual/hmac.h>          </td><td>  HMAC-SHA1   </td></tr>
  * <tr><td>  <usual/lookup3.h>       </td><td>  Jenkins' lookup3 hash   </td></tr>
  * <tr><td>  <usual/misc.h>          </td><td>  Misc arithmetic   </td></tr>
  * <tr><td>  <usual/md5.h>           </td><td>  MD5 hash   </td></tr>
index 05432535c6576351b31ce4bc6ebed88141850384..732f46eee4046aa8b9f5e91b132c01c6af6d1a2c 100644 (file)
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <string.h>
-
 #include <usual/hmac.h>
 #include <usual/sha1.h>
 
+#include <string.h>
+
 /* Clean HMAC-SHA1 state */
 void
 hmac_sha1_reset(struct hmac_sha1_ctx *ctx,
-                               const u_int8_t *key, u_int key_len)
+               const uint8_t *key, unsigned int key_len)
 {
-       uint8_t                          k_ipad[65];
-       int                                      i;
+       uint8_t k_ipad[SHA1_BLOCK_SIZE];
+       int i;
 
        if (key_len > SHA1_BLOCK_SIZE) {
                sha1_reset(&ctx->ctx);
@@ -59,14 +59,16 @@ hmac_sha1_reset(struct hmac_sha1_ctx *ctx,
 /* Update HMAC-SHA1 state with more data */
 void
 hmac_sha1_update(struct hmac_sha1_ctx *ctx,
-                                const void *data, unsigned int len) {
+                const void *data, unsigned int len)
+{
        sha1_update(&ctx->ctx, data, len);
 }
 
 
 /* Get final HMAC-SHA1 result */
-void hmac_sha1_final(uint8_t *dst, struct hmac_sha1_ctx *ctx) {
-       u_int8_t k_opad[SHA1_BLOCK_SIZE];
+void hmac_sha1_final(uint8_t *dst, struct hmac_sha1_ctx *ctx)
+{
+       uint8_t k_opad[SHA1_BLOCK_SIZE];
        int i;
 
        sha1_final(dst, &ctx->ctx);
index 61568f2ee70e8748a443f21e189b01168b362d0c..09b20b4bc2c1ef3645214016e5ec83f18329c319 100644 (file)
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+/**
+ * @file
+ * HMAC-SHA1 implementation (RFC2104).
+ */
+
 #ifndef _USUAL_HMAC_H_
 #define _USUAL_HMAC_H_
 
 
 #include <usual/sha1.h>
 
-/* HMAC-SHA1 Context */
+/** HMAC-SHA1 Context */
 struct hmac_sha1_ctx {
        struct  sha1_ctx        ctx;
-       uint8_t                         key[SHA1_BLOCK_SIZE];
-       size_t                          key_len;
+       uint8_t                 key[SHA1_BLOCK_SIZE];
+       unsigned int            key_len;
 };
 
-void hmac_sha1_reset(struct hmac_sha1_ctx *ctx,
-                               const u_int8_t *key, u_int key_len);
-void hmac_sha1_update(struct hmac_sha1_ctx *ctx,
-                                         const void *data, unsigned int len);
+/** Initialize context with new key */
+void hmac_sha1_reset(struct hmac_sha1_ctx *ctx, const uint8_t *key, unsigned int key_len);
+
+/** Hash more data */
+void hmac_sha1_update(struct hmac_sha1_ctx *ctx, const void *data, unsigned int len);
+
+/** Get final result */
 void hmac_sha1_final(uint8_t *dst, struct hmac_sha1_ctx *ctx);
 
 #endif /* _USUAL_HMAC_H_ */