1hmac(3)                             OpenSSL                            hmac(3)
2
3
4

NAME

6       HMAC, HMAC_CTX_init, HMAC_Init, HMAC_Init_ex, HMAC_Update, HMAC_Final,
7       HMAC_CTX_cleanup, HMAC_cleanup - HMAC message authentication code
8

SYNOPSIS

10        #include <openssl/hmac.h>
11
12        unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
13                      int key_len, const unsigned char *d, int n,
14                      unsigned char *md, unsigned int *md_len);
15
16        void HMAC_CTX_init(HMAC_CTX *ctx);
17
18        int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
19                      const EVP_MD *md);
20        int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
21                          const EVP_MD *md, ENGINE *impl);
22        int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
23        int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
24
25        void HMAC_CTX_cleanup(HMAC_CTX *ctx);
26        void HMAC_cleanup(HMAC_CTX *ctx);
27

DESCRIPTION

29       HMAC is a MAC (message authentication code), i.e. a keyed hash function
30       used for message authentication, which is based on a hash function.
31
32       HMAC() computes the message authentication code of the n bytes at d
33       using the hash function evp_md and the key key which is key_len bytes
34       long.
35
36       It places the result in md (which must have space for the output of the
37       hash function, which is no more than EVP_MAX_MD_SIZE bytes).  If md is
38       NULL, the digest is placed in a static array.  The size of the output
39       is placed in md_len, unless it is NULL. Note: passing a NULL value for
40       md  to use the static array is not thread safe.
41
42       evp_md can be EVP_sha1(), EVP_ripemd160() etc.
43
44       HMAC_CTX_init() initialises a HMAC_CTX before first use. It must be
45       called.
46
47       HMAC_CTX_cleanup() erases the key and other data from the HMAC_CTX and
48       releases any associated resources. It must be called when an HMAC_CTX
49       is no longer required.
50
51       HMAC_cleanup() is an alias for HMAC_CTX_cleanup() included for back
52       compatibility with 0.9.6b, it is deprecated.
53
54       The following functions may be used if the message is not completely
55       stored in memory:
56
57       HMAC_Init() initializes a HMAC_CTX structure to use the hash function
58       evp_md and the key key which is key_len bytes long. It is deprecated
59       and only included for backward compatibility with OpenSSL 0.9.6b.
60
61       HMAC_Init_ex() initializes or reuses a HMAC_CTX structure to use the
62       hash function evp_md and key key. If both are NULL (or evp_md is the
63       same as the previous digest used by ctx and key is NULL) the existing
64       key is reused. ctx must have been created with HMAC_CTX_new() before
65       the first use of an HMAC_CTX in this function. N.B. HMAC_Init() had
66       this undocumented behaviour in previous versions of OpenSSL - failure
67       to switch to HMAC_Init_ex() in programs that expect it will cause them
68       to stop working.
69
70       NB: if HMAC_Init_ex() is called with key NULL and evp_md is not the
71       same as the previous digest used by ctx then an error is returned
72       because reuse of an existing key with a different digest is not
73       supported.
74
75       HMAC_Update() can be called repeatedly with chunks of the message to be
76       authenticated (len bytes at data).
77
78       HMAC_Final() places the message authentication code in md, which must
79       have space for the hash function output.
80

RETURN VALUES

82       HMAC() returns a pointer to the message authentication code or NULL if
83       an error occurred.
84
85       HMAC_Init_ex(), HMAC_Update() and HMAC_Final() return 1 for success or
86       0 if an error occurred.
87
88       HMAC_CTX_init() and HMAC_CTX_cleanup() do not return values.
89

CONFORMING TO

91       RFC 2104
92

SEE ALSO

94       sha(3), evp(3)
95

HISTORY

97       HMAC(), HMAC_Init(), HMAC_Update(), HMAC_Final() and HMAC_cleanup() are
98       available since SSLeay 0.9.0.
99
100       HMAC_CTX_init(), HMAC_Init_ex() and HMAC_CTX_cleanup() are available
101       since OpenSSL 0.9.7.
102
103       HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in
104       versions of OpenSSL before 1.0.0.
105
106
107
1081.0.2o                            2018-03-27                           hmac(3)
Impressum