* <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>
* 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);
/* 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);
* 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_ */