fix
[libpgclient.git] / src / hmac.h
blobd70053077e3a8a8c886603691fccc414e51c35c5
1 /*Copyright (c) Brian B.
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License as published by the Free Software Foundation; either
6 version 3 of the License, or (at your option) any later version.
7 See the file LICENSE included with this distribution for more
8 information.
10 Portions Copyright (c) 1994, Regents of the University of California
13 #ifndef __HMAC_H__
14 #define __HMAC_H__
16 #include <stdlib.h>
17 #include <stdint.h>
19 #define SHA_BLOCK_LEN 64
20 #define SHA_DIGEST_LEN 32
21 #define SHA_DIGEST_STRLEN (SHA_DIGEST_LEN * 2 + 1)
22 #define HMAC_IPAD 0x36
23 #define HMAC_OPAD 0x5C
25 typedef struct {
26 uint32_t state [8];
27 uint64_t bitcount;
28 uint8_t buf [SHA_BLOCK_LEN];
29 } sha_t;
30 void sha_init (sha_t *ctx);
31 void sha_update (sha_t *ctx, const uint8_t *data, size_t len);
32 void sha_final (sha_t *ctx, uint8_t *digest);
34 typedef struct {
35 sha_t hash;
36 uint8_t ipad [SHA_BLOCK_LEN];
37 uint8_t opad [SHA_BLOCK_LEN];
38 } hmac_t;
39 void hmac_init (hmac_t *ctx, uint8_t *key, size_t len);
40 void hmac_update (hmac_t *ctx, const uint8_t *data, size_t len);
41 void hmac_final (hmac_t *ctx, uint8_t *dst, size_t len);
43 #endif